Skip to main content

Module sparse

Module sparse 

Source
Expand description

Sparse matrix types: CSR and COO representations. Sparse matrix representations and arithmetic.

Provides Compressed Sparse Row (SparseCsr) and Coordinate (SparseCoo) formats, plus element-wise and matrix-matrix operations.

§Determinism Contract

  • Row-wise reductions use [kahan_sum_f64] or [binned_sum_f64].
  • [sparse_matmul] accumulates column contributions in a [BTreeMap] for deterministic iteration order, then reduces each column with [binned_sum_f64].
  • No HashMap, no parallel iteration.

Structs§

SparseCoo
Coordinate (COO / triplet) sparse matrix representation.
SparseCsr
Compressed Sparse Row (CSR) matrix representation.

Functions§

sparse_add
Element-wise addition of two CSR matrices (same dimensions).
sparse_matmul
Sparse matrix-matrix multiplication (SpGEMM): C = A * B. Uses row-wise accumulation with BTreeMap for deterministic column ordering. All floating-point reductions use binned summation.
sparse_mul
Element-wise multiplication (Hadamard product) of two CSR matrices. Only positions where BOTH matrices have non-zeros produce non-zeros.
sparse_scalar_mul
Scalar multiplication: every non-zero element is multiplied by s.
sparse_sub
Element-wise subtraction of two CSR matrices (same dimensions).
sparse_transpose
Transpose a CSR matrix. Returns a new CSR where rows and columns are swapped.