Macros | Functions
matd.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include "common/math_util.h"
#include "common/svd22.h"
#include "common/matd.h"
#include "common/debug_print.h"
Include dependency graph for matd.c:

Go to the source code of this file.

Macros

#define TYPE   double
 

Functions

matd_tmatd_add (const matd_t *a, const matd_t *b)
 
void matd_add_inplace (matd_t *a, const matd_t *b)
 
matd_chol_tmatd_chol (matd_t *A)
 
void matd_chol_destroy (matd_chol_t *chol)
 
matd_tmatd_chol_inverse (matd_t *a)
 
matd_tmatd_chol_solve (const matd_chol_t *chol, const matd_t *b)
 
matd_tmatd_copy (const matd_t *m)
 
matd_tmatd_create (int rows, int cols)
 
matd_tmatd_create_data (int rows, int cols, const TYPE *data)
 
matd_tmatd_create_dataf (int rows, int cols, const float *data)
 
matd_tmatd_create_scalar (TYPE v)
 
matd_tmatd_crossproduct (const matd_t *a, const matd_t *b)
 
void matd_destroy (matd_t *m)
 
double matd_det (const matd_t *a)
 
static double matd_det_general (const matd_t *a)
 
TYPE matd_err_inf (const matd_t *a, const matd_t *b)
 
TYPE matd_get (const matd_t *m, int row, int col)
 
TYPE matd_get_scalar (const matd_t *m)
 
matd_tmatd_identity (int dim)
 
matd_tmatd_inverse (const matd_t *x)
 
void matd_ltransposetriangle_solve (matd_t *u, const TYPE *b, TYPE *x)
 
void matd_ltriangle_solve (matd_t *L, const TYPE *b, TYPE *x)
 
double matd_max (matd_t *m)
 
matd_tmatd_multiply (const matd_t *a, const matd_t *b)
 
matd_tmatd_op (const char *expr,...)
 
static matd_tmatd_op_gobble_right (const char *expr, int *pos, matd_t *acc, matd_t **garb, int *garbpos)
 
static matd_tmatd_op_recurse (const char *expr, int *pos, matd_t *acc, matd_t **args, int *argpos, matd_t **garb, int *garbpos, int oneterm)
 
matd_plu_tmatd_plu (const matd_t *a)
 
void matd_plu_destroy (matd_plu_t *mlu)
 
double matd_plu_det (const matd_plu_t *mlu)
 
matd_tmatd_plu_l (const matd_plu_t *mlu)
 
matd_tmatd_plu_p (const matd_plu_t *mlu)
 
matd_tmatd_plu_solve (const matd_plu_t *mlu, const matd_t *b)
 
matd_tmatd_plu_u (const matd_plu_t *mlu)
 
void matd_print (const matd_t *m, const char *fmt)
 
void matd_print_transpose (const matd_t *m, const char *fmt)
 
void matd_put (matd_t *m, int row, int col, TYPE value)
 
void matd_put_scalar (matd_t *m, TYPE value)
 
matd_tmatd_scale (const matd_t *a, double s)
 
void matd_scale_inplace (matd_t *a, double s)
 
matd_tmatd_select (const matd_t *a, int r0, int r1, int c0, int c1)
 
matd_tmatd_solve (matd_t *A, matd_t *b)
 
matd_tmatd_subtract (const matd_t *a, const matd_t *b)
 
void matd_subtract_inplace (matd_t *a, const matd_t *b)
 
matd_svd_t matd_svd (matd_t *A)
 
matd_svd_t matd_svd_flags (matd_t *A, int flags)
 
static matd_svd_t matd_svd_tall (matd_t *A, int flags)
 
matd_tmatd_transpose (const matd_t *a)
 
void matd_utriangle_solve (matd_t *u, const TYPE *b, TYPE *x)
 
double matd_vec_dist (const matd_t *a, const matd_t *b)
 
double matd_vec_dist_n (const matd_t *a, const matd_t *b, int n)
 
double matd_vec_dot_product (const matd_t *a, const matd_t *b)
 
double matd_vec_mag (const matd_t *a)
 
matd_tmatd_vec_normalize (const matd_t *a)
 
static int max_idx (const matd_t *A, int row, int maxcol)
 

Macro Definition Documentation

◆ TYPE

#define TYPE   double

Definition at line 44 of file matd.c.

Function Documentation

◆ matd_add()

matd_t* matd_add ( const matd_t a,
const matd_t b 
)

