#statistics #svd #r-svd


randomized singular value decomposition (rSVD)

2 releases

0.1.2 Jul 28, 2023
0.1.1 Jul 28, 2023

#129 in Science

Download history 42/week @ 2023-07-29 10/week @ 2023-08-05 8/week @ 2023-08-12 5/week @ 2023-08-19 6/week @ 2023-08-26 4/week @ 2023-09-02 12/week @ 2023-09-09 6/week @ 2023-09-16 9/week @ 2023-09-23 13/week @ 2023-09-30 12/week @ 2023-10-07 23/week @ 2023-10-14 12/week @ 2023-10-21 18/week @ 2023-10-28 16/week @ 2023-11-04 23/week @ 2023-11-11

72 downloads per month
Used in 2 crates (via pca)

MIT license

104 lines


A Rust library for computing an approximate singular value decomposition (SVD) of a matrix using randomized algorithms.


The singular value decomposition (SVD) is a matrix factorization technique that is useful for many applications in data analysis and scientific computing. However, computing the full SVD can be very computationally intensive for large matrices.

Randomized algorithms provide an efficient way to compute an approximate SVD that captures most of the action of the original matrix in significantly less time. The key ideas behind randomized SVD are:

  1. Use a random test matrix to sample the range of the input matrix
  2. Orthogonalize the samples to obtain a subspace that captures the range
  3. Compute the SVD of the smaller projected matrix

This technique allows the SVD to be approximated in O(mn log k) time instead of the O(mn min(m,n)) operations required for the full SVD, where m and n are the dimensions of the input matrix and k is the target rank.


  • Compute approximate rank-k SVD of a matrix in O(mn log k) time
  • Flexible choice of target rank k and oversampling parameter p
  • Uses BLAS/LAPACK via ndarray-linalg for performance
  • Pure Rust implementation


The main function is rsvd(), which takes a matrix, target rank k, and oversampling parameter p. It returns the approximate SVD factors U, S, and V^T.

use ndarray::{Array2, array};
use rsvd::rsvd;

let a = array!([1., 2., 3.],
               [8., 9., 4.],
               [7., 6., 5.]);

let (u, s, vt) = rsvd(&a, 2, 0, None);


Randomized SVD is useful for many applications that involve large data matrices:

  • Dimensionality reduction and feature extraction
  • Principal component analysis (PCA)
  • Recommender systems (collaborative filtering)
  • Image compression
  • Text analysis (LSA)

By efficiently approximating the SVD to capture the top k singular values/vectors, randomized SVD allows these techniques to scale to massive datasets.

The SVD also provides a powerful tool for analyzing and understanding the properties of a dataset contained in the matrix. The singular values indicate the importance of each component, while the singular vectors identify the principal components.



~840K SLoC