FancySafeBot 0.0.1
A safe robotics library
Loading...
Searching...
No Matches
Linear Algebra

Linear algebra utility for matrix and vector computations. More...

Macros

#define FSB_MAX(a, b)   (((a) > (b)) ? (a) : (b))
 
#define FSB_MIN(a, b)   (((a) < (b)) ? (a) : (b))
 

Typedefs

typedef double double_t
 Floating point type.
 
typedef enum FsbLapackErrorType FsbLinalgErrorType
 Error codes for linear algebra functions.
 

Enumerations

enum  FsbLapackErrorType {
  EFSB_LAPACK_ERROR_NONE = 0 , EFSB_LAPACK_ERROR_INPUT = 1 , EFSB_LAPACK_ERROR_MEMORY = 2 , EFSB_LAPACK_ERROR_CONVERGE = 3 ,
  EFSB_LAPACK_ERROR_QUERY = 4 , EFSB_LAPACK_NOT_POSITIVE_DEFINITE = 5 , EFSB_LAPACK_SINGULAR = 6 , EFSB_LAPACK_ERROR_NOT_FULL_RANK = 7
}
 Error codes for linear algebra functions. More...
 

Functions

FsbLinalgErrorType fsb_linalg_svd (const double_t mat[], size_t rows, size_t cols, bool u_full, bool v_full, size_t work_len, double_t work[], double_t unitary_u[], double_t sing_val[], double_t unitary_vt[])
 SVD decomposition.
 
FsbLinalgErrorType fsb_linalg_matrix_eig (const double_t mat[], size_t dim, size_t work_len, double_t work[], double_t val_real[], double_t val_imag[], double_t vec_real[], double_t vec_imag[])
 Eigenvalue decomposition.
 
FsbLinalgErrorType fsb_linalg_sym_lt_eig (const double_t mat[], size_t dim, size_t work_len, double_t work[], double_t val[], double_t vec[])
 Eigenvalue decomposition for symmetric lower triangular matrix.
 
FsbLinalgErrorType fsb_linalg_cholesky_decomposition (const double_t mat[], size_t dim, double_t mat_chol[])
 Cholesky factorization for symmetric positive definite matrix.
 
FsbLinalgErrorType fsb_linalg_cholesky_solve (const double_t mat[], const double_t b_vec[], size_t nrhs, size_t dim, size_t work_len, double_t work[], double_t x_vec[])
 Cholesky solve.
 
bool fsb_linalg_is_posdef (const double_t mat[], size_t dim, size_t work_len, double_t work[])
 Check if lower triangular symmetric matrix is positive definite.
 
FsbLinalgErrorType fsb_linalg_matrix_sqr_solve (const double_t mat[], const double_t y_vec[], size_t nrhs, size_t dim, size_t work_len, size_t iwork_len, double_t work[], int iwork[], double_t x_vec[])
 
FsbLinalgErrorType fsb_linalg_pseudoinverse (const double_t mat[], size_t rows, size_t columns, size_t work_len, double_t work[], double_t inv_mat[])
 Inverse of a matrix where number of columns are great er than or equal to number of rows.
 
FsbLinalgErrorType fsb_linalg_leastsquares_solve (const double_t mat[], size_t rows, size_t columns, const double_t b_vec[], size_t nrhs, size_t work_len, double_t work[], double_t x_vec[])
 Solve overdetermined or underdetermined system using least squares.
 
void sample_dgels_example (void)
 

Detailed Description

Linear algebra utility for matrix and vector computations.

Enumeration Type Documentation

◆ FsbLapackErrorType

Error codes for linear algebra functions.

Enumerator
EFSB_LAPACK_ERROR_NONE 

No error.

EFSB_LAPACK_ERROR_INPUT 

Input value error.

EFSB_LAPACK_ERROR_MEMORY 

Not enough memory.

EFSB_LAPACK_ERROR_CONVERGE 

Solution did not converge.

EFSB_LAPACK_ERROR_QUERY 

Work query failed.

EFSB_LAPACK_NOT_POSITIVE_DEFINITE 

Matrix not positive definite.

EFSB_LAPACK_SINGULAR 

Input matrix is singular.

EFSB_LAPACK_ERROR_NOT_FULL_RANK 

Matrix is not full rank.

Function Documentation

◆ fsb_linalg_cholesky_decomposition()

FsbLinalgErrorType fsb_linalg_cholesky_decomposition ( const double_t  mat[],
size_t  dim,
double_t  mat_chol[] 
)

Cholesky factorization for symmetric positive definite matrix.

Parameters
matInput matrix (dim x dim)
dimMatrix A dimension s
mat_cholCholesky factorization of input matrix A (dim x dim)
Returns
Error code

◆ fsb_linalg_cholesky_solve()

FsbLinalgErrorType fsb_linalg_cholesky_solve ( const double_t  mat[],
const double_t  b_vec[],
size_t  nrhs,
size_t  dim,
size_t  work_len,
double_t  work[],
double_t  x_vec[] 
)

Cholesky solve.

square symmetric positive-definite matrix cholesky solve. solve for b from x = A b Variable x is overwritten by b on exit

Parameters
mat
b_vec
nrhs
dim
work_len
work
x_vec
Returns

◆ fsb_linalg_is_posdef()

