Expand description
sprs is a sparse linear algebra library for Rust.
It features a sparse matrix type, CsMat
, and a sparse vector type,
CsVec
, both based on the
compressed storage scheme.
§Features
- sparse matrix/sparse matrix addition, multiplication.
- sparse vector/sparse vector addition, dot product.
- sparse matrix/dense matrix addition, multiplication.
- sparse triangular solves.
- powerful iteration over the sparse structure, enabling easy extension of the library.
- matrix construction using the triplet format, vertical and horizontal stacking, block construction.
- sparse cholesky solver in the separate crate
sprs-ldl
. - fully generic integer type for the storage of indices, enabling compact representations.
- planned interoperability with existing sparse solvers such as
SuiteSparse
.
§Quick Examples
Matrix construction:
use sprs::{CsMat, TriMat};
let mut a = TriMat::new((4, 4));
a.add_triplet(0, 0, 3.0_f64);
a.add_triplet(1, 2, 2.0);
a.add_triplet(3, 0, -2.0);
// This matrix type does not allow computations, and must to
// converted to a compatible sparse type, using for example
let b: CsMat<_> = a.to_csr();
Constructing matrix using the more efficient direct sparse constructor
use sprs::{CsMat, CsVec};
let eye : CsMat<f64> = CsMat::eye(3);
let a = CsMat::new_csc((3, 3),
vec![0, 2, 4, 5],
vec![0, 1, 0, 2, 2],
vec![1., 2., 3., 4., 5.]);
Matrix vector multiplication:
use sprs::{CsMat, CsVec};
let eye = CsMat::eye(5);
let x = CsVec::new(5, vec![0, 2, 4], vec![1., 2., 3.]);
let y = &eye * &x;
assert_eq!(x, y);
Matrix matrix multiplication, addition:
use sprs::{CsMat, CsVec};
let eye = CsMat::eye(3);
let a = CsMat::new_csc((3, 3),
vec![0, 2, 4, 5],
vec![0, 1, 0, 2, 2],
vec![1., 2., 3., 4., 5.]);
let b = &eye * &a;
assert_eq!(a, b.to_csc());
Re-exports§
pub use crate::indexing::SpIndex;
pub use crate::sparse::CompressedStorage::CSC;
pub use crate::sparse::CompressedStorage::CSR;
pub use SymmetryCheck::*;
pub use PermutationCheck::*;
Modules§
- approx
- Traits for comparing vectors and matrices using the approx traits
- array_
backend - Fixed size arrays usable for sparse matrices.
- binop
- Sparse matrix addition, subtraction
- errors
- Error type for sprs
- indexing
- Abstraction over types of indices
- io
- Serialization and deserialization of sparse matrices
- linalg
- Sparse linear algebra
- num_
kinds - Trait to be able to know at runtime if a generic scalar is an integer, a float or a complex.
- num_
matrixmarket - prod
- Sparse matrix product
- smmp
- Implementation of the paper Bank and Douglas, 2001, Sparse Matrix Multiplication Package (SMPP)
- special_
mats - Common sparse matrices
- stack
- vec
- visu
Structs§
- CsIter
- CsMat
Base - Compressed matrix in the CSR or CSC format, with sorted indices.
- CsVec
Base - A sparse vector, storing the indices of its non-zero data.
- IndPtr
Base - Permutation
- TriMat
Base - Sparse matrix in the triplet format.
- TriMat
Iter - An iterator over elements of a sparse matrix, in the triplet format
Enums§
- Compressed
Storage - Describe the storage of a
CsMat
- Fill
InReduction - The different kinds of fill-in-reduction algorithms supported by sprs
- Permutation
Check - Configuration enum to ask for permutation checks in algorithms
- Symmetry
Check - Configuration enum to ask for symmetry checks in algorithms
Traits§
- Dense
Vector - A trait for types representing dense vectors, useful for expressing algorithms such as sparse-dense dot product, or linear solves.
- Dense
Vector Mut - Trait for dense vectors that can be modified, useful for expressing algorithms which compute a resulting dense vector, such as solvers.
- MulAcc
- Trait for types that have a multiply-accumulate operation, as required in dot products and matrix products.
- Sparse
Mat - A trait for common members of sparse matrices
Functions§
- assign_
to_ dense - Assign a sparse matrix into a dense matrix
- bmat
- Specify a sparse matrix by constructing it from blocks of other matrices
- hstack
- Construct a sparse matrix by horizontally stacking other matrices
- is_
symmetric - kronecker_
product - Compute the Kronecker product between two matrices
- perm_
is_ valid - permute_
cols - Compute the matrix resulting from the product A * P
- permute_
rows - Compute the matrix resulting from the product P * A
- transform_
mat_ papt - Compute the square matrix resulting from the product P * A * P^T
- transform_
mat_ paq - Compute the matrix resulting from the product P * A * Q, using the same number of operations and allocation as for computing either P * A or A * Q by itself.
- vstack
- Construct a sparse matrix by vertically stacking other matrices
Type Aliases§
- CsMat
- CsMatI
- CsMat
VecView - CsMat
View - CsMat
ViewI - CsMat
View Mut - CsMat
View MutI - CsStructure
- CsStructureI
- CsStructure
View - CsStructure
ViewI - CsVec
- CsVecI
- CsVec
View - CsVec
ViewI - CsVec
View Mut - CsVec
View MutI - IndPtr
- IndPtr
View - Ix1
- Ix2
- Perm
Owned - Perm
OwnedI - Perm
View - Perm
ViewI - Shape
- The shape of a matrix. This a 2-tuple with the first element indicating the number of rows, and the second element indicating the number of columns.
- TriMat
- TriMatI
- TriMat
View - TriMat
ViewI - TriMat
View Mut - TriMat
View MutI