Zephyr Scientific Library (zscilib)
matrices.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 Kevin Townsend (KTOWN)
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
22 #ifndef ZEPHYR_INCLUDE_ZSL_MATRICES_H_
23 #define ZEPHYR_INCLUDE_ZSL_MATRICES_H_
24 
25 #include <zsl/zsl.h>
26 #include <zsl/vectors.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
41 #define EEIGENSIZE (100)
42 
43 #define ECOMPLEXVAL (101)
44 
46 struct zsl_mtx {
48  size_t sz_rows;
50  size_t sz_cols;
53 };
54 
61 #define ZSL_MATRIX_DEF(name, m, n); \
62  zsl_real_t name ## _mtx[m * n]; \
63  struct zsl_mtx name = { \
64  .sz_rows = m, \
65  .sz_cols = n, \
66  .data = name ## _mtx \
67  }
68  /* End of MTX_STRUCTS group */
70 
81 typedef enum zsl_mtx_unary_op {
103 
105 typedef enum zsl_mtx_binary_op {
121  /* End of MTX_OPERANDS group */
123 
142 typedef int (*zsl_mtx_unary_fn_t)(struct zsl_mtx *m, size_t i, size_t j);
143 
156 typedef int (*zsl_mtx_binary_fn_t)(struct zsl_mtx *ma, struct zsl_mtx *mb,
157  struct zsl_mtx *mc, size_t i, size_t j);
158 
168 typedef int (*zsl_mtx_init_entry_fn_t)(struct zsl_mtx *m, size_t i, size_t j);
169 
179 int zsl_mtx_entry_fn_empty(struct zsl_mtx *m, size_t i, size_t j);
180 
191 int zsl_mtx_entry_fn_identity(struct zsl_mtx *m, size_t i, size_t j);
192 
202 int zsl_mtx_entry_fn_random(struct zsl_mtx *m, size_t i, size_t j);
203 
214 int zsl_mtx_init(struct zsl_mtx *m, zsl_mtx_init_entry_fn_t entry_fn);
215 
234 int zsl_mtx_from_arr(struct zsl_mtx *m, zsl_real_t *a);
235 
244 int zsl_mtx_copy(struct zsl_mtx *mdest, struct zsl_mtx *msrc);
245  /* End of MTX_INIT group */
247 
268 int zsl_mtx_get(struct zsl_mtx *m, size_t i, size_t j, zsl_real_t *x);
269 
281 int zsl_mtx_set(struct zsl_mtx *m, size_t i, size_t j, zsl_real_t x);
282 
295 int zsl_mtx_get_row(struct zsl_mtx *m, size_t i, zsl_real_t *v);
296 
309 int zsl_mtx_set_row(struct zsl_mtx *m, size_t i, zsl_real_t *v);
310 
323 int zsl_mtx_get_col(struct zsl_mtx *m, size_t j, zsl_real_t *v);
324 
337 int zsl_mtx_set_col(struct zsl_mtx *m, size_t j, zsl_real_t *v);
338  /* End of MTX_DATAACCESS group */
340 
353 int zsl_mtx_unary_op(struct zsl_mtx *m, zsl_mtx_unary_op_t op);
354 
365 
378 int zsl_mtx_binary_op(struct zsl_mtx *ma, struct zsl_mtx *mb,
379  struct zsl_mtx *mc, zsl_mtx_binary_op_t op);
380 
394 int zsl_mtx_binary_func(struct zsl_mtx *ma, struct zsl_mtx *mb,
395  struct zsl_mtx *mc, zsl_mtx_binary_fn_t fn);
396  /* End of MTX_OPERANDS group */
398 
418 int zsl_mtx_add(struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc);
419 
433 int zsl_mtx_add_d(struct zsl_mtx *ma, struct zsl_mtx *mb);
434 
446 int zsl_mtx_sum_rows_d(struct zsl_mtx *m, size_t i, size_t j);
447 
464 int zsl_mtx_sum_rows_scaled_d(struct zsl_mtx *m, size_t i, size_t j,
465  zsl_real_t s);
466 
478 int zsl_mtx_sub(struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc);
479 
493 int zsl_mtx_sub_d(struct zsl_mtx *ma, struct zsl_mtx *mb);
494 
508 int zsl_mtx_mult(struct zsl_mtx *ma, struct zsl_mtx *mb, struct zsl_mtx *mc);
509 
523 int zsl_mtx_mult_d(struct zsl_mtx *ma, struct zsl_mtx *mb);
524 
534 int zsl_mtx_scalar_mult_d(struct zsl_mtx *m, zsl_real_t s);
535 
546 int zsl_mtx_scalar_mult_row_d(struct zsl_mtx *m, size_t i, zsl_real_t s);
547  /* End of MTX_BASICMATH group */
549 
569 int zsl_mtx_trans(struct zsl_mtx *ma, struct zsl_mtx *mb);
570 
581 int zsl_mtx_adjoint_3x3(struct zsl_mtx *m, struct zsl_mtx *ma);
582 
592 int zsl_mtx_adjoint(struct zsl_mtx *m, struct zsl_mtx *ma);
593 
594 #ifndef CONFIG_ZSL_SINGLE_PRECISION
595 
611 int zsl_mtx_vec_wedge(struct zsl_mtx *m, struct zsl_vec *v);
612 #endif
613 
626 int zsl_mtx_reduce(struct zsl_mtx *m, struct zsl_mtx *mr, size_t i, size_t j);
627 
628 /* NOTE: This is used for household method/QR. Should it be in the main lib? */
640 int zsl_mtx_reduce_iter(struct zsl_mtx *m, struct zsl_mtx *mred);
641 
642 /* NOTE: This is used for household method/QR. Should it be in the main lib? */
655 int zsl_mtx_augm_diag(struct zsl_mtx *m, struct zsl_mtx *maug);
656 
665 int zsl_mtx_deter_3x3(struct zsl_mtx *m, zsl_real_t *d);
666 
676 int zsl_mtx_deter(struct zsl_mtx *m, zsl_real_t *d);
677 
693 int zsl_mtx_gauss_elim(struct zsl_mtx *m, struct zsl_mtx *mg,
694  struct zsl_mtx *mi, size_t i, size_t j);
695 
710 int zsl_mtx_gauss_elim_d(struct zsl_mtx *m, struct zsl_mtx *mi,
711  size_t i, size_t j);
712 
723 int zsl_mtx_gauss_reduc(struct zsl_mtx *m, struct zsl_mtx *mi,
724  struct zsl_mtx *mg);
725 
737 int zsl_mtx_cols_norm(struct zsl_mtx *m, struct zsl_mtx *mnorm);
738 
751 int zsl_mtx_gram_schmidt(struct zsl_mtx *m, struct zsl_mtx *mort);
752 
765 int zsl_mtx_norm_elem(struct zsl_mtx *m, struct zsl_mtx *mn, struct zsl_mtx *mi,
766  size_t i, size_t j);
767 
780 int zsl_mtx_norm_elem_d(struct zsl_mtx *m, struct zsl_mtx *mi,
781  size_t i, size_t j);
782 
793 int zsl_mtx_inv_3x3(struct zsl_mtx *m, struct zsl_mtx *mi);
794 
804 int zsl_mtx_inv(struct zsl_mtx *m, struct zsl_mtx *mi);
805 
819 int zsl_mtx_cholesky(struct zsl_mtx *m, struct zsl_mtx *l);
820 
831 int zsl_mtx_balance(struct zsl_mtx *m, struct zsl_mtx *mout);
832 
846 int zsl_mtx_householder(struct zsl_mtx *m, struct zsl_mtx *h, bool hessenberg);
847 
870 int zsl_mtx_qrd(struct zsl_mtx *m, struct zsl_mtx *q, struct zsl_mtx *r,
871  bool hessenberg);
872 
873 #ifndef CONFIG_ZSL_SINGLE_PRECISION
874 
887 int zsl_mtx_qrd_iter(struct zsl_mtx *m, struct zsl_mtx *mout, size_t iter);
888 #endif
889 
890 #ifndef CONFIG_ZSL_SINGLE_PRECISION
891 
910 int zsl_mtx_eigenvalues(struct zsl_mtx *m, struct zsl_vec *v, size_t iter);
911 #endif
912 
913 #ifndef CONFIG_ZSL_SINGLE_PRECISION
914 
936 int zsl_mtx_eigenvectors(struct zsl_mtx *m, struct zsl_mtx *mev, size_t iter,
937  bool orthonormal);
938 #endif
939 
940 #ifndef CONFIG_ZSL_SINGLE_PRECISION
941 
955 int zsl_mtx_svd(struct zsl_mtx *m, struct zsl_mtx *u, struct zsl_mtx *e,
956  struct zsl_mtx *v, size_t iter);
957 #endif
958 
959 #ifndef CONFIG_ZSL_SINGLE_PRECISION
960 
972 int zsl_mtx_pinv(struct zsl_mtx *m, struct zsl_mtx *pinv, size_t iter);
973 #endif
974  /* End of MTX_TRANSFORMATIONS group */
976 
994 int zsl_mtx_min(struct zsl_mtx *m, zsl_real_t *x);
995 
1005 int zsl_mtx_max(struct zsl_mtx *m, zsl_real_t *x);
1006 
1021 int zsl_mtx_min_idx(struct zsl_mtx *m, size_t *i, size_t *j);
1022 
1037 int zsl_mtx_max_idx(struct zsl_mtx *m, size_t *i, size_t *j);
1038  /* End of MTX_LIMITS group */
1040 
1058 bool zsl_mtx_is_equal(struct zsl_mtx *ma, struct zsl_mtx *mb);
1059 
1068 bool zsl_mtx_is_notneg(struct zsl_mtx *m);
1069 
1077 bool zsl_mtx_is_sym(struct zsl_mtx *m);
1078  /* End of MTX_COMPARISON group */
1080 
1097 int zsl_mtx_print(struct zsl_mtx *m);
1098 
1099 // int zsl_mtx_fprint(FILE *stream, zsl_mtx *m);
1100  /* End of MTX_DISPLAY group */
1102 
1103 #ifdef __cplusplus
1104 }
1105 #endif
1106 
1107 #endif /* ZEPHYR_INCLUDE_ZSL_MATRICES_H_ */
1108  /* End of matrices group */
zsl_mtx_augm_diag
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...
Definition: matrices.c:696
zsl_mtx_mult_d
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 compatib...
Definition: matrices.c:468
zsl_mtx_svd
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',...
Definition: matrices.c:1652
zsl_mtx_sum_rows_scaled_d
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',...
Definition: matrices.c:403
zsl_mtx_scalar_mult_row_d
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'.
Definition: matrices.c:498
zsl_mtx_set
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).
Definition: matrices.c:113
zsl_mtx_get_row
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'.
Definition: matrices.c:127
ZSL_MTX_UNARY_OP_SINH
@ ZSL_MTX_UNARY_OP_SINH
Definition: matrices.h:99
zsl_mtx_norm_elem_d
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....
Definition: matrices.c:1003
zsl_mtx_cholesky
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...
Definition: matrices.c:1116
ZSL_MTX_UNARY_OP_FLOOR
@ ZSL_MTX_UNARY_OP_FLOOR
Definition: matrices.h:87
zsl_mtx::sz_rows
size_t sz_rows
Definition: matrices.h:48
zsl_mtx_get
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).
Definition: matrices.c:99
ZSL_MTX_UNARY_OP_ATAN
@ ZSL_MTX_UNARY_OP_ATAN
Definition: matrices.h:98
zsl_mtx_unary_fn_t
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_...
Definition: matrices.h:142
zsl_mtx
Represents a m x n matrix, with data stored in row-major order.
Definition: matrices.h:46
zsl_mtx_qrd
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 factorisatio...
Definition: matrices.c:1318
zsl_mtx_max
int zsl_mtx_max(struct zsl_mtx *m, zsl_real_t *x)
Traverses the matrix elements to find the maximum element value.
Definition: matrices.c:1799
zsl_mtx_init_entry_fn_t
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.
Definition: matrices.h:168
zsl_mtx_reduce_iter
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',...
Definition: matrices.c:680
ZSL_MTX_BINARY_OP_GREAT
@ ZSL_MTX_BINARY_OP_GREAT
Definition: matrices.h:117
zsl_mtx_sub_d
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 identi...
Definition: matrices.c:428
ZSL_MTX_UNARY_OP_ROUND
@ ZSL_MTX_UNARY_OP_ROUND
Definition: matrices.h:85
zsl_mtx_min
int zsl_mtx_min(struct zsl_mtx *m, zsl_real_t *x)
Traverses the matrix elements to find the minimum element value.
Definition: matrices.c:1783
ZSL_MTX_UNARY_OP_ASIN
@ ZSL_MTX_UNARY_OP_ASIN
Definition: matrices.h:96
zsl_mtx_eigenvectors
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 ...
Definition: matrices.c:1504
zsl_mtx_binary_op_t
enum zsl_mtx_binary_op zsl_mtx_binary_op_t
Component-wise binary operations.
ZSL_MTX_UNARY_OP_TANH
@ ZSL_MTX_UNARY_OP_TANH
Definition: matrices.h:101
zsl_mtx_mult
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 compatib...
Definition: matrices.c:434
ZSL_MTX_UNARY_OP_ACOS
@ ZSL_MTX_UNARY_OP_ACOS
Definition: matrices.h:97
ZSL_MTX_BINARY_OP_MULT
@ ZSL_MTX_BINARY_OP_MULT
Definition: matrices.h:108
ZSL_MTX_BINARY_OP_EQUAL
@ ZSL_MTX_BINARY_OP_EQUAL
Definition: matrices.h:114
zsl_mtx_get_col
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'.
Definition: matrices.c:159
zsl_mtx_deter_3x3
int zsl_mtx_deter_3x3(struct zsl_mtx *m, zsl_real_t *d)
Calculates the determinant of the input 3x3 matrix 'm'.
Definition: matrices.c:714
zsl_mtx_min_idx
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....
Definition: matrices.c:1815
zsl_mtx_gauss_reduc
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.
Definition: matrices.c:867
zsl_mtx_qrd_iter
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...
Definition: matrices.c:1369
zsl_mtx_unary_op_t
enum zsl_mtx_unary_op zsl_mtx_unary_op_t
Component-wise unary operations.
zsl_mtx_balance
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 ...
Definition: matrices.c:1173
ZSL_MTX_UNARY_OP_LOG10
@ ZSL_MTX_UNARY_OP_LOG10
Definition: matrices.h:91
zsl_mtx_deter
int zsl_mtx_deter(struct zsl_mtx *m, zsl_real_t *d)
Calculates the determinant of the input square matrix 'm'.
Definition: matrices.c:744
zsl_mtx_add_d
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 identicall...
Definition: matrices.c:381
zsl_mtx_eigenvalues
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....
Definition: matrices.c:1398
zsl_mtx_gauss_elim
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' ...
Definition: matrices.c:809
ZSL_MTX_BINARY_OP_MAX
@ ZSL_MTX_BINARY_OP_MAX
Definition: matrices.h:113
zsl_mtx_entry_fn_empty
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.
Definition: matrices.c:31
zsl_mtx_vec_wedge
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'....
Definition: matrices.c:607
zsl_mtx::data
zsl_real_t * data
Definition: matrices.h:52
ZSL_MTX_UNARY_OP_COS
@ ZSL_MTX_UNARY_OP_COS
Definition: matrices.h:94
zsl_mtx_sum_rows_d
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'.
Definition: matrices.c:387
zsl_mtx_init
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.
Definition: matrices.c:50
zsl_mtx_pinv
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'.
Definition: matrices.c:1734
ZSL_MTX_UNARY_OP_EXP
@ ZSL_MTX_UNARY_OP_EXP
Definition: matrices.h:89
zsl_mtx_add
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 i...
Definition: matrices.c:375
zsl_mtx_max_idx
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....
Definition: matrices.c:1836
ZSL_MTX_BINARY_OP_DIV
@ ZSL_MTX_BINARY_OP_DIV
Definition: matrices.h:109
ZSL_MTX_BINARY_OP_EXPON
@ ZSL_MTX_BINARY_OP_EXPON
Definition: matrices.h:111
zsl_mtx_cols_norm
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.
Definition: matrices.c:951
zsl_mtx_trans
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' col...
Definition: matrices.c:514
zsl_mtx_entry_fn_identity
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'.
Definition: matrices.c:37
zsl_mtx_entry_fn_random
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.
Definition: matrices.c:43
zsl_mtx_binary_fn_t
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 sym...
Definition: matrices.h:156
ZSL_MTX_BINARY_OP_SUB
@ ZSL_MTX_BINARY_OP_SUB
Definition: matrices.h:107
zsl_mtx_gauss_elim_d
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' ...
Definition: matrices.c:861
zsl_mtx_binary_func
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',...
Definition: matrices.c:347
zsl_mtx_copy
int zsl_mtx_copy(struct zsl_mtx *mdest, struct zsl_mtx *msrc)
Copies the contents of matrix 'msrc' into matrix 'mdest'.
Definition: matrices.c:81
vectors.h
API header file for vectors in zscilib.
zsl_mtx_norm_elem
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....
Definition: matrices.c:965
zsl_mtx_is_sym
bool zsl_mtx_is_sym(struct zsl_mtx *m)
Checks if the square input matrix is symmetric.
Definition: matrices.c:1885
ZSL_MTX_UNARY_OP_TAN
@ ZSL_MTX_UNARY_OP_TAN
Definition: matrices.h:95
ZSL_MTX_BINARY_OP_MIN
@ ZSL_MTX_BINARY_OP_MIN
Definition: matrices.h:112
ZSL_MTX_BINARY_OP_GEQ
@ ZSL_MTX_BINARY_OP_GEQ
Definition: matrices.h:119
ZSL_MTX_UNARY_OP_SQRT
@ ZSL_MTX_UNARY_OP_SQRT
Definition: matrices.h:92
zsl_mtx_gram_schmidt
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 calcul...
Definition: matrices.c:922
ZSL_MTX_BINARY_OP_LEQ
@ ZSL_MTX_BINARY_OP_LEQ
Definition: matrices.h:118
ZSL_MTX_BINARY_OP_MEAN
@ ZSL_MTX_BINARY_OP_MEAN
Definition: matrices.h:110
ZSL_MTX_UNARY_OP_CEIL
@ ZSL_MTX_UNARY_OP_CEIL
Definition: matrices.h:88
zsl_mtx_set_row
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'.
Definition: matrices.c:144
zsl_mtx_inv_3x3
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 ...
Definition: matrices.c:1009
zsl_mtx_print
int zsl_mtx_print(struct zsl_mtx *m)
Printf the supplied matrix using printf in a human-readable manner.
Definition: matrices.c:1907
zsl_mtx_is_equal
bool zsl_mtx_is_equal(struct zsl_mtx *ma, struct zsl_mtx *mb)
Checks if two matrices are identical in shape and content.
Definition: matrices.c:1857
ZSL_MTX_UNARY_OP_LOG
@ ZSL_MTX_UNARY_OP_LOG
Definition: matrices.h:90
zsl_mtx_is_notneg
bool zsl_mtx_is_notneg(struct zsl_mtx *m)
Checks if all elements in matrix m are >= zero.
Definition: matrices.c:1873
ZSL_MTX_UNARY_OP_ABS
@ ZSL_MTX_UNARY_OP_ABS
Definition: matrices.h:86
zsl.h
API header file for zscilib.
ZSL_MTX_UNARY_OP_COSH
@ ZSL_MTX_UNARY_OP_COSH
Definition: matrices.h:100
zsl_mtx_scalar_mult_d
int zsl_mtx_scalar_mult_d(struct zsl_mtx *m, zsl_real_t s)
Multiplies all elements in matrix 'm' by scalar value 's'.
Definition: matrices.c:488
zsl_mtx_unary_func
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...
Definition: matrices.c:266
zsl_mtx::sz_cols
size_t sz_cols
Definition: matrices.h:50
zsl_mtx_householder
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 ...
Definition: matrices.c:1254
zsl_vec
Represents a vector.
Definition: vectors.h:40
zsl_mtx_from_arr
int zsl_mtx_from_arr(struct zsl_mtx *m, zsl_real_t *a)
Converts an array of values into a matrix.
Definition: matrices.c:73
zsl_mtx_set_col
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'.
Definition: matrices.c:176
ZSL_MTX_UNARY_OP_NEGATIVE
@ ZSL_MTX_UNARY_OP_NEGATIVE
Definition: matrices.h:84
zsl_mtx_adjoint
int zsl_mtx_adjoint(struct zsl_mtx *m, struct zsl_mtx *ma)
Calculates the ajoint matrix, based on the input square matrix 'm'.
Definition: matrices.c:572
zsl_real_t
double zsl_real_t
Definition: zsl.h:51
ZSL_MTX_BINARY_OP_LESS
@ ZSL_MTX_BINARY_OP_LESS
Definition: matrices.h:116
ZSL_MTX_BINARY_OP_ADD
@ ZSL_MTX_BINARY_OP_ADD
Definition: matrices.h:106
zsl_mtx_inv
int zsl_mtx_inv(struct zsl_mtx *m, struct zsl_mtx *mi)
Calculates the inverse of square matrix 'm'.
Definition: matrices.c:1064
ZSL_MTX_BINARY_OP_NEQUAL
@ ZSL_MTX_BINARY_OP_NEQUAL
Definition: matrices.h:115
ZSL_MTX_UNARY_OP_INCREMENT
@ ZSL_MTX_UNARY_OP_INCREMENT
Definition: matrices.h:82
zsl_mtx_adjoint_3x3
int zsl_mtx_adjoint_3x3(struct zsl_mtx *m, struct zsl_mtx *ma)
Calculates the ajoint matrix, based on the input 3x3 matrix 'm'.
Definition: matrices.c:534
ZSL_MTX_UNARY_OP_SIN
@ ZSL_MTX_UNARY_OP_SIN
Definition: matrices.h:93
zsl_mtx_sub
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 al...
Definition: matrices.c:422
ZSL_MTX_UNARY_OP_DECREMENT
@ ZSL_MTX_UNARY_OP_DECREMENT
Definition: matrices.h:83
zsl_mtx_reduce
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...
Definition: matrices.c:645
zsl_mtx_unary_op
zsl_mtx_unary_op
Component-wise unary operations.
Definition: matrices.h:81
zsl_mtx_binary_op
zsl_mtx_binary_op
Component-wise binary operations.
Definition: matrices.h:105