smatrixb

Sparse matrix object (similar to MacKay, Davey, Lafferty convention)

Variants: smatrixb, smatrixf, smatrixi

Public Functions

smatrixb smatrixb_create(unsigned int _m, unsigned int _n)
smatrixb smatrixb_create_array(unsigned char * _x, unsigned int _m, unsigned int _n)
int smatrixb_destroy(smatrixb _q)
int smatrixb_print(smatrixb _q)
int smatrixb_print_expanded(smatrixb _q)
int smatrixb_size(smatrixb _q, unsigned int * _m, unsigned int * _n)
int smatrixb_clear(smatrixb _q)
int smatrixb_reset(smatrixb _q)
int smatrixb_isset(smatrixb _q, unsigned int _m, unsigned int _n)
int smatrixb_insert(smatrixb _q, unsigned int _m, unsigned int _n, unsigned char _v)
int smatrixb_delete(smatrixb _q, unsigned int _m, unsigned int _n)
int smatrixb_set(smatrixb _q, unsigned int _m, unsigned int _n, unsigned char _v)
unsigned char smatrixb_get(smatrixb _q, unsigned int _m, unsigned int _n)
int smatrixb_eye(smatrixb _q)
int smatrixb_mul(smatrixb _x, smatrixb _y, smatrixb _z)
int smatrixb_vmul(smatrixb _q, unsigned char * _x, unsigned char * _y)

Interfaces

smatrixb smatrixb_create(unsigned int _m, unsigned int _n)

Create \(M \times N\) sparse matrix, initialized with zeros

  • _m : number of rows in matrix
  • _n : number of columns in matrix

smatrixb smatrixb_create_array(unsigned char * _x, unsigned int _m, unsigned int _n)

Create \(M \times N\) sparse matrix, initialized on array

  • _x : input matrix, shape: (_m, _n)
  • _m : number of rows in input matrix
  • _n : number of columns in input matrix

int smatrixb_destroy(smatrixb _q)

Destroy object, freeing all internal memory

int smatrixb_print(smatrixb _q)

Print sparse matrix in compact form to stdout

int smatrixb_print_expanded(smatrixb _q)

Print sparse matrix in expanded form to stdout

int smatrixb_size(smatrixb _q, unsigned int * _m, unsigned int * _n)

Get size of sparse matrix (number of rows and columns)

  • _q : sparse matrix object
  • _m : number of rows in matrix
  • _n : number of columns in matrix

int smatrixb_clear(smatrixb _q)

Zero all elements and retain allocated memory

int smatrixb_reset(smatrixb _q)

Zero all elements and clear memory

int smatrixb_isset(smatrixb _q, unsigned int _m, unsigned int _n)

Determine if value has been set (allocated memory)

  • _q : sparse matrix object
  • _m : row index of value to query
  • _n : column index of value to query

int smatrixb_insert(smatrixb _q, unsigned int _m, unsigned int _n, unsigned char _v)

Insert an element at index, allocating memory as necessary

  • _q : sparse matrix object
  • _m : row index of value to insert
  • _n : column index of value to insert
  • _v : value to insert

int smatrixb_delete(smatrixb _q, unsigned int _m, unsigned int _n)

Delete an element at index, freeing memory

  • _q : sparse matrix object
  • _m : row index of value to delete
  • _n : column index of value to delete

int smatrixb_set(smatrixb _q, unsigned int _m, unsigned int _n, unsigned char _v)

Set the value in matrix at specified row and column, allocating memory if needed

  • _q : sparse matrix object
  • _m : row index of value to set
  • _n : column index of value to set
  • _v : value to set in matrix

unsigned char smatrixb_get(smatrixb _q, unsigned int _m, unsigned int _n)

Get the value from matrix at specified row and column

  • _q : sparse matrix object
  • _m : row index of value to get
  • _n : column index of value to get

int smatrixb_eye(smatrixb _q)

Initialize to identity matrix; set all diagonal elements to 1, all others to 0. This is done with both square and non-square matrices.

int smatrixb_mul(smatrixb _x, smatrixb _y, smatrixb _z)

Multiply two sparse matrices, \( \vec{Z} = \vec{X} \vec{Y} \)

  • _x : sparse matrix object (input)
  • _y : sparse matrix object (input)
  • _z : sparse matrix object (output)

int smatrixb_vmul(smatrixb _q, unsigned char * _x, unsigned char * _y)

Multiply sparse matrix by vector

  • _q : sparse matrix
  • _x : input vector, shape: (_n, 1)
  • _y : output vector, shape: (_m, 1)