Skip to contents

The singular value decomposition of a matrix, as svd computes it, on the GPU with NVIDIA's cuSOLVER (gesvd).

Usage

gpuSvd(x, nu = min(n, p), nv = min(n, p),
  precision = getOption("gputools.precision", "single"))

Arguments

x

a numeric matrix, without missing or infinite values.

nu, nv

the number of left and right singular vectors to return, as in svd; at most min(nrow(x), ncol(x)), since the thin decomposition is computed.

precision

"single" or "double": the floating point precision the GPU computes in. Single precision is the default, set with options(gputools.precision = "double"); it runs many times faster on most consumer GPUs. Results are returned as doubles either way.

Value

As svd: a list with d, the singular values in decreasing order, and, when asked for, u and v, the left and right singular vectors as columns. As with any SVD, each pair of singular vectors is determined only up to sign, so their signs can differ from svd's.

See also

Examples

if (FALSE) { # gpuAvailable()
x <- matrix(rnorm(200 * 20), 200, 20)
s <- gpuSvd(x, precision = "double")
s$d
max(abs(x - s$u %*% diag(s$d) %*% t(s$v)))
}