Skip to contents

Solves x b = y for b on the GPU, like solve. If y is omitted, returns the inverse of x.

A square x is solved by LU decomposition with partial pivoting, as solve does (NVIDIA's cuSOLVER, getrf/getrs). An x with more rows than columns is solved in the least-squares sense by Householder QR (geqrf/ormqr), and its "inverse" is the pseudo-inverse.

Usage

gpuSolve(x, y=NULL,
    precision = getOption("gputools.precision", "single"))

Arguments

x

a matrix of floating point numbers.

y

a vector of length nrow(x), or a matrix with nrow(x) rows.

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

b: a vector of length ncol(x) if y is a vector, otherwise a matrix with ncol(x) rows. If y is omitted, the ncol(x) by nrow(x) inverse (or pseudo-inverse) of x. Rows are named by the columns of x, as with solve.

A square x that is exactly singular is an error, as with solve; so is an overdetermined x whose columns are linearly dependent, since the least-squares solution is then not unique.

Examples

if (FALSE) { # gpuAvailable()
  x <- matrix(runif(100), 10, 10)
  y <- runif(10)
  b <- gpuSolve(x, y)
  cat("Solution:\n")
  print(b)
  x.inverse <- gpuSolve(x)
  cat("an estimate of a pseudo inverse for x:\n")
  print(x.inverse)
}