Zephyr Scientific Library (zscilib)
|
API header file for matrices in zscilib. More...
Go to the source code of this file.
Data Structures | |
struct | zsl_mtx |
Represents a m x n matrix, with data stored in row-major order. More... | |
Macros | |
#define | EEIGENSIZE (100) |
#define | ECOMPLEXVAL (101) |
#define | ZSL_MATRIX_DEF(name, m, n) |
Typedefs | |
typedef enum zsl_mtx_unary_op | zsl_mtx_unary_op_t |
Component-wise unary operations. More... | |
typedef enum zsl_mtx_binary_op | zsl_mtx_binary_op_t |
Component-wise binary operations. More... | |
typedef int(* | zsl_mtx_unary_fn_t) (struct zsl_mtx *m, size_t i, size_t j) |
Function prototype called when applying a set of component-wise unary operations to a matrix via zsl_mtx_unary_func . More... | |
typedef int(* | zsl_mtx_binary_fn_t) (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc, size_t i, size_t j) |
Function prototype called when applying a set of component-wise binary operations using a pair of symmetrical matrices via zsl_mtx_binary_func . More... | |
typedef int(* | zsl_mtx_init_entry_fn_t) (struct zsl_mtx *m, size_t i, size_t j) |
Function prototype called when populating a matrix via zsl_mtx_init . More... | |
Functions | |
int | zsl_mtx_entry_fn_empty (struct zsl_mtx *m, size_t i, size_t j) |
Assigns a zero-value to all entries in the matrix. More... | |
int | zsl_mtx_entry_fn_identity (struct zsl_mtx *m, size_t i, size_t j) |
Sets the value to '1.0' if the entry is on the diagonal (row=col), otherwise '0.0'. More... | |
int | zsl_mtx_entry_fn_random (struct zsl_mtx *m, size_t i, size_t j) |
Sets the value to a random number between -1.0 and 1.0. More... | |
int | zsl_mtx_init (struct zsl_mtx *m, zsl_mtx_init_entry_fn_t entry_fn) |
Initialises matrix 'm' using the specified entry function to assign values. More... | |
int | zsl_mtx_from_arr (struct zsl_mtx *m, zsl_real_t *a) |
Converts an array of values into a matrix. More... | |
int | zsl_mtx_copy (struct zsl_mtx *mdest, struct zsl_mtx *msrc) |
Copies the contents of matrix 'msrc' into matrix 'mdest'. More... | |
int | zsl_mtx_get (struct zsl_mtx *m, size_t i, size_t j, zsl_real_t *x) |
Gets a single value from the specified row (i) and column (j). More... | |
int | zsl_mtx_set (struct zsl_mtx *m, size_t i, size_t j, zsl_real_t x) |
Sets a single value at the specified row (i) and column (j). More... | |
int | zsl_mtx_get_row (struct zsl_mtx *m, size_t i, zsl_real_t *v) |
Gets the contents of row 'i' from matrix 'm', assigning the array of data to 'v'. More... | |
int | zsl_mtx_set_row (struct zsl_mtx *m, size_t i, zsl_real_t *v) |
Sets the contents of row 'i' in matrix 'm', assigning the values found in array 'v'. More... | |
int | zsl_mtx_get_col (struct zsl_mtx *m, size_t j, zsl_real_t *v) |
Gets the contents of column 'j' from matrix 'm', assigning the array of data to 'v'. More... | |
int | zsl_mtx_set_col (struct zsl_mtx *m, size_t j, zsl_real_t *v) |
Sets the contents of column 'j' in matrix 'm', assigning the values found in array 'v'. More... | |
int | zsl_mtx_add (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc) |
Adds matrices 'ma' and 'mb', assigning the output to 'mc'. Matrices 'ma', 'mb' and 'mc' must all be identically shaped. More... | |
int | zsl_mtx_add_d (struct zsl_mtx *ma, struct zsl_mtx *mb) |
Adds matrices 'ma' and 'mb', assigning the output to 'ma'. Matrices 'ma', and 'mb' must be identically shaped. More... | |
int | zsl_mtx_sum_rows_d (struct zsl_mtx *m, size_t i, size_t j) |
Adds the values of row 'j' to row 'i' in matrix 'm'. This operation is destructive for row 'i'. More... | |
int | zsl_mtx_sum_rows_scaled_d (struct zsl_mtx *m, size_t i, size_t j, zsl_real_t s) |
This function takes the coefficients of row 'j' and multiplies them by scalar 's', then adds the resulting coefficient to the parallel element in row 'i'. Row 'i' will be modified in this operation. More... | |
int | zsl_mtx_sub (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc) |
Subtracts matrices 'mb' from 'ma', assigning the output to 'mc'. Matrices 'ma', 'mb' and 'mc' must all be identically shaped. More... | |
int | zsl_mtx_sub_d (struct zsl_mtx *ma, struct zsl_mtx *mb) |
Subtracts matrix 'mb' from 'ma', assigning the output to 'ma'. Matrices 'ma', and 'mb' must be identically shaped. More... | |
int | zsl_mtx_mult (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc) |
Multiplies matrix 'ma' by 'mb', assigning the output to 'mc'. Matrices 'ma' and 'mb' must be compatibly shaped, meaning that 'ma' must have the same numbers of columns as there are rows in 'mb'. More... | |
int | zsl_mtx_mult_d (struct zsl_mtx *ma, struct zsl_mtx *mb) |
Multiplies matrix 'ma' by 'mb', assigning the output to 'ma'. Matrices 'ma' and 'mb' must be compatibly shaped, meaning that 'ma' must have the same numbers of columns as there are rows in 'mb'. To use this function, 'mb' must be a square matrix. This function is destructive. More... | |
int | zsl_mtx_scalar_mult_d (struct zsl_mtx *m, zsl_real_t s) |
Multiplies all elements in matrix 'm' by scalar value 's'. More... | |
int | zsl_mtx_scalar_mult_row_d (struct zsl_mtx *m, size_t i, zsl_real_t s) |
Multiplies the elements of row 'i' in matrix 'm' by scalar 's'. More... | |
int | zsl_mtx_trans (struct zsl_mtx *ma, struct zsl_mtx *mb) |
Transposes the matrix 'ma' into matrix 'mb'. Note that output matrix 'mb' must have 'ma->sz_rows' columns, and 'ma->sz_cols' rows. More... | |
int | zsl_mtx_adjoint_3x3 (struct zsl_mtx *m, struct zsl_mtx *ma) |
Calculates the ajoint matrix, based on the input 3x3 matrix 'm'. More... | |
int | zsl_mtx_adjoint (struct zsl_mtx *m, struct zsl_mtx *ma) |
Calculates the ajoint matrix, based on the input square matrix 'm'. More... | |
int | zsl_mtx_vec_wedge (struct zsl_mtx *m, struct zsl_vec *v) |
Calculates the wedge product of n-1 vectors of size n, which are the rows of the matrix 'm'. This n-1 vectors must be linearly independent. More... | |
int | zsl_mtx_reduce (struct zsl_mtx *m, struct zsl_mtx *mr, size_t i, size_t j) |
Removes row 'i' and column 'j' from square matrix 'm', assigning the remaining elements in the matrix to 'mr'. More... | |
int | zsl_mtx_reduce_iter (struct zsl_mtx *m, struct zsl_mtx *mred) |
Reduces the number of rows/columns in the input square matrix 'm' to match the shape of 'mred', where mred < m. Rows/cols will be removed starting on the left and upper vectors. More... | |
int | zsl_mtx_augm_diag (struct zsl_mtx *m, struct zsl_mtx *maug) |
Augments the input square matrix with additional rows and columns, based on the size 'diff' between m and maug (where maug > m). New rows and columns are assigned values based on an identity matrix, meaning 1.0 on the new diagonal values and 0.0 above and below the diagonal. More... | |
int | zsl_mtx_deter_3x3 (struct zsl_mtx *m, zsl_real_t *d) |
Calculates the determinant of the input 3x3 matrix 'm'. More... | |
int | zsl_mtx_deter (struct zsl_mtx *m, zsl_real_t *d) |
Calculates the determinant of the input square matrix 'm'. More... | |
int | zsl_mtx_gauss_elim (struct zsl_mtx *m, struct zsl_mtx *mg, struct zsl_mtx *mi, size_t i, size_t j) |
Given the element (i,j) in matrix 'm', this function performs gaussian elimination by adding row 'i' to the other rows until all of the elements in column 'j' are equal to 0.0, aside from the element at position (i, j). The result of this process will be assigned to matrix 'mg'. More... | |
int | zsl_mtx_gauss_elim_d (struct zsl_mtx *m, struct zsl_mtx *mi, size_t i, size_t j) |
Given the element (i,j) in matrix 'm', this function performs gaussian elimination by adding row 'i' to the other rows until all of the elements in column 'j' are equal to 0.0, aside from the element at position (i, j). This function is destructive and will modify the contents of m. More... | |
int | zsl_mtx_gauss_reduc (struct zsl_mtx *m, struct zsl_mtx *mi, struct zsl_mtx *mg) |
Given matrix 'm', puts the matrix into echelon form using Gauss-Jordan reduction. More... | |
int | zsl_mtx_cols_norm (struct zsl_mtx *m, struct zsl_mtx *mnorm) |
Updates the values of every column vector in input matrix 'm' to have unitary values. More... | |
int | zsl_mtx_gram_schmidt (struct zsl_mtx *m, struct zsl_mtx *mort) |
Performs the Gram-Schmidt algorithm on the set of column vectors in matrix 'm'. This algorithm calculates a set of orthogonal vectors in the same vectorial space as the original vectors. More... | |
int | zsl_mtx_norm_elem (struct zsl_mtx *m, struct zsl_mtx *mn, struct zsl_mtx *mi, size_t i, size_t j) |
Normalises elements in matrix m such that the element at position (i, j) is equal to 1.0. More... | |
int | zsl_mtx_norm_elem_d (struct zsl_mtx *m, struct zsl_mtx *mi, size_t i, size_t j) |
Normalises elements in matrix m such that the element at position (i, j) is equal to 1.0. This function is destructive and will modify the contents of m. More... | |
int | zsl_mtx_inv_3x3 (struct zsl_mtx *m, struct zsl_mtx *mi) |
Calculates the inverse of 3x3 matrix 'm'. If the determinant of 'm' is zero, an identity matrix will be returned via 'mi'. More... | |
int | zsl_mtx_inv (struct zsl_mtx *m, struct zsl_mtx *mi) |
Calculates the inverse of square matrix 'm'. More... | |
int | zsl_mtx_cholesky (struct zsl_mtx *m, struct zsl_mtx *l) |
Calculates the Cholesky decomposition of a symmetric square matrix using the Cholesky–Crout algorithm. More... | |
int | zsl_mtx_balance (struct zsl_mtx *m, struct zsl_mtx *mout) |
Balances the square matrix 'm', a process in which the eigenvalues of the output matrix are the same as the eigenvalues of the input matrix. More... | |
int | zsl_mtx_householder (struct zsl_mtx *m, struct zsl_mtx *h, bool hessenberg) |
Calculates the householder reflection of 'm'. Used as part of QR decomposition. When 'hessenberg' is active, it calculates the householder reflection but without using the first line of 'm'. More... | |
int | zsl_mtx_qrd (struct zsl_mtx *m, struct zsl_mtx *q, struct zsl_mtx *r, bool hessenberg) |
If 'hessenberg' is set to false, this function performs the QR decomposition, which is a factorisation of matrix 'm' into an orthogonal matrix (q) and an upper triangular matrix (r). If 'hessenberg' is set to true, this function puts the matrix 'm' into hessenberg form. This function uses the householder reflections. More... | |
int | zsl_mtx_qrd_iter (struct zsl_mtx *m, struct zsl_mtx *mout, size_t iter) |
Computes recursively the QR decompisition method to put the input square matrix into upper triangular form. More... | |
int | zsl_mtx_eigenvalues (struct zsl_mtx *m, struct zsl_vec *v, size_t iter) |
Calculates the eigenvalues for input matrix 'm' using QR decomposition recursively. The output vector will only contain real eigenvalues, even if the input matrix has complex eigenvalues. More... | |
int | zsl_mtx_eigenvectors (struct zsl_mtx *m, struct zsl_mtx *mev, size_t iter, bool orthonormal) |
Calcualtes the set of eigenvectors for input matrix 'm', using the specified number of iterations to find a balance between precision and processing effort. Optionally, the output eigenvectors can be orthonormalised. More... | |
int | zsl_mtx_svd (struct zsl_mtx *m, struct zsl_mtx *u, struct zsl_mtx *e, struct zsl_mtx *v, size_t iter) |
Performs singular value decomposition, converting input matrix 'm' into matrices 'u', 'e', and 'v'. More... | |
int | zsl_mtx_pinv (struct zsl_mtx *m, struct zsl_mtx *pinv, size_t iter) |
Performs the pseudo-inverse (aka pinv or Moore-Penrose inverse) on input matrix 'm'. More... | |
int | zsl_mtx_min (struct zsl_mtx *m, zsl_real_t *x) |
Traverses the matrix elements to find the minimum element value. More... | |
int | zsl_mtx_max (struct zsl_mtx *m, zsl_real_t *x) |
Traverses the matrix elements to find the maximum element value. More... | |
int | zsl_mtx_min_idx (struct zsl_mtx *m, size_t *i, size_t *j) |
Traverses the matrix elements to find the (i,j) index of the minimum element value. If multiple identical minimum values are founds, the (i, j) index values returned will refer to the first element. More... | |
int | zsl_mtx_max_idx (struct zsl_mtx *m, size_t *i, size_t *j) |
Traverses the matrix elements to find the (i,j) index of the maximum element value. If multiple identical maximum values are founds, the (i, j) index values returned will refer to the first element. More... | |
bool | zsl_mtx_is_equal (struct zsl_mtx *ma, struct zsl_mtx *mb) |
Checks if two matrices are identical in shape and content. More... | |
bool | zsl_mtx_is_notneg (struct zsl_mtx *m) |
Checks if all elements in matrix m are >= zero. More... | |
bool | zsl_mtx_is_sym (struct zsl_mtx *m) |
Checks if the square input matrix is symmetric. More... | |
int | zsl_mtx_print (struct zsl_mtx *m) |
Printf the supplied matrix using printf in a human-readable manner. More... | |
int | zsl_mtx_unary_op (struct zsl_mtx *m, zsl_mtx_unary_op_t op) |
Applies a unary operand on every coefficient in matrix 'm'. More... | |
int | zsl_mtx_unary_func (struct zsl_mtx *m, zsl_mtx_unary_fn_t fn) |
Applies a unary function on every coefficient in matrix 'm', using the specified 'zsl_mtx_apply_unary_fn_t' instance. More... | |
int | zsl_mtx_binary_op (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc, zsl_mtx_binary_op_t op) |
Applies a component-wise binary operation on every coefficient in symmetrical matrices 'ma' and 'mb', with the results being stored in the identically shaped mc matrix. More... | |
int | zsl_mtx_binary_func (struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc, zsl_mtx_binary_fn_t fn) |
Applies a component-wise binary operztion on every coefficient in symmetrical matrices 'ma' and 'mb', with the results being stored in the identically shaped 'mc' matrix. The actual binary operation is executed using the specified 'zsl_mtx_binary_fn_t' callback. More... | |
API header file for matrices in zscilib.
This file contains the zscilib matrix APIs
Definition in file matrices.h.