SphinxBase  5prealpha
matrix.h File Reference

Matrix and linear algebra functions. More...

#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>

Go to the source code of this file.

Functions

SPHINXBASE_EXPORT void norm_3d (float32 ***arr, uint32 d1, uint32 d2, uint32 d3)
 Norm an array. More...
 
SPHINXBASE_EXPORT void accum_3d (float32 ***out, float32 ***in, uint32 d1, uint32 d2, uint32 d3)
 Floor 3-d array. More...
 
SPHINXBASE_EXPORT void band_nz_1d (float32 *v, uint32 d1, float32 band)
 Ensures that non-zero values x such that -band < x < band, band > 0 are set to -band if x < 0 and band if x > 0. More...
 
SPHINXBASE_EXPORT void floor_nz_3d (float32 ***m, uint32 d1, uint32 d2, uint32 d3, float32 floor)
 Floor 3-d array. More...
 
SPHINXBASE_EXPORT void floor_nz_1d (float32 *v, uint32 d1, float32 floor)
 Floor 1-d array. More...
 
SPHINXBASE_EXPORT float64 determinant (float32 **a, int32 len)
 Calculate the determinant of a positive definite matrix. More...
 
SPHINXBASE_EXPORT int32 invert (float32 **out_ainv, float32 **a, int32 len)
 Invert (if possible) a positive definite matrix with QR algorithm. More...
 
SPHINXBASE_EXPORT int32 solve (float32 **a, float32 *b, float32 *out_x, int32 n)
 Solve (if possible) a positive-definite system of linear equations AX=B for X. More...
 
SPHINXBASE_EXPORT void outerproduct (float32 **out_a, float32 *x, float32 *y, int32 len)
 Calculate the outer product of two vectors. More...
 
SPHINXBASE_EXPORT void matrixmultiply (float32 **out_c, float32 **a, float32 **b, int32 n)
 Multiply C=AB where A and B are symmetric matrices. More...
 
SPHINXBASE_EXPORT void scalarmultiply (float32 **inout_a, float32 x, int32 n)
 Multiply a symmetric matrix by a constant in-place. More...
 
SPHINXBASE_EXPORT void matrixadd (float32 **inout_a, float32 **b, int32 n)
 Add A += B. More...
 

Detailed Description

Matrix and linear algebra functions.

This file contains some basic matrix and linear algebra operations. In general these operate on positive definite matrices ONLY, because all matrices we're likely to encounter are either covariance matrices or are derived from them, and therefore a non-positive-definite matrix indicates some kind of pathological condition.

Definition in file matrix.h.

Function Documentation

SPHINXBASE_EXPORT void accum_3d ( float32 ***  out,
float32 ***  in,
uint32  d1,
uint32  d2,
uint32  d3 
)

Floor 3-d array.

Parameters
outoutput array
ininput array
d1dimension
d2dimension
d3dimension

Definition at line 78 of file matrix.c.

SPHINXBASE_EXPORT void band_nz_1d ( float32 *  v,
uint32  d1,
float32  band 
)

Ensures that non-zero values x such that -band < x < band, band > 0 are set to -band if x < 0 and band if x > 0.

Parameters
varray
d1array size
bandband value

Definition at line 127 of file matrix.c.

SPHINXBASE_EXPORT float64 determinant ( float32 **  a,
int32  len 
)

Calculate the determinant of a positive definite matrix.

Parameters
aThe input matrix, must be positive definite.
lenThe dimension of the input matrix.
Returns
The determinant of the input matrix, or -1.0 if the matrix is not positive definite.
Note
These can be vanishingly small hence the float64 return type. Also note that only the upper triangular portion of a is considered, therefore the check for positive-definiteness is not reliable.

Definition at line 147 of file matrix.c.

References E_FATAL.

SPHINXBASE_EXPORT void floor_nz_1d ( float32 *  v,
uint32  d1,
float32  floor 
)

Floor 1-d array.

Parameters
varray
d1dimension
floorfloor value

Definition at line 114 of file matrix.c.

SPHINXBASE_EXPORT void floor_nz_3d ( float32 ***  m,
uint32  d1,
uint32  d2,
uint32  d3,
float32  floor 
)

Floor 3-d array.

Parameters
marray
d1dimension
d2dimension
d3dimension
floorfloor value

Definition at line 96 of file matrix.c.

SPHINXBASE_EXPORT int32 invert ( float32 **  out_ainv,
float32 **  a,
int32  len 
)

Invert (if possible) a positive definite matrix with QR algorithm.

Parameters
out_ainvThe inverse of a will be stored here.
aThe input matrix, must be positive definite.
lenThe dimension of the input matrix.
Returns
0 for success or -1 for a non-positive-definite matrix.
Note
Only the upper triangular portion of a is considered, therefore the check for positive-definiteness is not reliable.
The inversion can be done in-place, so you can use the same matrix if you do not need to keep a.

Definition at line 153 of file matrix.c.

References E_FATAL.

SPHINXBASE_EXPORT void matrixadd ( float32 **  inout_a,
float32 **  b,
int32  n 
)

Add A += B.

Parameters
inout_aThe A matrix to add.
bThe B matrix to add to A.
ndimension of a and b.

Definition at line 309 of file matrix.c.

SPHINXBASE_EXPORT void matrixmultiply ( float32 **  out_c,
float32 **  a,
float32 **  b,
int32  n 
)

Multiply C=AB where A and B are symmetric matrices.

Parameters
out_cThe output matrix C.
aThe input matrix A.
bThe input matrix B.
nDimensionality of A and B.

Definition at line 166 of file matrix.c.

SPHINXBASE_EXPORT void norm_3d ( float32 ***  arr,
uint32  d1,
uint32  d2,
uint32  d3 
)

Norm an array.

Parameters
arrarray
d1dimension
d2dimension
d3dimension

Definition at line 50 of file matrix.c.

SPHINXBASE_EXPORT void outerproduct ( float32 **  out_a,
float32 *  x,
float32 *  y,
int32  len 
)

Calculate the outer product of two vectors.

Parameters
out_aA (pre-allocated) len x len array. The outer product will be stored here.
xA vector of length len.
yA vector of length len.
lenThe length of the input vectors.

Definition at line 281 of file matrix.c.

SPHINXBASE_EXPORT void scalarmultiply ( float32 **  inout_a,
float32  x,
int32  n 
)

Multiply a symmetric matrix by a constant in-place.

Parameters
inout_aThe matrix to multiply.
xThe constant to multiply it by.
ndimension of a.

Definition at line 295 of file matrix.c.

SPHINXBASE_EXPORT int32 solve ( float32 **  a,
float32 *  b,
float32 *  out_x,
int32  n 
)

Solve (if possible) a positive-definite system of linear equations AX=B for X.

Parameters
aThe A matrix on the left-hand side of the equation, must be positive-definite.
bThe B vector on the right-hand side of the equation.
out_xThe X vector will be stored here.
nThe dimension of the A matrix (n by n) and the B and X vectors.
Returns
0 for success or -1 for a non-positive-definite matrix.
Note
Only the upper triangular portion of a is considered, therefore the check for positive-definiteness is not reliable.

Definition at line 159 of file matrix.c.

References E_FATAL.