- Written in
C
for maximum compatibility among various systems - No external libraries (all-in-one header file)
- Small enough to fit inside MS-DOS (and eventually embedded systems)
- Tailored to be used in Finite Element and Machine Learning softwares
All the functions that return a matrix allocate new memory for the returned matrix.
function | operation | math |
---|---|---|
mat_new(n,m) |
allocate memory for |
|
mat_free(A) |
free the allocated memory for matrix |
|
mat_set(A,i,j,a) |
set the member of |
|
a = mat_get(A,i,j) |
get the member of |
|
B = mat_copy(A) |
copy the matrix |
|
mat_add_r(A,B) |
add matrix |
|
mat_sub_r(A,B) |
subtract matrix |
|
C = mat_add(A,B) |
add matrix |
|
C = mat_sub(A,B) |
subtract matrix |
|
B = mat_smul(A,c) |
scale the matrix |
|
mat_smul_r(A,c) |
scale the matrix |
|
C = mat_mul(A,B) |
multiply |
|
mat_equal(A,B,tol) |
check if matrix |
true if |
B = mat_transpose(A) |
transpose the matrix |
|
mat_transpose_r(A) |
transpose the matrix |
|
t = mat_trace(A) |
return the trace of |
|
I = mat_eye(n) |
create an |
|
U = mat_GaussJordan(A) |
transform matrix |
|
LUP = mat_lup_solve(A) |
find the LU(P) decomposition of lup struct) |
|
QR = mat_qr_solve(A) |
find the QR decomposition of qr struct) |
|
a = eigen_qr(A) |
calculate eigenvalues of |
|
mat_print(A) |
print matrix |
#include "SLAP.h"
void main()
{
// allocate the matrix structure and set the values:
mat *A = mat_init(3,3, (double[]){1,2,3,4,5,6,7,8,9});
printf("A = \n"); mat_print(A); // print the matrix
mat_free(A); // free the allocated memory
}
#include "SLAP.h"
void main()
{
mat *A, *I, *u, *v;
A = mat_init(3,3, (double[]){1,2,3,4,5,6,7,8,9});
I = mat_init(3,3, (double[]){1,0,0,0,1,0,0,0,1}); // identity matrix
// scalar-matrix multiplication:
mat_print(mat_smul(A, 2.5)); // print 2.5 * A
// vector-vector multiplication:
u = mat_init(3,1, (double[]){1,2,3}); // column vector
v = mat_init(3,1, (double[]){2,2,2}); // column vector
printf("u^T * v =\n"); mat_print(mat_mul(mat_transpose(u), v)); // scalar product
printf("u * v^T = "); mat_print(mat_mul(u, mat_transpose(v))); // tensor product
// matrix-vector multiplication:
mat_print(mat_mul(A,u)); // A * u
// matrix-matrix multiplication:
mat_print(mat_mul(A,I)); // A * I
mat_print(mat_mul(A,A)); // A * A
mat_free(A); mat_free(I); mat_free(u); mat_free(v);
}
#include "SLAP.h"
void main()
{
mat *A = mat_init(3,3, (double[]){1,3,3,4,5,6,7,8,9});
mat *b = mat_init(3,1, (double[]){1,1,1});
printf("A =\n"); mat_print(A);
printf("b =\n"); mat_print(b);
printf("Solve A * x = b for x\n\n");
printf("LU(P) decomposition:\n");
mat_lup *lu = mat_lup_solve(A); // LU(P) decomposition of matrix A
mat* x = solve_lu(lu, b); // solve linear system using LU decomposition
printf("x =\n"); mat_print(x);
printf("\n\n\nGauss elimination of A:\n");
print_mat(mat_GaussJordan(A));
mat_free(A); mat_free(b);
}
#include "SLAP.h"
void main()
{
mat *A = mat_init(3,3, (double[]){1,3,3,4,5,6,7,8,9});
mat_print(eigen_qr(A)); // print eigenvalues using QR decomposition
}
- CORE
- BTC++
mat_init_DOS
- error handling
-
push_back()
likevector<TYPE>
for vectors (column or row matrices) -
__attribute__((cleanup(mat_free)))
prima della definizione delle matrici che devono auto-eliminarsi? - usare
static
davanti amat*
di ritorno di alcune funzioni? -
inline void
permat_free
? -
const mat*
come arg alle funzioni migliora la gestione della memoria?
- BTC++
- BASIC OPERATIONS
- multiplication
- cache aligned (for row-major)
- Strassen
- Coppersmith?
- Hadamard product
- trace
- diagonal square matrix from vector
- rename
smul
intoscale
? - ...
- multiplication
- DECOMPOSITION
- separare l'implementazione di LU e QR dai solver (files separati)
- QR
- Householder method
- Gibs rotations?
- Cholesky factorization
- Singular Value Decomposition (SVD)
- Principal Component Analysis (PCA)
- ...
- SOLVER
- controllare la stabilitĂ (e la velocitĂ )
- LU decomposition
- use Cholesky factorialization for positive definite matrix to improve speed
- QR decomposition
- devo solamente implementare la routine che risolve il sistema
- iterative algorithms (for large scale problems)
- Jacobi iterative method
- Gauss-Seidel iterative method
- Successive over Relaxation SOR method
- Conjugate gradient
- Fix for 3x3 example (2x2 works)
- Bi-conjugate gradient
- Sparse solvers
- conjugate gradient?
- preconditioning?
- ...
- EIGEN
- QR decomposition
- definire meglio quando finire la procedura iterativa
- forma di Hessenberg per aumentare l'efficienza
- implicit QR algorithm?
- Iterative power methods
- ...
- QR decomposition
- ADVANCED OPERATIONS
- determinant
- LU(P) decomposition (nml)
- Sviluppo di Laplace
- Bareiss algorithm
- Division-free algorithm
- Fast matrix multiplication
- inverse
- LU(P) decomposition (nml)
- matrice aggiunta e determinante
- positive defined check
- Eigenvalues?
- matrix norms
- exponent
- least squares (example)
- order of a matrix
- vector product
vec3 * vec3
- conjugate matrix
- Hessenberg form
- Vandermonde, Hankel, etc.
- Jacobian
- Hessian
- FFT
- Control systems methods
- ...
- determinant
- UTILS
- random number generator
- simple mod-type pseudo-random generator
- sample from gaussian distribution
- complex matrices
- ...
- random number generator