Integer matrices

Integer matrices — Integer matrices

Synopsis

#include "integer_matrix.h"


typedef             IntegerMatrix;

IntegerMatrix *     intmat_new                          (unsigned int rows,
                                                         unsigned int cols);
IntegerMatrix *     intmat_copy                         (IntegerMatrix *m);
void                intmat_free                         (IntegerMatrix *m);

signed int          intmat_get                          (const IntegerMatrix *m,
                                                         unsigned int i,
                                                         unsigned int j);
void                intmat_set                          (IntegerMatrix *m,
                                                         unsigned int i,
                                                         unsigned int j,
                                                         signed int v);

IntegerMatrix *     intmat_intmat_mult                  (const IntegerMatrix *a,
                                                         const IntegerMatrix *b);
signed int *        intmat_intvec_mult                  (const IntegerMatrix *m,
                                                         const signed int *vec);
signed int          intmat_det                          (const IntegerMatrix *m);
IntegerMatrix *     intmat_inverse                      (const IntegerMatrix *m);

int                 intmat_equals                       (const IntegerMatrix *a,
                                                         const IntegerMatrix *b);
int                 intmat_is_identity                  (const IntegerMatrix *m);
int                 intmat_is_inversion                 (const IntegerMatrix *m);

void                intmat_print                        (const IntegerMatrix *m);

Description

An integer matrix library

Details

IntegerMatrix

typedef struct _integermatrix IntegerMatrix;

The IntegerMatrix is an opaque data structure representing an integer matrix.


intmat_new ()

IntegerMatrix *     intmat_new                          (unsigned int rows,
                                                         unsigned int cols);

Allocates a new IntegerMatrix with all elements set to zero.

rows :

Number of rows that the new matrix is to have

cols :

Number of columns that the new matrix is to have

Returns :

a new IntegerMatrix, or NULL on error.

intmat_copy ()

IntegerMatrix *     intmat_copy                         (IntegerMatrix *m);

m :

An IntegerMatrix

Returns :

a newly allocated copy of m, or NULL on error/

intmat_free ()

void                intmat_free                         (IntegerMatrix *m);

Frees m, unless m is NULL in which case nothing is done.

m :

An IntegerMatrix

intmat_get ()

signed int          intmat_get                          (const IntegerMatrix *m,
                                                         unsigned int i,
                                                         unsigned int j);

Gets the i,j element of m.

m :

An IntegerMatrix

i :

column number to set

j :

row number to set

Returns :

the i,j element of m.

intmat_set ()

void                intmat_set                          (IntegerMatrix *m,
                                                         unsigned int i,
                                                         unsigned int j,
                                                         signed int v);

Sets the i,j element of m to v.

m :

An IntegerMatrix

i :

row number to set

j :

column number to set

v :

value to set to

intmat_intmat_mult ()

IntegerMatrix *     intmat_intmat_mult                  (const IntegerMatrix *a,
                                                         const IntegerMatrix *b);

Multiplies the matrix a by the matrix b.

a :

An IntegerMatrix

b :

An IntegerMatrix

Returns :

a newly allocated IntegerMatrix containing the answer, or NULL on error.

intmat_intvec_mult ()

signed int *        intmat_intvec_mult                  (const IntegerMatrix *m,
                                                         const signed int *vec);

Multiplies the matrix m by the vector vec. The size of vec must equal the number of columns in m, and the size of the result equals the number of rows in m.

m :

An IntegerMatrix

vec :

An array of signed integers

Returns :

a newly allocated array of signed integers containing the answer, or NULL on error.

intmat_det ()

signed int          intmat_det                          (const IntegerMatrix *m);

Calculates the determinant of m. Inefficiently.

m :

An IntegerMatrix

Returns :

the determinant of m.

intmat_inverse ()

IntegerMatrix *     intmat_inverse                      (const IntegerMatrix *m);

Calculates the inverse of m. Inefficiently.

m :

An IntegerMatrix

Returns :

the inverse of m, or NULL on error.

intmat_equals ()

int                 intmat_equals                       (const IntegerMatrix *a,
                                                         const IntegerMatrix *b);

a :

An IntegerMatrix

b :

An IntegerMatrix

Returns :

true if a = b.

intmat_is_identity ()

int                 intmat_is_identity                  (const IntegerMatrix *m);

m :

An IntegerMatrix

Returns :

true if m is an identity matrix.

intmat_is_inversion ()

int                 intmat_is_inversion                 (const IntegerMatrix *m);

m :

An IntegerMatrix

Returns :

true if m = -I, where I is an identity matrix.

intmat_print ()

void                intmat_print                        (const IntegerMatrix *m);

Prints m to stderr.

m :

An IntegerMatrix