Sparse Randomized SVD#

2026-09-18

3 min read time

Applies to Linux

#include <raft/sparse/solver/randomized_svds.cuh>

namespace raft::sparse::solver

template<typename ValueTypeT, typename OperatorT>
void sparse_randomized_svd(
raft::resources const &handle,
sparse_svd_config<ValueTypeT> const &config,
OperatorT const &op,
raft::device_vector_view<ValueTypeT, uint32_t> singular_values,
detail::nondeduced_optional_matrix_view_t<raft::device_matrix_view<ValueTypeT, uint32_t, raft::col_major>> U = std::nullopt,
detail::nondeduced_optional_matrix_view_t<raft::device_matrix_view<ValueTypeT, uint32_t, raft::col_major>> Vt = std::nullopt
)#

Compute truncated SVD using randomized algorithm with a generic linear operator.

Implements randomized SVD (Halko et al. 2009) with CholeskyQR2 orthogonalization (Tomás et al. 2024) for efficient GPU execution on sparse matrices.

The operator interface allows implicit linear operators (e.g. mean-centered sparse matrices for PCA) without materializing the dense matrix. OperatorT must expose the minimal interface used by the randomized SVD inner loop:

  • int rows() const / int cols() const

  • void apply(handle, X, Y) const computes Y = A @ X

  • void apply_transpose(handle, X, Z) const computes Z = A^T @ X

where X, Y, Z are raft::device_matrix_view<..., uint32_t, raft::col_major>. This is intentionally a narrow, SVD-specific operator: only the two matrix products above are required, and no other operations (addition, scaling, inverse, eigensolves, etc.) are assumed or supported — it is not a general-purpose linear operator like scipy.sparse.linalg.LinearOperator.

Note

References: [1] Halko, Martinsson, Tropp (2009) “Finding structure with randomness” https://arxiv.org/abs/0909.4061

[2] Tomás, Quintana-Ortí, Anzt (2024) “Fast Truncated SVD of Sparse and Dense Matrices

on Graphics Processors”

https://arxiv.org/abs/2403.06218

Template Parameters:
  • ValueTypeT – Data type (float or double)

  • OperatorT – Linear operator type satisfying the interface above

Parameters:
  • handle – [in] raft resources handle

  • config – [in] SVD configuration parameters

  • op – [in] linear operator representing the matrix to decompose

  • singular_values – [out] output singular values of shape (n_components,) in descending order

  • U – [out] optional output left singular vectors of shape (m, n_components), col-major. Pass std::nullopt to skip computing U.

  • Vt – [out] optional output right singular vectors of shape (n_components, n), col-major. Pass std::nullopt to skip computing Vt.

template<typename ValueTypeT, typename NNZTypeT>
void sparse_randomized_svd(
raft::resources const &handle,
sparse_svd_config<ValueTypeT> const &config,
raft::device_csr_matrix_view<const ValueTypeT, int, int, NNZTypeT> A,
raft::device_vector_view<ValueTypeT, uint32_t> singular_values,
detail::nondeduced_optional_matrix_view_t<raft::device_matrix_view<ValueTypeT, uint32_t, raft::col_major>> U = std::nullopt,
detail::nondeduced_optional_matrix_view_t<raft::device_matrix_view<ValueTypeT, uint32_t, raft::col_major>> Vt = std::nullopt
)#

Compute truncated SVD of a sparse CSR matrix using randomized algorithm.

Convenience overload that accepts a CSR matrix view directly.

Template Parameters:
  • ValueTypeT – Data type (float or double)

  • NNZTypeT – Type for number of non-zeros

Parameters:
  • handle – [in] raft resources handle

  • config – [in] SVD configuration parameters

  • A – [in] input sparse CSR matrix of shape (m, n)

  • singular_values – [out] output singular values of shape (n_components,) in descending order

  • U – [out] optional output left singular vectors of shape (m, n_components), col-major. Pass std::nullopt to skip computing U.

  • Vt – [out] optional output right singular vectors of shape (n_components, n), col-major. Pass std::nullopt to skip computing Vt.

template<typename ValueTypeT>
struct sparse_svd_config#
#include <svds_config.hpp>

Configuration parameters for the sparse randomized SVD solver.

Template Parameters:

ValueTypeT – Data type for values (float or double)

Public Members

int n_components = 0#

Number of singular values/vectors to compute. Must be set by the user.

int n_oversamples = 10#

Number of extra random vectors for better approximation. Total subspace dimension is n_components + n_oversamples.

int n_power_iters = 2#

Number of power iteration passes. More iterations improve accuracy for matrices with slowly decaying singular values.

std::optional<uint64_t> seed = std::nullopt#

Random seed for reproducibility.