smatrixi

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

Variants: smatrixb, smatrixf, smatrixi

Public Functions

smatrixi smatrixi_create(unsigned int _m, unsigned int _n)
smatrixi smatrixi_create_array(short int * _x, unsigned int _m, unsigned int _n)
int smatrixi_destroy(smatrixi _q)
int smatrixi_print(smatrixi _q)
int smatrixi_print_expanded(smatrixi _q)
int smatrixi_size(smatrixi _q, unsigned int * _m, unsigned int * _n)
int smatrixi_clear(smatrixi _q)
int smatrixi_reset(smatrixi _q)
int smatrixi_isset(smatrixi _q, unsigned int _m, unsigned int _n)
int smatrixi_insert(smatrixi _q, unsigned int _m, unsigned int _n, short int _v)
int smatrixi_delete(smatrixi _q, unsigned int _m, unsigned int _n)
int smatrixi_set(smatrixi _q, unsigned int _m, unsigned int _n, short int _v)
short int smatrixi_get(smatrixi _q, unsigned int _m, unsigned int _n)
int smatrixi_eye(smatrixi _q)
int smatrixi_mul(smatrixi _x, smatrixi _y, smatrixi _z)
int smatrixi_vmul(smatrixi _q, short int * _x, short int * _y)

Interfaces

smatrixi smatrixi_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

smatrixi smatrixi_create_array(short int * _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 smatrixi_destroy(smatrixi _q)

Destroy object, freeing all internal memory

int smatrixi_print(smatrixi _q)

Print sparse matrix in compact form to stdout

int smatrixi_print_expanded(smatrixi _q)

Print sparse matrix in expanded form to stdout

int smatrixi_size(smatrixi _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 smatrixi_clear(smatrixi _q)

Zero all elements and retain allocated memory

int smatrixi_reset(smatrixi _q)

Zero all elements and clear memory

int smatrixi_isset(smatrixi _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 smatrixi_insert(smatrixi _q, unsigned int _m, unsigned int _n, short int _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 smatrixi_delete(smatrixi _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 smatrixi_set(smatrixi _q, unsigned int _m, unsigned int _n, short int _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

short int smatrixi_get(smatrixi _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 smatrixi_eye(smatrixi _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 smatrixi_mul(smatrixi _x, smatrixi _y, smatrixi _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 smatrixi_vmul(smatrixi _q, short int * _x, short int * _y)

Multiply sparse matrix by vector

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