Adds the two supplied matrices together, cell-by-cell, and returns the results as a new matrix of the same dimensions. The supplied matrices must have identical dimensions. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 291 of file matd.c.

◆ matd_add_inplace()

void matd_add_inplace ( matd_t a,
const matd_t b 
)

Adds the values of 'b' to matrix 'a', cell-by-cell, and overwrites the contents of 'a' with the results. The supplied matrices must have identical dimensions.

Definition at line 312 of file matd.c.

◆ matd_chol()

matd_chol_t* matd_chol ( matd_t A)

Definition at line 1852 of file matd.c.

◆ matd_chol_destroy()

void matd_chol_destroy ( matd_chol_t chol)

Definition at line 1899 of file matd.c.

◆ matd_chol_inverse()

matd_t* matd_chol_inverse ( matd_t a)

Definition at line 2002 of file matd.c.

◆ matd_chol_solve()

matd_t* matd_chol_solve ( const matd_chol_t chol,
const matd_t b 
)

Definition at line 1950 of file matd.c.

◆ matd_copy()

matd_t* matd_copy ( const matd_t m)

Creates an exact copy of the supplied matrix 'm'. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 154 of file matd.c.

◆ matd_create()

matd_t* matd_create ( int  rows,
int  cols 
)

Creates a double matrix with the given number of rows and columns (or a scalar in the case where rows=0 and/or cols=0). All data elements will be initialized to zero. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 46 of file matd.c.

◆ matd_create_data()

matd_t* matd_create_data ( int  rows,
int  cols,
const TYPE data 
)

Definition at line 71 of file matd.c.

◆ matd_create_dataf()

matd_t* matd_create_dataf ( int  rows,
int  cols,
const float *  data 
)

Creates a double matrix with the given number of rows and columns (or a scalar in the case where rows=0 and/or cols=0). All data elements will be initialized using the supplied array of float data, which must contain at least rows*cols elements, arranged in row-major order (i.e. index = row*ncols + col). It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 83 of file matd.c.

◆ matd_create_scalar()

matd_t* matd_create_scalar ( TYPE  v)

Definition at line 61 of file matd.c.

◆ matd_crossproduct()

matd_t* matd_crossproduct ( const matd_t a,
const matd_t b 
)

Calculates the cross product of supplied matrices 'a' and 'b' (i.e. a x b) and returns it as a new matrix. Both 'a' and 'b' must be vectors of dimension 3, but can be either row or column vectors. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 939 of file matd.c.

◆ matd_destroy()

void matd_destroy ( matd_t m)

Frees the memory associated with matrix 'm', being the result of an earlier call to a matd_*() function, after which 'm' will no longer be usable.

Definition at line 222 of file matd.c.

◆ matd_det()

double matd_det ( const matd_t a)

Calculates the determinant of the supplied matrix 'a'.

Definition at line 421 of file matd.c.

◆ matd_det_general()

static double matd_det_general ( const matd_t a)
static

Definition at line 391 of file matd.c.

◆ matd_err_inf()

TYPE matd_err_inf ( const matd_t a,
const matd_t b 
)

Definition at line 954 of file matd.c.

◆ matd_get()

TYPE matd_get ( const matd_t m,
int  row,
int  col 
)

Retrieves the cell value for matrix 'm' at the given zero-based row and column index. Performs more thorough validation checking than MATD_EL().

Definition at line 108 of file matd.c.

◆ matd_get_scalar()

TYPE matd_get_scalar ( const matd_t m)

Retrieves the scalar value of the given element ('m' must be a scalar). Performs more thorough validation checking than MATD_EL().

Definition at line 138 of file matd.c.

◆ matd_identity()

matd_t* matd_identity ( int  dim)

Creates a square identity matrix with the given number of rows (and therefore columns), or a scalar with value 1 in the case where dim=0. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 95 of file matd.c.

◆ matd_inverse()

matd_t* matd_inverse ( const matd_t a)

Attempts to compute an inverse of the supplied matrix 'a' and return it as a new matrix. This is strictly only possible if the determinant of 'a' is non-zero (matd_det(a) != 0).

If the determinant is zero, NULL is returned. It is otherwise the caller's responsibility to cope with the results caused by poorly conditioned matrices. (E.g.., if such a situation is likely to arise, compute the pseudo-inverse from the SVD.)

Definition at line 481 of file matd.c.

◆ matd_ltransposetriangle_solve()