bool fsb_linalg_is_posdef ( const double_t  mat[],
size_t  dim,
size_t  work_len,
double_t  work[] 
)

Check if lower triangular symmetric matrix is positive definite.

Parameters
matInput lower triangular matrix (sxs)
dimMatrix A dimension
work_lenWork vector length
workWork vector
Returns
true
false

◆ fsb_linalg_leastsquares_solve()

FsbLinalgErrorType fsb_linalg_leastsquares_solve ( const double_t  mat[],
size_t  rows,
size_t  columns,
const double_t  b_vec[],
size_t  nrhs,
size_t  work_len,
double_t  work[],
double_t  x_vec[] 
)

Solve overdetermined or underdetermined system using least squares.

Solves min ||A*X - B|| for X where A is an M-by-N matrix using the singular value decomposition (SVD) approach. This method handles rank-deficient least squares problems more robustly than the QR approach.

Parameters
matInput matrix A (rows x columns)
rowsNumber of rows in A
columnsNumber of columns in A
b_vecRight-hand side matrix B (rows x nrhs)
nrhsNumber of right-hand side vectors
work_lenLength of work vector
workWork vector
x_vecOutput solution matrix X (columns x nrhs).
Returns
Error code

◆ fsb_linalg_matrix_eig()

FsbLinalgErrorType fsb_linalg_matrix_eig ( const double_t  mat[],
size_t  dim,
size_t  work_len,
double_t  work[],
double_t  val_real[],
double_t  val_imag[],
double_t  vec_real[],
double_t  vec_imag[] 
)

Eigenvalue decomposition.

Parameters
[in]matinput matrix (sxs)
[in]dimmatrix A dimension
[in]work_lenbuffer
[in,out]workbuffer
[out]val_realreal components of the eigenvalues (sx1)
[out]val_imagimaginary components of the eigenvalues (sx1)
[out]vec_realreal components of the eigenvectors (sxs)
[out]vec_imagimaginary components of the eigenvectors (sxs)
Returns
error code

◆ fsb_linalg_matrix_sqr_solve()

FsbLinalgErrorType fsb_linalg_matrix_sqr_solve ( const double_t  mat[],
const double_t  y_vec[],
size_t  nrhs,
size_t  dim,
size_t  work_len,
size_t  iwork_len,
double_t  work[],
int  iwork[],
double_t  x_vec[] 
)

@biref Solve linear system of equations with a square matrix

Parameters
matMatrix to solve (dim x dim)
y_vecRight-hand side vector (dim x nrhs)
nrhsNumber of right-hand side vectors
dimMatrix A dimension (s)
work_lenWork vector length
iwork_lenInteger work vector length
workWork vector
iworkInteger work vector
x_vecOutput Solution vector (dim x nrhs)
Returns
Error code

◆ fsb_linalg_pseudoinverse()

FsbLinalgErrorType fsb_linalg_pseudoinverse ( const double_t  mat[],
size_t  rows,
size_t  columns,
size_t  work_len,
double_t  work[],
double_t  inv_mat[] 
)

Inverse of a matrix where number of columns are great er than or equal to number of rows.

Work length must be at least rows * MIN(rows, columns) + MIN(rows, columns) + MIN(rows, columns) * columns and additional length required by the fsb_linalg_svd function.

Parameters
matInput matrix (rows x columns)
rowsNumber of rows in matrix
columnsNumber of columns in matrix
work_lenLength of work vector
workWork vector
inv_matOutput inverse matrix (columns x rows)
Returns
Error code

◆ fsb_linalg_svd()

FsbLinalgErrorType fsb_linalg_svd ( const double_t  mat[],
size_t  rows,
size_t  cols,
bool  u_full,
bool  v_full,
size_t  work_len,
double_t  work[],
double_t  unitary_u[],
double_t  sing_val[],
double_t  unitary_vt[] 
)

SVD decomposition.

u_full and v_full affect the output matrices as follows: if (m < n) then s = m else s = n if (u_full, v_full) == (0, 0) then U(m,s), S(s,s), VT(s,n) if (u_full, v_full) == (1, 0) then U(m,m), S(m,s), VT(s,n) if (u_full, v_full) == (0, 1) then U(m,s), S(s,n), VT(n,n) if (u_full, v_full) == (1, 1) then U(m,m), S(m,n), VT(n,n)

Parameters
[in]matmatrix to perform SVD
[in]rowsrows of A
[in]colscolumns of A
[in]u_fullBoolean for full U matrix
[in]v_fullBoolean for full V matrix
[in]work_lenbuffer
[in,out]workbuffer
[out]unitary_uUnitary matrix U (m x m)
[out]sing_valSingular values array S (s x 1)
[out]unitary_vtTranspose of unitary matrix V (n x n)

◆ fsb_linalg_sym_lt_eig()

FsbLinalgErrorType fsb_linalg_sym_lt_eig ( const double_t  mat[],
size_t  dim,
size_t  work_len,
double_t  work[],
double_t  val[],
double_t  vec[] 
)

Eigenvalue decomposition for symmetric lower triangular matrix.

Parameters
[in]matinput matrix (sxs)
[in]dimmatrix A dimension
[in]work_lenbuffer
[in,out]workbuffer
[out]valeigenvalues (sx1)
[out]veccolumn eigenvectors (sxs)