Skip to main content

Module sparse

Module sparse 

Source
Expand description

Sparse matrix integration with ndarray types.

This module provides conversion functions between ndarray dense matrices and OxiBLAS sparse matrix formats (CSR, CSC), plus sparse linear algebra operations that accept and return ndarray types.

§Features

  • Conversions: Dense (Array2) to/from CSR and CSC sparse formats
  • SpMV: Sparse matrix-vector multiplication returning Array1
  • Sparse Solve: Solve sparse linear systems using CG, returning Array1

§Example

use ndarray::array;
use oxiblas_ndarray::sparse::{array2_to_csr, spmv_ndarray};

let dense = array![[1.0, 0.0, 2.0], [0.0, 3.0, 0.0], [4.0, 0.0, 5.0]];
let csr = array2_to_csr(&dense);
assert_eq!(csr.nnz(), 5);

let x = array![1.0, 1.0, 1.0];
let y = spmv_ndarray(&csr, &x);
assert_eq!(y, array![3.0, 3.0, 9.0]);

Enums§

SparseNdarrayError
Error type for sparse ndarray operations.

Functions§

array2_to_csc
Converts a dense Array2 to CSC (Compressed Sparse Column) format using exact-zero sparsification.
array2_to_csc_with_tolerance
Converts a dense Array2 to CSC (Compressed Sparse Column) format, with an explicit, opt-in tolerance for approximate sparsification.
array2_to_csr
Converts a dense Array2 to CSR (Compressed Sparse Row) format using exact-zero sparsification.
array2_to_csr_with_tolerance
Converts a dense Array2 to CSR (Compressed Sparse Row) format, with an explicit, opt-in tolerance for approximate sparsification.
csc_to_array2
Converts a CSC matrix back to a dense Array2.
csr_to_array2
Converts a CSR matrix back to a dense Array2.
sparse_solve_ndarray
Solve a sparse linear system A * x = b using Conjugate Gradient.
sparse_solve_ndarray_with_options
Solve a sparse linear system with custom tolerance and max iterations.
spmv_full_ndarray
Sparse matrix-vector multiplication with scaling: y = alpha * A * x + beta * y
spmv_ndarray
Sparse matrix-vector multiplication: y = A * x