void matd_ltransposetriangle_solve ( matd_t u,
const TYPE b,
TYPE x 
)

Definition at line 1906 of file matd.c.

◆ matd_ltriangle_solve()

void matd_ltriangle_solve ( matd_t L,
const TYPE b,
TYPE x 
)

Definition at line 1920 of file matd.c.

◆ matd_max()

double matd_max ( matd_t m)

Definition at line 2016 of file matd.c.

◆ matd_multiply()

matd_t* matd_multiply ( const matd_t a,
const matd_t b 
)

Multiplies the two supplied matrices together (matrix product), and returns the results as a new matrix. The supplied matrices must have dimensions such that columns(a) = rows(b). The returned matrix will have a row count of rows(a) and a column count of columns(b). It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 231 of file matd.c.

◆ matd_op()

matd_t* matd_op ( const char *  expr,
  ... 
)

Creates a new matrix by applying a series of matrix operations, as expressed in 'expr', to the supplied list of matrices. Each matrix to be operated upon must be represented in the expression by a separate matrix placeholder, 'M', and there must be one matrix supplied as an argument for each matrix placeholder in the expression. All rules and caveats of the corresponding matrix operations apply to the operated-on matrices. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Available operators (in order of increasing precedence): M+M add two matrices together M-M subtract one matrix from another M*M multiply two matrices together (matrix product) MM multiply two matrices together (matrix product) -M negate a matrix M^-1 take the inverse of a matrix M' take the transpose of a matrix

Expressions can be combined together and grouped by enclosing them in parenthesis, i.e.: -M(M+M+M)-(M*M)^-1

Scalar values can be generated on-the-fly, i.e.: M*2.2 scales M by 2.2 -2+M adds -2 to all elements of M

All whitespace in the expression is ignored.

Definition at line 794 of file matd.c.

◆ matd_op_gobble_right()

static matd_t* matd_op_gobble_right ( const char *  expr,
int *  pos,
matd_t acc,
matd_t **  garb,
int *  garbpos 
)
inlinestatic

Definition at line 552 of file matd.c.

◆ matd_op_recurse()

static matd_t* matd_op_recurse ( const char *  expr,
int *  pos,
matd_t acc,
matd_t **  args,
int *  argpos,
matd_t **  garb,
int *  garbpos,
int  oneterm 
)
static

Definition at line 594 of file matd.c.

◆ matd_plu()

matd_plu_t* matd_plu ( const matd_t a)

Definition at line 1512 of file matd.c.

◆ matd_plu_destroy()

void matd_plu_destroy ( matd_plu_t mlu)

Definition at line 1592 of file matd.c.

◆ matd_plu_det()

double matd_plu_det ( const matd_plu_t mlu)

Definition at line 1600 of file matd.c.

◆ matd_plu_l()

matd_t* matd_plu_l ( const matd_plu_t mlu)

Definition at line 1625 of file matd.c.

◆ matd_plu_p()

matd_t* matd_plu_p ( const matd_plu_t mlu)

Definition at line 1613 of file matd.c.

◆ matd_plu_solve()

matd_t* matd_plu_solve ( const matd_plu_t mlu,
const matd_t b 
)

Definition at line 1660 of file matd.c.

◆ matd_plu_u()

matd_t* matd_plu_u ( const matd_plu_t mlu)

Definition at line 1641 of file matd.c.

◆ matd_print()

void matd_print ( const matd_t m,
const char *  fmt 
)

Prints the supplied matrix 'm' to standard output by applying the supplied printf format specifier 'fmt' for each individual element. Each row will be printed on a separate newline.

Definition at line 186 of file matd.c.

◆ matd_print_transpose()

void matd_print_transpose ( const matd_t m,
const char *  fmt 
)

Prints the transpose of the supplied matrix 'm' to standard output by applying the supplied printf format specifier 'fmt' for each individual element. Each row will be printed on a separate newline.

Definition at line 204 of file matd.c.

◆ matd_put()

void matd_put ( matd_t m,
int  row,
int  col,
TYPE  value 
)

Definition at line 121 of file matd.c.

◆ matd_put_scalar()

void matd_put_scalar ( matd_t m,
TYPE  value 
)

Definition at line 146 of file matd.c.

◆ matd_scale()

matd_t* matd_scale ( const matd_t a,
double  s 
)

Scales all cell values of matrix 'a' by the given scale factor 's' and returns the result as a new matrix of the same dimensions. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 257 of file matd.c.

