Skip to contents

Computes a rank-k truncated singular value decomposition of X, dispatching to the most suitable algorithm and backend based on matrix size, requested rank, and available hardware.

Usage

svd_factor(
  X,
  k = min(dim(X)),
  method = c("auto", "exact", "rsvd", "subspace"),
  n_oversamples = .amatrix_svd_factor_default_oversamples(k),
  n_iter = 2L
)

Arguments

X

An aMatrix (typically adgeMatrix or adgCMatrix).

k

Positive integer; the number of singular values and vectors to compute. Defaults to min(dim(X)).

method

One of "auto" (default), "exact", "rsvd", or "subspace". "auto" selects the algorithm based on matrix dimensions and the available backend.

n_oversamples

Non-negative integer; extra random vectors used to stabilize randomized algorithms. Ignored for method = "exact".

n_iter

Non-negative integer; number of power iterations for the subspace method. Ignored for method = "exact".

Value

An amSVD object containing slots u, d, v, and metadata.

Examples

m <- matrix(rnorm(30), nrow = 6)
A <- adgeMatrix(m)
fac <- svd_factor(A, k = 3L)
fac
#> amSVD [6x5 -> rank 3 | strict | exact/exact_svd@cpu | source: 20260702132121.033621-1cdf1817:am:117]
#>   d[1:min(3,k)]: 4.4865, 3.2935, 2.2253