rSVD for faer matrices
rsvd-faer is a Rust crate for randomized singular value decomposition, rewritten from the original ekg/rsvd implementation to work directly with faer matrices.
Overview
This crate computes an approximate rank-k SVD of a matrix A using randomized range finding and projection:
- Draw a Gaussian test matrix
Ω - Compute the sample matrix
Y = A Ω - Optionally apply
qpower iterations to improve spectral approximation - Compute a thin QR factorization of
Y - Project
Ainto the smaller subspace and compute a thin SVD - Recover approximate factors
U,S, andVᵀ
The implementation uses faer for matrix storage, BLAS-style multiplication, QR decomposition, and SVD on the smaller projected matrix.
Features
- Approximate truncated SVD for
faer::Mat<f64>matrices with a target rankkwhich runs faster than full svd. - Supports RNG seed and
faer::Parallelism. - Returns
U,S, andVᵀdirectly asfaer::Mat<f64> - Inspired by the original
ekg/rsvdcrate and adapted for thefaermatrix ecosystem
Example
use ;
use SeedableRng;
use ChaCha8Rng;
use rsvd;
let mut rng = seed_from_u64;
let a = from_fn;
let = rsvd;
println!;
println!;
println!;
API
a: input matrix with shape(m, n)k: target rank of the approximationp: oversampling parameter, typically5..10q: number of power iterations; use0for no iterationrng: random number generator for Gaussian samplingpar:faer::Parallelismmode for matrix multiplication
Returns:
U: left singular vectors with shape(m, k)S: singular values as a(k, 1)matrixVᵀ: right singular vectors transposed with shape(k, n)
Notes
- The crate uses a Gaussian random matrix for range sampling.
- The returned
Smatrix contains the topksingular values down the diagonal. q > 0improves accuracy for matrices with slowly decaying singular values, at the cost of extra matrix multiplications.
Acknowledgements
This crate is inspired by the original ekg/rsvd implementation. Thanks to the original author for the reference implementation and the randomized SVD design.
References
- Nathan Halko, Per-Gunnar Martinsson, and Joel A. Tropp, “Finding structure with randomness: Probabilistic algorithms for constructing approximate matrix decompositions,” 2011. https://arxiv.org/abs/0909.4061
License
MIT