◆ matd_scale_inplace()

void matd_scale_inplace ( matd_t a,
double  s 
)

Scales all cell values of matrix 'a' by the given scale factor 's' and overwrites the contents of 'a' with the results.

Definition at line 275 of file matd.c.

◆ matd_select()

matd_t* matd_select ( const matd_t a,
int  r0,
int  r1,
int  c0,
int  c1 
)

Creates a copy of a subset of the supplied matrix 'a'. The subset will include rows 'r0' through 'r1', inclusive ('r1' >= 'r0'), and columns 'c0' through 'c1', inclusive ('c1' >= 'c0'). All parameters are zero-based (i.e. matd_select(a, 0, 0, 0, 0) will return only the first cell). Cannot be used on scalars or to extend beyond the number of rows/columns of 'a'. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 167 of file matd.c.

◆ matd_solve()

matd_t* matd_solve ( matd_t A,
matd_t b 
)

Definition at line 1693 of file matd.c.

◆ matd_subtract()

matd_t* matd_subtract ( const matd_t a,
const matd_t b 
)

Subtracts matrix 'b' from matrix 'a', cell-by-cell, and returns the results as a new matrix of the same dimensions. The supplied matrices must have identical dimensions. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 332 of file matd.c.

◆ matd_subtract_inplace()

void matd_subtract_inplace ( matd_t a,
const matd_t b 
)

Subtracts the values of 'b' from matrix 'a', cell-by-cell, and overwrites the contents of 'a' with the results. The supplied matrices must have identical dimensions.

Definition at line 353 of file matd.c.

◆ matd_svd()

matd_svd_t matd_svd ( matd_t A)

Compute a complete SVD of a matrix. The SVD exists for all matrices. For a matrix MxN, we will have:

A = U*S*V'

where A is MxN, U is MxM (and is an orthonormal basis), S is MxN (and is diagonal up to machine precision), and V is NxN (and is an orthonormal basis).

The caller is responsible for destroying U, S, and V.

Definition at line 1459 of file matd.c.

◆ matd_svd_flags()

matd_svd_t matd_svd_flags ( matd_t A,
int  flags 
)

Definition at line 1464 of file matd.c.

◆ matd_svd_tall()

static matd_svd_t matd_svd_tall ( matd_t A,
int  flags 
)
static

Definition at line 979 of file matd.c.

◆ matd_transpose()

matd_t* matd_transpose ( const matd_t a)

Creates a matrix which is the transpose of the supplied matrix 'a'. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 373 of file matd.c.

◆ matd_utriangle_solve()

void matd_utriangle_solve ( matd_t u,
const TYPE b,
TYPE x 
)

Definition at line 1936 of file matd.c.

◆ matd_vec_dist()

double matd_vec_dist ( const matd_t a,
const matd_t b 
)

Calculates the magnitude of the distance between the points represented by matrices 'a' and 'b'. Both 'a' and 'b' must be vectors and have the same dimension (although one may be a row vector and one may be a column vector).

Definition at line 858 of file matd.c.

◆ matd_vec_dist_n()

double matd_vec_dist_n ( const matd_t a,
const matd_t b,
int  n 
)

Same as matd_vec_dist, but only uses the first 'n' terms to compute distance

Definition at line 869 of file matd.c.

◆ matd_vec_dot_product()

double matd_vec_dot_product ( const matd_t a,
const matd_t b 
)

Calculates the dot product of two vectors. Both 'a' and 'b' must be vectors and have the same dimension (although one may be a row vector and one may be a column vector).

Definition at line 905 of file matd.c.

◆ matd_vec_mag()

double matd_vec_mag ( const matd_t a)

Calculates the magnitude of the supplied matrix 'a'.

Definition at line 846 of file matd.c.

◆ matd_vec_normalize()

matd_t* matd_vec_normalize ( const matd_t a)

Calculates the normalization of the supplied vector 'a' (i.e. a unit vector of the same dimension and orientation as 'a' with a magnitude of 1) and returns it as a new vector. 'a' must be a vector of any dimension and must have a non-zero magnitude. It is the caller's responsibility to call matd_destroy() on the returned matrix.

Definition at line 922 of file matd.c.

◆ max_idx()

static int max_idx ( const matd_t A,
int  row,
int  maxcol 
)
inlinestatic

Definition at line 887 of file matd.c.



apriltag
Author(s): Edwin Olson , Max Krogius
autogenerated on Mon Jun 26 2023 02:26:35