Linear Algebra

Utilities

void ksl_swapArray(const int n, double *a, const int a_stride, double *b, const int b_stride)
int ksl_maxIndex(const int n, const double *a)

Gram Schmidt Decomposition

void ksl_linalg_gramSchmidt(double *A, int m, int n)

Principal Component Analysis

void ksl_linalg_pca(ksl_mat3x3_t *A, ksl_mat3x3_t *v)

LU Decomposition

row major order

int ksl_linalg_lu_full_rmo(const int rowDim, const int colDim, double *A, const double eps, int *pr, int *pc)
int ksl_linalg_lu_full_specified_rmo(const int rowDim, const int colDim, double *A, double eps, int *pr, int *pc, const int specifiedIndex)
void ksl_linalg_lu_rmo(const int rank, const int colDim, double *A)
void ksl_linalg_lu_setBMatrix_rmo(const int rowDim, const int colDim, const int rank, double *A)
void ksl_linalg_lu_setCMatrix_rmo(int rowDim, int colDim, int rank, double *A)

compute Row Major Order C matrix

This block overwrites LR with LR*inverse(Lr) If rank==1, the Lr matrix is a 1 by 1 identity matrix, so there is nothing to do here. This loop computes A[rank:rowDim-1][0:rank-1]=LR*inverse(Lr) where LR is stored in A[rank:rowDim-1][0:rank-1] and Lr is stored in A[0:rank-1][0:rank-1]. j is the column number in LR. It ends at 1 because the diagonal entry in row 0 of Lr is 1. i is the row number in LR. k is the column number in Lr

Parameters
  • rowDim: [in] row dimension of matrix A.
  • colDim: [in] column dimension of matrix A.
  • rank: [in] rank of matrix A.
  • *A: [in/out] matrix with dimensions A[0:rowDim-1][0:colDim-1]:

column major order

int ksl_linalg_lu_full_cmo(const int rowDim, const int colDim, double *A, const double eps, int *pr, int *pc)
int ksl_linalg_lu_full_specified_cmo(const int rowDim, const int colDim, double *A, double eps, int *pr, int *pc, const int specifiedIndex)
void ksl_linalg_lu_cmo(const int rank, const int colDim, double *A)
void ksl_linalg_lu_setBMatrix_cmo(const int rowDim, const int colDim, const int rank, double *A)
void ksl_linalg_lu_setCMatrix_cmo(int rowDim, int colDim, int rank, double *A)

compute Column Major Order C matrix

This block overwrites LR with LR*inverse(Lr) If rank==1, the Lr matrix is a 1 by 1 identity matrix, so there is nothing to do here. This loop computes A[rank:rowDim-1][0:rank-1]=LR*inverse(Lr) where LR is stored in A[rank:rowDim-1][0:rank-1] and Lr is stored in A[0:rank-1][0:rank-1]. j is the column number in LR. It ends at 1 because the diagonal entry in row 0 of Lr is 1. i is the row number in LR. k is the column number in Lr

Parameters
  • rowDim: [in] row dimension of matrix A.
  • colDim: [in] column dimension of matrix A.
  • rank: [in] rank of matrix A.
  • *A: [in/out] matrix with dimensions A[0:rowDim-1][0:colDim-1]:

Cholesky Decomposition

row major order

int ksl_linalg_cholesky_rmo(double *A, const int n)
void ksl_linalg_cholesky_forwardElimination_rmo(const double *L, const double *b, double *y, const int n)
void ksl_linalg_cholesky_backwardSubstitution_rmo(const double *L, const double *y, double *x, const int n)
void ksl_linalg_cholesky_solve_rmo(const double *A, const double *b, double *x, const int n)

column major order

int ksl_linalg_ldlt_cmo(double *A, const int n)
int ksl_linalg_cholesky_cmo(double *A, const int n)
void ksl_linalg_cholesky_forwardElimination_cmo(const double *L, const double *b, double *y, const int n)
void ksl_linalg_cholesky_backwardSubstitution_cmo(const double *L, const double *y, double *x, const int n)
void ksl_linalg_cholesky_solve_cmo(const double *A, const double *b, double *x, const int n)

LDLT Decomposition

row major order

int ksl_linalg_ldlt_rmo(double *A, const int n)
void ksl_linalg_ldlt_forwardElimination_rmo(const double *L, const double *b, double *y, const int n)
void ksl_linalg_ldlt_backwardSubstitution_rmo(const double *L, const double *b, double *x, const int n)
void ksl_linalg_ldlt_solve_rmo(const double *A, const double *b, double *x, const int n)

column major order

int ksl_linalg_ldlt_cmo(double *A, const int n)
void ksl_linalg_ldlt_forwardElimination_cmo(const double *L, const double *b, double *y, const int n)
void ksl_linalg_ldlt_backwardSubstitution_cmo(const double *L, const double *b, double *x, const int n)
void ksl_linalg_ldlt_solve_cmo(const double *A, double *const b, double *x, const int n)

Symmetric Matrix Inverse

row major order

int ksl_linalg_symmetricMatrixInverse_rmo(double *A, const int n)

column major order

int ksl_linalg_symmetricMatrixInverse_cmo(double *A, const int n)