Module sparse

Source
Expand description

Comprehensive sparse matrix format support

Provides unified support for common sparse matrix formats:

  • COO (Coordinate), CSR (Compressed Sparse Row), and CSC (Compressed Sparse Column) formats
  • Efficient format conversion algorithms
  • Matrix operations (addition, multiplication, transpose)
  • I/O support with Matrix Market integration
  • Performance-optimized algorithms for large sparse matrices
  • Memory-efficient sparse data handling

§Examples

use scirs2_io::sparse::SparseMatrix;
use ndarray::Array2;

// Create a sparse matrix from a dense array
let dense = Array2::from_shape_vec((3, 3), vec![
    1.0_f64, 0.0_f64, 2.0_f64,
    0.0_f64, 3.0_f64, 0.0_f64,
    4.0_f64, 0.0_f64, 5.0_f64
]).unwrap();

let mut sparse = SparseMatrix::from_dense_2d(&dense, 0.0_f64)?;
println!("Sparse matrix: {} non-zeros", sparse.nnz());

// Convert to different formats
let _csr = sparse.to_csr()?;
let _csc = sparse.to_csc()?;

// Save to file
sparse.save_matrix_market("matrix.mtx")?;

Comprehensive sparse matrix format support

This module provides unified support for common sparse matrix formats used in scientific computing: COO (Coordinate), CSR (Compressed Sparse Row), and CSC (Compressed Sparse Column). It integrates and enhances the existing sparse matrix functionality from other modules.

§Features

  • Multiple Formats: Support for COO, CSR, and CSC formats
  • Format Conversion: Efficient conversion between formats
  • Matrix Operations: Basic sparse matrix operations (addition, multiplication, transpose)
  • I/O Support: Reading and writing in various file formats
  • Integration: Seamless integration with Matrix Market and other formats
  • Performance: Optimized algorithms for large sparse matrices
  • Memory Efficiency: Minimal memory overhead for sparse data

§Examples

use scirs2_io::sparse::{SparseMatrix, SparseFormat};
use ndarray::Array2;

// Create a sparse matrix from a dense array
let dense = Array2::from_shape_vec((3, 3), vec![
    1.0, 0.0, 2.0,
    0.0, 3.0, 0.0,
    4.0, 0.0, 5.0
]).unwrap();

let mut sparse = SparseMatrix::from_dense(&dense, 1e-10)?;
println!("Sparse matrix: {} non-zeros", sparse.nnz());

// Convert to different formats
let csr = sparse.to_csr()?;
let csc = sparse.to_csc()?;

// Save to file
sparse.save_matrix_market("matrix.mtx")?;

Modules§

ops
Sparse matrix operations

Structs§

SparseMatrix
Comprehensive sparse matrix supporting multiple formats
SparseStats
Sparse matrix statistics for analysis

Enums§

SparseFormat
Sparse matrix storage formats