single_svdlib
A Rust library for performing Singular Value Decomposition (SVD) on sparse matrices using the Lanczos algorithm. It is build on the original library and expan
Overview
svdlibrs is a Rust port of LAS2 from SVDLIBC, originally developed by Doug Rohde. This library efficiently computes SVD on sparse matrices, particularly large ones, and returns the decomposition as ndarray components.
This implementation extends the original svdlibrs by Dave Farnham with:
- Updated dependency versions
- Support for a broader range of numeric types (f64, f32, others)
- Column masking capabilities for analyzing specific subsets of data
Features
- Performs SVD on sparse matrices using the Lanczos algorithm
- Works with various input formats: CSR, CSC, or COO matrices
- Column masking for dimension selection without data copying
- Generic implementation supporting different numeric types
- High numerical precision for critical calculations
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.10.0"
= "0.16.1"
Basic Usage
use ;
use ;
// Create a sparse matrix
let mut coo = new;
coo.push; coo.push; coo.push;
coo.push; coo.push; coo.push;
coo.push; coo.push; coo.push;
let csr = from;
// Compute SVD
let svd_result = svd?;
// Access the results
println!;
println!;
println!;
println!;
// Reconstruct the original matrix
let reconstructed = svd_result.recompose;
Column Masking
The library supports analyzing specific columns without copying the data:
use ;
use ;
// Create a sparse matrix
let mut coo = new;
coo.push; coo.push; coo.push;
coo.push; coo.push;
coo.push; coo.push; coo.push;
let csr = from;
// Method 1: Using a boolean mask (true = include column)
let mask = vec!; // Only columns 0, 2, 4
let masked_matrix = new;
// Method 2: Specifying which columns to include
let columns = vec!;
let masked_matrix = with_columns;
// Run SVD on the masked matrix
let svd_result = svd?;
Support for Different Numeric Types
The library supports various numeric types:
// With f64 (double precision)
let csr_f64 = from;
let svd_result = svd?;
// With f32 (single precision)
let csr_f32 = from;
let svd_result = svd?;
// With integer types (converted internally)
let csr_i32 = from;
let masked_i32 = with_columns;
let svd_result = svd?;
Advanced Usage
For more control over the SVD computation:
use ;
// Customize the SVD calculation
let svd: SvdRec = svdLAS2?;
SVD Results and Diagnostics
The SVD results are returned in a SvdRec struct:
The Diagnostics struct provides detailed information about the computation:
License
This library is provided under the BSD License, as per the original SVDLIBC implementation.
Acknowledgments
- Dave Farnham for the original Rust port
- Doug Rohde for the original SVDLIBC implementation
- University of Tennessee Research Foundation for the underlying mathematical library