rsparse
A Rust library for solving sparse linear systems using direct methods.
Data structures
- CSC matrix (
Sprs
) - Triplet matrix (
Trpl
)
Features
- Convert from dense
[Vec<T>]
orVec<Vec<T>>
matrix to CSC sparse matrixSprs
- Convert from sparse to dense
Vec<Vec<T>>
- Convert from a triplet format matrix
Trpl
to CSCSprs
- Sparse matrix addition [C=A+B]
- Sparse matrix multiplication [C=A*B]
- Transpose sparse matrices
- Solve sparse linear systems
Solvers
- lsolve: Solve a lower triangular system. Solves Lx=b where x and b are dense.
- ltsolve: Solve L’x=b where x and b are dense.
- usolve: Solve an upper triangular system. Solves Ux=b where x and b are dense
- utsolve: Solve U’x=b where x and b are dense
- cholsol: A\b solver using Cholesky factorization. Where A is a defined positive
Sprs
matrix and b is a dense vector - lusol: A\b solver using LU factorization. Where A is a square
Sprs
matrix and b is a dense vector - qrsol: A\b solver using QR factorization. Where A is a rectangular
Sprs
matrix and b is a dense vector
Examples
Basic matrix operations
use rsparse;
Output:
A
0 0 2
1 0 0
9 9 9
At
0 1 9
0 0 9
2 0 9
B
0 1 11
1 0 9
11 9 18
C
22 18 36
0 1 11
108 90 342
Solve a linear system
use rsparse;
Output:
X
[0.2646806068156303, -1.2280777288645675, -0.035491404094236435, -0.6766064748053932, -0.06619898266432682, 0.7615102544801993, 1.8522970972589123, -0.2830302118359591]
Documentation
Documentation is available at docs.rs.
Sources
- Davis, T. (2006). Direct Methods for Sparse Linear Systems. Society for Industrial and Applied Mathematics. https://doi.org/10.1137/1.9780898718881
- CSparse: A Concise Sparse Matrix Package in C