|
Robotat Linalg
|
Matrix Linear Algebra Operations. More...
Data Structures | |
| struct | matf32_t |
| Floating point matrix data structure. More... | |
Enumerations | |
| enum | err_status_t { MATH_SUCCESS , MATH_ARGUMENT_ERROR , MATH_LENGTH_ERROR , MATH_SIZE_MISMATCH , MATH_NANINF , MATH_SINGULAR , MATH_TEST_FAILURE , MATH_DECOMPOSITION_FAILURE } |
| Error status from matrix operations. More... | |
| enum | pseudoinverse_methods_t { BASIC_PINV , SVD_PINV } |
| Available methods to calculate the pseudoinverse of a matrix. More... | |
Functions | |
| float | dot (float *p_srca, float *p_srcb, uint16_t length) |
| Find the dot product of two vectors, pointed by p_srca and p_srcb, of the same size. Assign to a float variable to store the result. Both vectores need to have the same length. | |
| void | eye (float *p_dst, uint16_t row, uint16_t column) |
| Create an identity matrix array with size row x column. | |
| void | diag (float *p_src, float *p_dst, int row_d, int column_d) |
| Creates a diagonal matrix array from the vector pointed by p_src and storing the result into a vector pointed by p_dst, with size row x column. Notice that the row of vector x needs to have the same length as the column of the matrix. | |
| void | zeros (float *p_dst, int row, int column) |
| Turn into 0 all the elements of the matrix array pointed by p_dst (size row x column). | |
| void | ones (float *p_dst, int row, int column) |
| Turn into 1 all the elements of the matrix array pointed by p_dst (size row x column). | |
| void | randn (float *p_dst, uint16_t length, float mu, float sigma) |
| Creates a random array with values sampled from a normal (Gaussian) distribution. | |
| float | norm (float *p_src, int row, int column) |
| Calculates the norm of a given matrix (euclidean for vectors, frobenius for matrices). Assign to a float variable to store the result of the norm. | |
| void | scale (float *p_src, uint16_t length, float scalar, float *p_dst) |
| Multiplies a vector by a scalar, stores the result in a vector (can be the same as the input vector or a different vector). | |
| void | copy (float *p_src, float *p_dst, int row, int column) |
| Size-aware matrix copy. | |
| void | print (float *p_src, uint16_t row, uint16_t column) |
| Prints an array to the console (formatted). | |
| float | saturation (float input, float lower_limit, float upper_limit) |
| Saturates the input, given upper and lower limits. | |
| float | sign (float number) |
| Gets the input's sign by checking if the number is greater, equal to, or less than 0. | |
| float | mean (float *p_src, uint16_t length) |
| Gets the mean of a given array. | |
| float | std_dev (float *p_src, uint16_t length) |
| Gets the standard deviation of a given array. Named this way instead of "std" to avoid conflict with std namesapce in c++. | |
| bool | is_equal (float *p_a, float *p_b, uint16_t length) |
| Checks if two arrays are equal, taking into account a margin or tolerance. For this, it uses the function is_equal_margin. | |
| void | zero_patch (float *p_a, uint16_t length) |
| Changes NaN and Inf values to zero. Needed to avoid errors in cases where irrelevant elements end set as NaN or Inf. | |
| void | matf32_init (matf32_t *const instance, uint16_t num_rows, uint16_t num_cols, float *p_data) |
| Constructor for the floating point matrix data structure. | |
| void | matf32_print (const matf32_t *p_src) |
| Prints matrix data to console (formatted to print as a matrix). | |
| void | err_status_print (err_status_t err) |
| Prints error status err_status_t to console. For example: prints MATH_SUCCESS for MATH_SUCCESS, MATH_SINGULAR for MATH_SINGULAR, etc. | |
| void | matf32_cond (const matf32_t *const p_src, float *p_cond) |
| Calculates condition number of a matrix. This routine is useful for monitoring the behavior of matrices, as a higher condition number may lead to approximation issues or unexpected behavior in some operations. | |
| err_status_t | matf32_submatrix_copy (const matf32_t *const p_src, matf32_t *const p_dst, const uint16_t src_row, const uint16_t src_col, const uint16_t dst_row, const uint16_t dst_col, const uint16_t rows, const uint16_t cols) |
| Copies a specified number of rows and columns from a matrix into another matrix. That means, it can either copy an entire matrix to another one, or just a submatrix of the former. | |
| void | matf32_set_row (matf32_t *const p_dst, uint16_t row, float val) |
| Sets all elements in a matrix row to a specified value. | |
| void | matf32_set_col (matf32_t *const p_dst, uint16_t col, float val) |
| Sets all elements in a matrix column to a specified value. | |
| void | matf32_eye (matf32_t *const p_dst) |
| Sets a matrix structure to the identity matrix. | |
| void | matf32_diag (float *p_src, matf32_t *const p_dst) |
| Sets a matrix structure to a diagonal matrix, created from a given vector. | |
| void | matf32_zeros (matf32_t *const p_dst) |
| Sets a matrix structure to the zero matrix. | |
| void | matf32_ones (matf32_t *const p_dst) |
| Sets a matrix structure to a ones matrix. | |
| void | matf32_randn (matf32_t *const p_dst, float mu, float sigma) |
| Sets a matrix structure to a matrix with random entries, sampled from a normal distribution. | |
| bool | matf32_check_triangular_upper (const matf32_t *const p_mat) |
| Checks if matrix is upper triangular. | |
| bool | matf32_check_triangular_lower (const matf32_t *const p_mat) |
| Checks if matrix is lower triangular. | |
| bool | matf32_is_equal (const matf32_t *const p_mat_a, const matf32_t *const p_mat_b) |
| Checks if two matrices are equal. | |
| bool | matf32_is_equal_scalar (const matf32_t *const p_mat, float scalar) |
| Checks if a matrix values are equal to a scalar. | |
| bool | matf32_is_equal_less_scalar (const matf32_t *const p_mat, float scalar) |
| Checks if a matrix values are equal or lesser than a scalar. | |
| bool | matf32_check_symmetric (const matf32_t *const p_mat) |
| Checks if a matrix is symmetric. | |
| bool | matf32_check_hessenberg_upper (const matf32_t *const p_mat) |
| Checks if a matrix is upper hessenberg. | |
| bool | matf32_check_hessenberg_lower (const matf32_t *const p_mat) |
| Checks if a matrix is lower hessenberg. | |
| bool | matf32_check_symposdef (const matf32_t *const p_mat) |
| Checks if a matrix is symmetric positive definite. | |
| err_status_t | matf32_add (const matf32_t *p_srca, const matf32_t *p_srcb, matf32_t *p_dst) |
| Adds two matrices and saves the result in another matrix. The result can be saved either in a new matf32_t matrix or in one of the input matrices (overwriting its previous contents). Both must have the same dimensions. | |
| err_status_t | matf32_sub (const matf32_t *p_srca, const matf32_t *p_srcb, matf32_t *p_dst) |
| Substracts two matrices and saves the result in another matrix. The result can be saved either in a new matf32_t matrix or in one of the input matrices (overwriting its previous contents). Both need to be of the same dimension. | |
| err_status_t | matf32_scale (const matf32_t *p_src, float scalar, matf32_t *p_dst) |
| Multiplies a matrix by a scalar, element-wise, and saves the result in another matrix. The result can be saved either in a new matf32_t matrix or in one of the input matrices (overwriting its previous contents). | |
| err_status_t | matf32_trans (const matf32_t *p_src, matf32_t *p_dst) |
| Transposes a matrix and saves the result in another matrix. | |
| err_status_t | matf32_mul (const matf32_t *p_srca, const matf32_t *p_srcb, matf32_t *p_dst) |
| Multiplies two matrices. The number of columns of the first matrix must be the same as the number of rows of the second matrix. | |
| err_status_t | matf32_lup (const matf32_t *p_src, matf32_t *p_lu, uint16_t *pivot) |
| Computes the LU decomposition (with partial pivoting) of a square matrix A, pointed by p_src, such that PA = LU. | |
| err_status_t | matf32_inv (const matf32_t *p_src, matf32_t *p_dst) |
| Computes the inverse of a square, non-singular matrix. | |
| err_status_t | matf32_pinv (const matf32_t *const p_a, matf32_t *const p_dst, pseudoinverse_methods_t method) |
| Calculates the pseudoinverse of a given matrix using the singular values of the SVD decomposition of A. | |
| err_status_t | matf32_dot (const matf32_t *const p_srca, const matf32_t *const p_srcb, float *const p_dst) |
| Dot product between two vectors (wether row or column). | |
| void | matf32_vecposmul (const matf32_t *p_srcm, float *p_srcv, float *p_dst) |
| Matrix-vector post multiplication, i.e. Ax. Assumes a column vector. | |
| void | matf32_vecpremul (const matf32_t *p_srcm, float *p_srcv, float *p_dst) |
| vector-Matrix pre multiplication, i.e. xA. Assumes a row vector. | |
| void | matf32_vecmul_col_row (const float *const col_vec, const float *const row_vec, matf32_t *const p_dst) |
| Vector-Vector Multiplication (the result is a matrix). | |
| err_status_t | matf32_exp (const matf32_t *const p_src, matf32_t *const p_dst, uint16_t exp) |
| Calculates the power of a matrix to a given exponent. | |
| err_status_t | matf32_arr_add (const matf32_t **const p_matarray, uint16_t length, matf32_t *p_dst) |
| Adds an array of matrices sequentially. The size of all matrices must be the same. | |
| err_status_t | matf32_arr_sub (const matf32_t **const p_matarray, uint16_t length, matf32_t *p_dst) |
| Subtracts an array of matrices sequentially. The size of all matrices must be the same. | |
| err_status_t | matf32_arr_mul (const matf32_t **const p_matarray, uint16_t length, matf32_t *p_dst) |
| Multiplies an array of matrices sequentially. The number of columns of any matrix must be the same as the number of rows of the next. Output matrix cannot be the same as one of the inputs. | |
| err_status_t | matf32_qr (const matf32_t *const p_a, matf32_t *const p_q, matf32_t *const p_r) |
| Computes the Householder QR factorization of a matrix A, saving the Q and R factors in different matrices. | |
| err_status_t | matf32_lu (const matf32_t *p_a, matf32_t *const p_l, matf32_t *const p_u, uint16_t *p_index) |
| Computes the LU decomposition of a square matrix A, pointed by p_a, such that PA = LU, and saves the L and U factors in different matrices, and the list of permutations corresponding to the matrix P are saved in an array to save memory. | |
| err_status_t | matf32_cholesky (const matf32_t *const p_a, matf32_t *const p_c) |
| Calculates the Cholesky decomposition of a matrix A = LL', where L is a lowe triangular matrix. | |
| err_status_t | matf32_one_sided_jacobi (const matf32_t *const p_a, matf32_t *const p_v, uint16_t j, uint16_t k) |
| Generates and applies a one-sided jacobi rotation to matrix A and saves the result as A = AV and V (an orthonormal matrix to accumulate the rotations applied). | |
| err_status_t | matf32_jacobi_svd (const matf32_t *const p_a, matf32_t *const p_u, matf32_t *const p_s, matf32_t *const p_v) |
| Calculates the SVD of a matrix using using the one-sided Jacobi algorithm. | |
Matrix Linear Algebra Operations.
Last modified: 18 Nov. 2026 By: Andrea Pineda
| struct matf32_t |
| enum err_status_t |
Error status from matrix operations.
Defined this way for compatibility with ARM's CMSIS-DSP library.
| Enumerator | |
|---|---|
| MATH_SUCCESS | Successfull mathematical operation. |
| MATH_ARGUMENT_ERROR | Error in an input matf32_t instance. |
| MATH_LENGTH_ERROR | Incorrect size for one of the dimensions of a matf32_t instance. |
| MATH_SIZE_MISMATCH | matf32_t matrix dimensions don't match and thus cannot be operated as needed. |
| MATH_NANINF | Result has NaN or Inf values. |
| MATH_SINGULAR | Matrix is singular or close to singular and may impact negatively the precision of the results. |
| MATH_TEST_FAILURE | Matrix operation failure. |
| MATH_DECOMPOSITION_FAILURE | Matrix factorization or decomposition failed. |
| void copy | ( | float * | p_src, |
| float * | p_dst, | ||
| int | row, | ||
| int | column ) |
Size-aware matrix copy.
| [in] | p_src | Points to matrix to copy from. |
| [in,out] | p_dst | Points to matrix to copy to. |
| [in] | row | Number of rows of the matrix. |
| [in] | column | Number of columns of the matrix. |
| void diag | ( | float * | p_src, |
| float * | p_dst, | ||
| int | row_d, | ||
| int | column_d ) |
Creates a diagonal matrix array from the vector pointed by p_src and storing the result into a vector pointed by p_dst, with size row x column. Notice that the row of vector x needs to have the same length as the column of the matrix.
| [in] | p_src | Points to vector with diagonal entries. |
| [in,out] | p_dst | Points to array to allocate the diagonal matrix. |
| [in] | row_d | Number of required rows. |
| [in] | column_d | Number of required columns. |
| float dot | ( | float * | p_srca, |
| float * | p_srcb, | ||
| uint16_t | length ) |
Find the dot product of two vectors, pointed by p_srca and p_srcb, of the same size. Assign to a float variable to store the result. Both vectores need to have the same length.
| [in] | p_srca | Points to vector 1. |
| [in] | p_srcb | Points to vector 2. |
| [in] | length | Length of vectors. |
| void err_status_print | ( | err_status_t | err | ) |
Prints error status err_status_t to console. For example: prints MATH_SUCCESS for MATH_SUCCESS, MATH_SINGULAR for MATH_SINGULAR, etc.
| [in] | err | Error stats value to print. |
| void eye | ( | float * | p_dst, |
| uint16_t | row, | ||
| uint16_t | column ) |
Create an identity matrix array with size row x column.
| [in,out] | p_dst | Points to array to allocate the identity matrix. |
| [in] | row | Number of required rows. |
| [in] | column | Number of required columns. |
| bool is_equal | ( | float * | p_a, |
| float * | p_b, | ||
| uint16_t | length ) |
Checks if two arrays are equal, taking into account a margin or tolerance. For this, it uses the function is_equal_margin.
| [in] | p_a | Points to first array. |
| [in] | p_b | Points to second array. |
| [in] | length | Arrays length. |
| err_status_t matf32_add | ( | const matf32_t * | p_srca, |
| const matf32_t * | p_srcb, | ||
| matf32_t * | p_dst ) |
Adds two matrices and saves the result in another matrix. The result can be saved either in a new matf32_t matrix or in one of the input matrices (overwriting its previous contents). Both must have the same dimensions.
| [in] | p_srca | Points to first input matrix structure. |
| [in] | p_srcb | Points to second input matrix structure. |
| [in,out] | p_dst | Points to output matrix structure. |
| err_status_t matf32_arr_add | ( | const matf32_t **const | p_matarray, |
| uint16_t | length, | ||
| matf32_t * | p_dst ) |
Adds an array of matrices sequentially. The size of all matrices must be the same.
| [in] | p_matarray | Points to the matrix array. |
| [in] | length | Number of matrices in the array. |
| [in,out] | p_dst | Points to output matrix structure. |
| err_status_t matf32_arr_mul | ( | const matf32_t **const | p_matarray, |
| uint16_t | length, | ||
| matf32_t * | p_dst ) |
Multiplies an array of matrices sequentially. The number of columns of any matrix must be the same as the number of rows of the next. Output matrix cannot be the same as one of the inputs.
| [in] | p_matarray | Points to the matrix array. |
| [in] | length | Number of matrices in the array. |
| [in,out] | p_dst | Points to output matrix structure. |
| err_status_t matf32_arr_sub | ( | const matf32_t **const | p_matarray, |
| uint16_t | length, | ||
| matf32_t * | p_dst ) |
Subtracts an array of matrices sequentially. The size of all matrices must be the same.
| [in] | p_matarray | Points to the matrix array. |
| [in] | length | Number of matrices in the array. |
| [in,out] | p_dst | Points to output matrix structure. |
| bool matf32_check_hessenberg_lower | ( | const matf32_t *const | p_mat | ) |
Checks if a matrix is lower hessenberg.
| [in] | p_mat | Points to matrix to check. |
| bool matf32_check_hessenberg_upper | ( | const matf32_t *const | p_mat | ) |
Checks if a matrix is upper hessenberg.
| [in] | p_mat | Points to matrix to check. |
| bool matf32_check_symmetric | ( | const matf32_t *const | p_mat | ) |
Checks if a matrix is symmetric.
| [in] | p_mat | Points to matrix to check. |
| bool matf32_check_symposdef | ( | const matf32_t *const | p_mat | ) |
Checks if a matrix is symmetric positive definite.
| [in] | p_mat | Points to matrix to check. |
| bool matf32_check_triangular_lower | ( | const matf32_t *const | p_mat | ) |
Checks if matrix is lower triangular.
| [in] | p_mat | Points to the matrix to test. |
| bool matf32_check_triangular_upper | ( | const matf32_t *const | p_mat | ) |
Checks if matrix is upper triangular.
| [in] | p_mat | Points to the matrix to test. |
| err_status_t matf32_cholesky | ( | const matf32_t *const | p_a, |
| matf32_t *const | p_c ) |
Calculates the Cholesky decomposition of a matrix A = LL', where L is a lowe triangular matrix.
Below is an example of how this factorization looks like:
\[\begin{aligned} \textbf{A}= \textbf{LL}^\top = \begin{bmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{bmatrix} = \begin{bmatrix} m_{11} & 0 & 0\\ m_{21} & m_{22} & 0\\ m_{31} & m_{32} & m_{33} \end{bmatrix} \begin{bmatrix} m_{11} & m_{21} & m_{31}\\ 0 & m_{22} & m_{32}\\ 0 & 0 & m_{33} \end{bmatrix} \end{aligned} \]
| [in] | p_a | Points to matrix to factorize. |
| [in,out] | p_c | Points to lower triangular factorized matrix. |
| void matf32_cond | ( | const matf32_t *const | p_src, |
| float * | p_cond ) |
Calculates condition number of a matrix. This routine is useful for monitoring the behavior of matrices, as a higher condition number may lead to approximation issues or unexpected behavior in some operations.
| [in] | p_src | Points to matrix from which to calculate the condition number. |
| [in] | p_cond | Points to float to store condition number. |
| void matf32_diag | ( | float * | p_src, |
| matf32_t *const | p_dst ) |
Sets a matrix structure to a diagonal matrix, created from a given vector.
| [in] | p_src | Points to vector with the diagonal entries to be used. |
| [in,out] | p_dst | Points to matrix to allocate the diagonal matrix. |
| err_status_t matf32_dot | ( | const matf32_t *const | p_srca, |
| const matf32_t *const | p_srcb, | ||
| float *const | p_dst ) |
Dot product between two vectors (wether row or column).
| [in] | p_srca | Points to first input vector. |
| [in] | p_srcb | Points to second input vector. |
| [in] | p_dst | Points to scalar result. |
| err_status_t matf32_exp | ( | const matf32_t *const | p_src, |
| matf32_t *const | p_dst, | ||
| uint16_t | exp ) |
Calculates the power of a matrix to a given exponent.
| [in] | p_src | Points to the source matrix |
| [in,out] | p_dst | Points to the output matrix |
| [in] | exp | Indicates the exponent to be used |
| void matf32_eye | ( | matf32_t *const | p_dst | ) |
Sets a matrix structure to the identity matrix.
| [in,out] | p_dst | Points to matrix to allocate the identity matrix. |
| void matf32_init | ( | matf32_t *const | instance, |
| uint16_t | num_rows, | ||
| uint16_t | num_cols, | ||
| float * | p_data ) |
Constructor for the floating point matrix data structure.
| [in,out] | instance | Points to an instance of the floating-point matrix structure. |
| [in] | num_rows | Number of rows in the matrix. |
| [in] | num_cols | Number of columns in the matrix. |
| [in] | p_data | Points to the matrix data array. |
| err_status_t matf32_inv | ( | const matf32_t * | p_src, |
| matf32_t * | p_dst ) |
Computes the inverse of a square, non-singular matrix.
NOTE: use only as a last resort, solving the linear system Ax = b should always be the first choice. This routine is also very numerically sensitive, as the matrix are defined with 32-bit floating point data.
| [in] | p_src | Points to input matrix. |
| [in,out] | p_dst | Points to output matrix. |
Checks if two matrices are equal.
| [in] | p_mat_a | Points to first matrix to compare. |
| [in] | p_mat_b | Points to second matrix to compare. |
| bool matf32_is_equal_less_scalar | ( | const matf32_t *const | p_mat, |
| float | scalar ) |
Checks if a matrix values are equal or lesser than a scalar.
| [in] | p_mat | Points to the matrix to compare. |
| [in] | scalar | Value to compare against. |
| bool matf32_is_equal_scalar | ( | const matf32_t *const | p_mat, |
| float | scalar ) |
Checks if a matrix values are equal to a scalar.
| [in] | p_mat | Points to the matrix to compare. |
| [in] | scalar | Value to compare against. |
| err_status_t matf32_jacobi_svd | ( | const matf32_t *const | p_a, |
| matf32_t *const | p_u, | ||
| matf32_t *const | p_s, | ||
| matf32_t *const | p_v ) |
Calculates the SVD of a matrix using using the one-sided Jacobi algorithm.
Below is an example of how this factorization looks like:
\[\begin{aligned} \textbf{A} = \textbf{U}\boldsymbol{\Sigma}\textbf{V}^\top = \begin{bmatrix} u_{11} & u_{12} & u_{13}\\ u_{21} & u_{22} & u_{23}\\ u_{31} & u_{32} & u_{33} \end{bmatrix} \begin{bmatrix} \sigma_{11} & 0 & 0 \\ 0 & \sigma_{22} & 0 \\ 0 & 0 & \sigma_{33} \end{bmatrix} \begin{bmatrix} v_{11} & v_{12} & v_{13}\\ v_{21} & v_{22} & v_{23}\\ v_{31} & v_{32} & v_{33} \end{bmatrix} \end{aligned} \]
| [in] | p_a | Points to input matrix (square matrix) |
| [in,out] | p_u | Points to matrix to save the orthogonal matrix U |
| [in,out] | p_s | Points to matrix to save the singular values matrix S |
| [in,out] | p_v | Points to matrix to save the orthogonal matrix V |
| err_status_t matf32_lu | ( | const matf32_t * | p_a, |
| matf32_t *const | p_l, | ||
| matf32_t *const | p_u, | ||
| uint16_t * | p_index ) |
Computes the LU decomposition of a square matrix A, pointed by p_a, such that PA = LU, and saves the L and U factors in different matrices, and the list of permutations corresponding to the matrix P are saved in an array to save memory.
Below is an example of how this factorization looks like:
\[\begin{aligned} \textbf{A}= \textbf{LU} = \begin{bmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0\\ m_{21} & 1 & 0\\ m_{31} & m_{32} & 1 \end{bmatrix} \begin{bmatrix} u_{11} & u_{12} & u_{13}\\ 0 & u_{22} & u_{23}\\ 0 & 0 & u_{33} \end{bmatrix} \end{aligned} \]
| [in] | p_a | Points to square matrix to decompose. |
| [in,out] | p_l | Points to the lower result of the decomposition. |
| [in,out] | p_u | Points to the upper of the decomposition. |
| [in,out] | p_index | Saved indexes for permutation |
| err_status_t matf32_lup | ( | const matf32_t * | p_src, |
| matf32_t * | p_lu, | ||
| uint16_t * | pivot ) |
Computes the LU decomposition (with partial pivoting) of a square matrix A, pointed by p_src, such that PA = LU.
| [in] | p_src | Points to square matrix to decompose. |
| [in,out] | p_lu | Points to the result of the decomposition. |
| [in,out] | pivot | Points to the pivot vector. |
| err_status_t matf32_mul | ( | const matf32_t * | p_srca, |
| const matf32_t * | p_srcb, | ||
| matf32_t * | p_dst ) |
Multiplies two matrices. The number of columns of the first matrix must be the same as the number of rows of the second matrix.
| [in] | p_srca | Points to first input matrix structure. |
| [in] | p_srcb | Points to second input matrix structure. |
| [in,out] | p_dst | Points to output matrix structure. |
| err_status_t matf32_one_sided_jacobi | ( | const matf32_t *const | p_a, |
| matf32_t *const | p_v, | ||
| uint16_t | j, | ||
| uint16_t | k ) |
Generates and applies a one-sided jacobi rotation to matrix A and saves the result as A = AV and V (an orthonormal matrix to accumulate the rotations applied).
| [in] | p_a | Points to input matrix (square matrix) |
| [in,out] | p_v | Points to matrix to save the orthonormal matrix V |
| [in] | j | Index j for the rotation |
| [in] | k | Index k for the rotation |
| void matf32_ones | ( | matf32_t *const | p_dst | ) |
Sets a matrix structure to a ones matrix.
| [in,out] | p_dst | Points to matrix to allocate the ones matrix. |
| err_status_t matf32_pinv | ( | const matf32_t *const | p_a, |
| matf32_t *const | p_dst, | ||
| pseudoinverse_methods_t | method ) |
Calculates the pseudoinverse of a given matrix using the singular values of the SVD decomposition of A.
| [in] | p_a | Points to input matrix to work with |
| [in,out] | p_dst | Points to output matrix in which to save the pseudoinverse |
| [in] | method | Enum constant to choose method to calculate the pseudoinverse |
| void matf32_print | ( | const matf32_t * | p_src | ) |
Prints matrix data to console (formatted to print as a matrix).
| [in] | p_src | Points to matrix to be printed. |
| err_status_t matf32_qr | ( | const matf32_t *const | p_a, |
| matf32_t *const | p_q, | ||
| matf32_t *const | p_r ) |
Computes the Householder QR factorization of a matrix A, saving the Q and R factors in different matrices.
Below is an example of how this factorization looks like:
\[\begin{aligned} \textbf{A}= \textbf{QR} = \begin{bmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{bmatrix} = \begin{bmatrix} q_{11} & q_{12} & q_{13}\\ q_{21} & q_{22} & q_{23}\\ q_{31} & q_{32} & q_{33} \end{bmatrix} \begin{bmatrix} r_{11} & r_{21} & r_{31}\\ 0 & r_{22} & r_{32}\\ 0 & 0 & r_{33} \end{bmatrix} \end{aligned} \]
| [in] | p_a | Points to the matrix to be factorized/decomposed into a QR factorization. |
| [in,out] | p_q | Points to a matrix where the Q factor will be saved. |
| [in,out] | p_r | Points to a matrix where the R factor will be saved. |
| void matf32_randn | ( | matf32_t *const | p_dst, |
| float | mu, | ||
| float | sigma ) |
Sets a matrix structure to a matrix with random entries, sampled from a normal distribution.
| [in,out] | p_dst | Points to random matrix. |
| [in] | mu | Mean. |
| [in] | sigma | Standard deviation. |
| err_status_t matf32_scale | ( | const matf32_t * | p_src, |
| float | scalar, | ||
| matf32_t * | p_dst ) |
Multiplies a matrix by a scalar, element-wise, and saves the result in another matrix. The result can be saved either in a new matf32_t matrix or in one of the input matrices (overwriting its previous contents).
| [in] | p_src | Points to input matrix. |
| [in] | scalar | Scaling factor. |
| [in,out] | p_dst | Points to output matrix. |
| void matf32_set_col | ( | matf32_t *const | p_dst, |
| uint16_t | col, | ||
| float | val ) |
Sets all elements in a matrix column to a specified value.
| [in,out] | p_dst | Points to matrix to edit. |
| [in] | col | Number of column to set as a value. |
| [in] | val | Value to set the row to. |
| void matf32_set_row | ( | matf32_t *const | p_dst, |
| uint16_t | row, | ||
| float | val ) |
Sets all elements in a matrix row to a specified value.
| [in,out] | p_dst | Points to matrix to edit. |
| [in] | row | Number of row to set as a value. |
| [in] | val | Value to set the row to. |
| err_status_t matf32_sub | ( | const matf32_t * | p_srca, |
| const matf32_t * | p_srcb, | ||
| matf32_t * | p_dst ) |
Substracts two matrices and saves the result in another matrix. The result can be saved either in a new matf32_t matrix or in one of the input matrices (overwriting its previous contents). Both need to be of the same dimension.
| [in] | p_srca | Points to first input matrix structure. |
| [in] | p_srcb | Points to second input matrix structure. |
| [in,out] | p_dst | Points to output matrix structure. |
| err_status_t matf32_submatrix_copy | ( | const matf32_t *const | p_src, |
| matf32_t *const | p_dst, | ||
| const uint16_t | src_row, | ||
| const uint16_t | src_col, | ||
| const uint16_t | dst_row, | ||
| const uint16_t | dst_col, | ||
| const uint16_t | rows, | ||
| const uint16_t | cols ) |
Copies a specified number of rows and columns from a matrix into another matrix. That means, it can either copy an entire matrix to another one, or just a submatrix of the former.
| [in] | p_src | Points to the origin matrix from which to copy data. |
| [in,out] | p_dst | Points to the destination matrix on which to store the copied data. |
| [in] | src_row | Origin row from which to start copying data from the origin matrix (zero-indexed). |
| [in] | src_col | Origin column from which to start copying data from the origin matrix (zero-indexed). |
| [in] | dst_row | Row in which to start saving the copied data in the destination matrix (zero-indexed). |
| [in] | dst_col | Column in which to start saving the copied data in the destination matrix (zero-indexed). |
| [in] | rows | Number of rows to copy in total (starting to count from the origin row and until reaching this rows value). |
| [in] | cols | Number of columns to copy in total (starting to count from the origin column and until reaching this cols value). |
| err_status_t matf32_trans | ( | const matf32_t * | p_src, |
| matf32_t * | p_dst ) |
Transposes a matrix and saves the result in another matrix.
| [in] | p_src | Points to input matrix. |
| [in,out] | p_dst | Points to output matrix. |
| void matf32_vecmul_col_row | ( | const float *const | col_vec, |
| const float *const | row_vec, | ||
| matf32_t *const | p_dst ) |
Vector-Vector Multiplication (the result is a matrix).
| [in] | col_vec | Points to a float array representing the column vector |
| [in] | row_vec | Points to a float array representing the row vector |
| [in,out] | p_dst | Points to matrix in which to save the result |
| void matf32_vecposmul | ( | const matf32_t * | p_srcm, |
| float * | p_srcv, | ||
| float * | p_dst ) |
Matrix-vector post multiplication, i.e. Ax. Assumes a column vector.
| [in] | p_srcm | Points to input matrix. |
| [in] | p_srcv | Points to input vector. |
| [in,out] | p_dst | Points to result vector. |
| void matf32_vecpremul | ( | const matf32_t * | p_srcm, |
| float * | p_srcv, | ||
| float * | p_dst ) |
vector-Matrix pre multiplication, i.e. xA. Assumes a row vector.
| [in] | p_srcm | Points to input matrix. |
| [in] | p_srcv | Points to input vector. |
| [in,out] | p_dst | Points to result vector. |
| void matf32_zeros | ( | matf32_t *const | p_dst | ) |
Sets a matrix structure to the zero matrix.
| [in,out] | p_dst | Points to matrix to allocate the zero matrix. |
| float mean | ( | float * | p_src, |
| uint16_t | length ) |
Gets the mean of a given array.
| [in] | p_src | Points to input array. |
| [in] | length | Array length. |
| float norm | ( | float * | p_src, |
| int | row, | ||
| int | column ) |
Calculates the norm of a given matrix (euclidean for vectors, frobenius for matrices). Assign to a float variable to store the result of the norm.
| [in,out] | p_src | Points to matrix array. |
| [in] | row | Number or rows. |
| [in] | column | Number of columns. |
| void ones | ( | float * | p_dst, |
| int | row, | ||
| int | column ) |
Turn into 1 all the elements of the matrix array pointed by p_dst (size row x column).
| [in,out] | p_dst | Points to ones matrix array. |
| [in] | row | Number or rows. |
| [in] | column | Number of columns. |
| void print | ( | float * | p_src, |
| uint16_t | row, | ||
| uint16_t | column ) |
Prints an array to the console (formatted).
| [in] | p_src | Points to array to be printed. |
| [in] | row | Number of rows. |
| [in] | column | Number of columns. |
| void randn | ( | float * | p_dst, |
| uint16_t | length, | ||
| float | mu, | ||
| float | sigma ) |
Creates a random array with values sampled from a normal (Gaussian) distribution.
| [in,out] | p_dst | Points to random vector to create. |
| [in] | length | Vector length. |
| [in] | mu | Mean. |
| [in] | sigma | Standard deviation. |
| float saturation | ( | float | input, |
| float | lower_limit, | ||
| float | upper_limit ) |
Saturates the input, given upper and lower limits.
| [in] | input | Input value. |
| [in] | lower_limit | Lower saturation threshold. |
| [in] | upper_limit | Upper saturation threshold. |
| void scale | ( | float * | p_src, |
| uint16_t | length, | ||
| float | scalar, | ||
| float * | p_dst ) |
Multiplies a vector by a scalar, stores the result in a vector (can be the same as the input vector or a different vector).
| [in] | p_src | Vector to scale. |
| [in] | length | Vector size. |
| [in] | scalar | Factor to scale the vector. |
| [out] | p_dst | Scaled vector (output vector). |
| float sign | ( | float | number | ) |
Gets the input's sign by checking if the number is greater, equal to, or less than 0.
| [in] | number | Input value. |
| float std_dev | ( | float * | p_src, |
| uint16_t | length ) |
Gets the standard deviation of a given array. Named this way instead of "std" to avoid conflict with std namesapce in c++.
| [in] | p_src | Points to input array. |
| [in] | length | Array length. |
| void zero_patch | ( | float * | p_a, |
| uint16_t | length ) |
Changes NaN and Inf values to zero. Needed to avoid errors in cases where irrelevant elements end set as NaN or Inf.
| [in] | p_a | Points to array. |
| [in] | length | Array length. |
| void zeros | ( | float * | p_dst, |
| int | row, | ||
| int | column ) |
Turn into 0 all the elements of the matrix array pointed by p_dst (size row x column).
| [in,out] | p_dst | Points to zero matrix array. |
| [in] | row | Number or rows. |
| [in] | column | Number of columns. |