neco-sparse
Lightweight COO and CSR sparse matrix types for assembling sparse operators and iterating rows efficiently in caller-side sparse linear algebra code.
Matrix formats
neco-sparse focuses on two storage formats:
CooMat<T>for assembly, where entries are pushed as(row, col, value)tripletsCsrMat<T>for computation, where rows are contiguous and row-wise traversal runs inO(nnz)
The common workflow is to accumulate entries in COO, allow duplicates during assembly, and convert once to CSR for iteration, diagonal extraction, submatrix construction, or caller-side SpMV.
Usage
Build CSR directly
use CsrMat;
let csr = try_from_csr_data.unwrap;
assert_eq!;
assert_eq!;
Assemble in COO, then convert
use ;
let mut coo = new;
coo.push;
coo.push;
coo.push;
let csr = from;
assert_eq!;
Iterate rows and build auxiliary matrices
use CsrMat;
let eye = identity;
let zeros = zeros;
for row in eye.row_iter
assert_eq!;
Extract diagonals and submatrices
use ;
let mut coo = new;
coo.push;
coo.push;
coo.push;
coo.push;
coo.push;
let csr = from;
let diag = csr.diagonal.unwrap;
let sub = csr.submatrix.unwrap;
assert_eq!;
assert_eq!;
API
| Item | Description |
|---|---|
CooMat<T> |
Coordinate-format sparse matrix for assembly |
CooMat::new(rows, cols) |
Create an empty COO matrix |
CooMat::push(row, col, value) |
Add one triplet entry |
CsrMat<T> |
Compressed sparse row matrix for computation |
CsrMat::try_from_csr_data(...) |
Construct CSR directly from raw arrays with validation |
From<&CooMat<T>> for CsrMat<T> |
Convert COO to CSR and sum duplicate coordinates |
CsrMat::row(i) / row_iter() |
Access one row or iterate rows |
CsrRow<'a, T> |
Borrowed row view with column indices and values |
CsrMat::identity(n) / zeros(rows, cols) |
Convenience constructors for f64 matrices |
CsrMat::linear_combination(alpha, other, beta) |
Build alpha * self + beta * other when both CSR patterns match |
CsrMat::diagonal() |
Extract the diagonal entries and return Err when a required entry is missing |
CsrMat::submatrix(rows, cols) |
Build a CSR submatrix from unique row/column index lists |
License
MIT