SciRS2 Sparse
Production-ready sparse matrix library for Rust - rc.2 release (0.1.0-rc.2) with SciRS2 POLICY implementation.
SciRS2 Sparse provides comprehensive sparse matrix functionality with feature parity to SciPy's sparse module. Following the SciRS2 POLICY, this module is designed for high-performance scientific computing applications with memory-efficient storage, optimized algorithms, and enhanced GPU support through scirs2-core abstractions.
🚀 rc.2 Release Status
Release Candidate 2 continues the production-ready sparse matrix implementation with:
- ✅ GPU Acceleration: Multi-backend GPU support (CUDA, OpenCL, Metal) established in beta.4
- ✅ Complete Graph Algorithms: BFS, DFS, shortest paths, MST, Laplacian matrices (csgraph module)
- ✅ Advanced Solvers: Full suite of iterative solvers (CG, BiCG, GMRES, QMR, etc.) with preconditioners
- ✅ Zero Warnings: Full clippy compliance as part of workspace-wide quality initiative
- ✅ Production Ready: Comprehensive testing, documentation, and SciPy API compatibility
Features
- 🎯 Production-Ready: Thoroughly tested with comprehensive test coverage and numerical accuracy validation
- 📊 Complete Sparse Matrix Support: CSR, CSC, COO, DOK, LIL, DIA, BSR formats with seamless conversions
- 🔧 Advanced Linear Algebra: Full suite of iterative solvers (CG, BiCG, GMRES, QMR, etc.) with preconditioning
- ⚡ High Performance: Memory-efficient algorithms optimized for sparse data structures
- 🔄 SciPy Compatibility: API design compatible with SciPy's sparse module for easy migration
- 🛡️ Type Safety: Rust's type system ensures memory safety and prevents common numerical errors
- 🔗 Modular Design: Integrates seamlessly with other SciRS2 modules and the broader ecosystem
Installation
Add the following to your Cargo.toml:
[]
= "0.1.0-rc.2"
Optional Performance Features
For enhanced performance in production environments:
[]
= { = "0.1.0-rc.2", = ["parallel", "simd"] }
Available Features:
parallel- Enable parallel processing using Rayon for large matricessimd- Enable SIMD acceleration for computational kernelsserde- Enable serialization support for sparse matrices
Stability Note
This is Release Candidate 2 (rc.2) before the 1.0.0 stable release. The API is stable and production-ready for all core functionality. This release includes comprehensive GPU acceleration support (from beta.4) and workspace-wide code quality improvements with zero warnings. Breaking changes will be minimal and well-documented in the migration to 1.0.0.
Usage
Basic usage examples:
use ;
use CoreResult;
use ;
// Create and use a CSR matrix
// Convert between different sparse formats
// Sparse linear algebra operations
Production Examples
For more comprehensive examples, see the examples/ directory:
index_dtype_demo.rs- Advanced index dtype handling and optimization techniquessymmetric_matrix_ops.rs- Symmetric sparse matrix operations with performance comparisons
These examples demonstrate real-world usage patterns and best practices for production applications.
Components
Sparse Matrix Formats
Various sparse matrix implementations:
use ;
Format Conversions
Functions for converting between formats:
use ;
Linear Algebra
Sparse matrix operations:
use ;
Utilities
Helper functions:
use ;
Performance Considerations
The sparse matrix implementations are optimized for performance:
- Memory-efficient storage for matrices with many zeros
- Specialized algorithms for sparse operations
- Leverages the
sprscrate for core implementations - Support for parallel operations when feature flags are enabled
Example of performance comparison:
use ;
use Array2;
use Instant;
// Create a large, sparse matrix (95% zeros)
let n = 1000;
let density = 0.05;
let sparse_mat = random.unwrap;
// Convert to dense for comparison
let dense_mat = sparse_mat.to_dense.unwrap;
// Create a vector
let vec = vec!;
// Measure sparse matrix-vector multiplication time
let start = now;
let sparse_result = spmv.unwrap;
let sparse_time = start.elapsed;
// Measure dense matrix-vector multiplication time
let start = now;
let dense_result = dense_mat.dot;
let dense_time = start.elapsed;
println!;
println!;
println!;
Contributing
See the CONTRIBUTING.md file for contribution guidelines.
License
This project is dual-licensed under:
You can choose to use either license. See the LICENSE file for details.