Use the C++ Spectra solver (same as RSpectra package), in order to
compute the largest k values and corresponding singular vectors.
Empirically, memory usage is much lower than using `irlba::irlba()`

, likely
due to avoiding R garbage creation while solving due to the pure-C++ solver.
This documentation is a slightly-edited version of the `RSpectra::svds()`

documentation.

## Usage

`svds(A, k, nu = k, nv = k, opts = list(), threads=0L, ...)`

## Arguments

- A
The matrix whose truncated SVD is to be computed.

- k
Number of singular values requested.

- nu
Number of right singular vectors to be computed. This must be between 0 and 'k'. (Must be equal to 'k' for BPCells IterableMatrix)

- opts
Control parameters related to computing algorithm. See

*Details*below- threads
Control threads to use calculating mat-vec producs (BPCells specific)

## Value

A list with the following components:

- d
A vector of the computed singular values.

- u
An

`m`

by`nu`

matrix whose columns contain the left singular vectors. If`nu == 0`

,`NULL`

will be returned.- v
An

`n`

by`nv`

matrix whose columns contain the right singular vectors. If`nv == 0`

,`NULL`

will be returned.- nconv
Number of converged singular values.

- niter
Number of iterations used.

- nops
Number of matrix-vector multiplications used.

## Details

When RSpectra is installed, this function will just add a method to
`RSpectra::svds()`

for the `IterableMatrix`

class.

The `opts`

argument is a list that can supply any of the
following parameters:

`ncv`

Number of Lanzcos basis vectors to use. More vectors will result in faster convergence, but with greater memory use.

`ncv`

must be satisfy \(k < ncv \le p\) where`p = min(m, n)`

. Default is`min(p, max(2*k+1, 20))`

.`tol`

Precision parameter. Default is 1e-10.

`maxitr`

Maximum number of iterations. Default is 1000.

`center`

Either a logical value (

`TRUE`

/`FALSE`

), or a numeric vector of length \(n\). If a vector \(c\) is supplied, then SVD is computed on the matrix \(A - 1c'\), in an implicit way without actually forming this matrix.`center = TRUE`

has the same effect as`center = colMeans(A)`

. Default is`FALSE`

. Ignored in BPCells`scale`

Either a logical value (

`TRUE`

/`FALSE`

), or a numeric vector of length \(n\). If a vector \(s\) is supplied, then SVD is computed on the matrix \((A - 1c')S\), where \(c\) is the centering vector and \(S = diag(1/s)\). If`scale = TRUE`

, then the vector \(s\) is computed as the column norm of \(A - 1c'\). Default is`FALSE`

. Ignored in BPCells

## References

Qiu Y, Mei J (2022). *RSpectra: Solvers for Large-Scale Eigenvalue and SVD Problems*. R package version 0.16-1, https://CRAN.R-project.org/package=RSpectra.