smatrixf

Variants: smatrixb, smatrixf, smatrixi

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

Public Functions

smatrixf smatrixf_create(unsigned int _m, unsigned int _n)
smatrixf smatrixf_create_array(float * _x, unsigned int _m, unsigned int _n)
int smatrixf_destroy(smatrixf _q)
int smatrixf_print(smatrixf _q)
int smatrixf_print_expanded(smatrixf _q)
int smatrixf_size(smatrixf _q, unsigned int * _m, unsigned int * _n)
int smatrixf_clear(smatrixf _q)
int smatrixf_reset(smatrixf _q)
int smatrixf_isset(smatrixf _q, unsigned int _m, unsigned int _n)
int smatrixf_insert(smatrixf _q, unsigned int _m, unsigned int _n, float _v)
int smatrixf_delete(smatrixf _q, unsigned int _m, unsigned int _n)
int smatrixf_set(smatrixf _q, unsigned int _m, unsigned int _n, float _v)
float smatrixf_get(smatrixf _q, unsigned int _m, unsigned int _n)
int smatrixf_eye(smatrixf _q)
int smatrixf_mul(smatrixf _x, smatrixf _y, smatrixf _z)
int smatrixf_vmul(smatrixf _q, float * _x, float * _y)

Interfaces

smatrixf smatrixf_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

smatrixf smatrixf_create_array(float * _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 smatrixf_destroy(smatrixf _q)

Destroy object, freeing all internal memory

int smatrixf_print(smatrixf _q)

Print sparse matrix in compact form to stdout

int smatrixf_print_expanded(smatrixf _q)

Print sparse matrix in expanded form to stdout

int smatrixf_size(smatrixf _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 smatrixf_clear(smatrixf _q)

Zero all elements and retain allocated memory

int smatrixf_reset(smatrixf _q)

Zero all elements and clear memory

int smatrixf_isset(smatrixf _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 smatrixf_insert(smatrixf _q, unsigned int _m, unsigned int _n, float _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 smatrixf_delete(smatrixf _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 smatrixf_set(smatrixf _q, unsigned int _m, unsigned int _n, float _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

float smatrixf_get(smatrixf _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 smatrixf_eye(smatrixf _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 smatrixf_mul(smatrixf _x, smatrixf _y, smatrixf _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 smatrixf_vmul(smatrixf _q, float * _x, float * _y)

Multiply sparse matrix by vector

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