Expand description
§algebra-sparse
A sparse linear algebra library built on top of nalgebra, providing efficient sparse matrix and vector operations.
§Features
- Compressed Sparse Matrix Storage: CSR (Compressed Sparse Row) and CSC (Compressed Sparse Column) formats
- Block Diagonal Matrices: Efficient storage and operations for block diagonal matrices
- Matrix Operations: Sparse-sparse, sparse-dense, and sparse-vector multiplications
- Zero Threshold Support: Automatic filtering of near-zero values for memory efficiency
- View-based API: Efficient borrowing and slicing without allocation
- nalgebra Integration: Seamless conversion between sparse and dense representations
§Quick Start
use algebra_sparse::CsrMatrix;
use nalgebra::DMatrix;
// Create a dense matrix and convert to sparse
let dense = DMatrix::from_row_slice(3, 3, &[
1.0, 0.0, 2.0,
0.0, 3.0, 0.0,
4.0, 0.0, 5.0,
]);
let sparse = CsrMatrix::from_dense(dense.as_view());
// Perform sparse matrix operations
let result = sparse.as_view() * dense.column(0);
println!("Result: {:?}", result);§Matrix Formats
This library supports several sparse matrix formats optimized for different use cases:
- CSR (Compressed Sparse Row): Efficient for row-wise operations and matrix-vector products
- CSC (Compressed Sparse Column): Efficient for column-wise operations
- Block Diagonal: Optimized for block diagonal structure common in physical simulations
§Performance Considerations
- Zero values below the threshold are automatically filtered during construction
- View-based operations avoid unnecessary allocations
- Sparse-sparse operations use efficient merging algorithms
- Block diagonal operations leverage structure for optimal performance
Re-exports§
pub use set::*;
Modules§
Structs§
- CsMatrix
- Compressed Sparse Matrix in either CSR or CSC format.
- CsMatrix
View - An immutable view of a compressed sparse matrix.
- CsVec
Builder - A builder for constructing sparse vectors efficiently.
- CsVec
Mut - A mutable view of a sparse vector.
- CsVec
Ref - An immutable view of a sparse vector.
- CscMatrix
View - Compressed Sparse Column (CSC) Matrix View.
- CsrMatrix
- Compressed Sparse Row (CSR) Matrix.
- CsrMatrix
View - An immutable view of a CSR matrix.
- Diagonal
Block Matrix - A sparse matrix composed of block diagonal matrices.
- Diagonal
Block Matrix View - An immutable view of a block diagonal matrix.
Traits§
- CsrMatrix
View Methods - Trait providing methods for CSR matrix view operations.
- Real
- Trait combining nalgebra’s RealField with ZeroThreshold for use in sparse operations.
- Zero
Threshold - Trait for types that have a zero threshold.