solve_gpu.matrix {GPUmatrix}R Documentation

Solve a System of Equations

Description

The function solve mimics of the 'base' function solve to operate on gpu.matrix-class objects: it "solves the equation a %*% x = b."

The function ginv mimics the function ginv of package 'MASS' to operate on gpu.matrix-class objects: it "Calculates the Moore-Penrose generalized inverse of a matrix X."

The function chol_solve is a GPUmatrix own function. This function uses the Cholesky decomposition to solve a system of equations.

Usage


## S4 method for signature 'ANY,gpu.matrix.tensorflow'
solve(a,b)
## S4 method for signature 'ANY,gpu.matrix.torch'
solve(a,b)
## S4 method for signature 'gpu.matrix.tensorflow,ANY'
solve(a,b)
## S4 method for signature 'gpu.matrix.tensorflow,missing'
solve(a)
## S4 method for signature 'gpu.matrix.torch,ANY'
solve(a,b)
## S4 method for signature 'gpu.matrix.torch,missing'
solve(a)

## S4 method for signature 'gpu.matrix.torch'
ginv(X,tol)
## S4 method for signature 'gpu.matrix.tensorflow'
ginv(X,tol)

## S4 method for signature 'ANY,gpu.matrix.torch'
chol_solve(x,y)
## S4 method for signature 'ANY,gpu.matrix.tensorflow'
chol_solve(x,y)
## S4 method for signature 'gpu.matrix.torch,ANY'
chol_solve(x,y)
## S4 method for signature 'gpu.matrix.tensorflow,ANY'
chol_solve(x,y)


Arguments

These inputs correspond to the solve function:

a

a square numeric or complex gpu.matrix containing the coefficients of the linear system.

b

a numeric or complex vector or matrix giving the right-hand side(s) of the linear system. If b missing, solve will return the inverse of a.

These inputs correspond to the chol_solve function:

x

Given the equation Ax=b, x must be the transponsed of the cholesky decomposition of matrix A if A is a real symmetric positive-definite square matrix.

y

a numeric or complex vector or matrix giving the right-hand side(s) of the linear system.

These inputs correspond to the ginv function:

X

Matrix for which the Moore-Penrose inverse is required.

tol

A relative tolerance to detect zero singular values.

Details

The functions solve, and ginv internally calls the corresponding function of the library torch or tensorflow (depending on the type of input gpu.matrix-class).

If the input gpu.matrix-class object(s) are stored on the GPU, then the operations will be performed on the GPU. See gpu.matrix.

Value

The result of these functions is an object of the class gpu.matrix.

See Also

See also solve, ginv, torch_inverse, and torch_pinverse.

For cholesky decomposition see chol from base or matrix_decomposition from GPUmatrix.

Also see qr.solve.

Examples


## Not run: 

#solve a system of equations:
a <- gpu.matrix(rnorm(9),nrow=3,ncol=3)
b <- c(1,1,1)
betas <- solve(a,b)
a %*% betas

#the inverse matrix
inv <- solve(a)
a %*% inv

#inverse using ginv
inv_2 <- ginv(a)
a %*% inv_2


#chol_solve: it can be applies only if
# in the equation Ax=b A is real symmetric positive-definite square matrix.
a <- gpu.matrix(rnorm(9),3,3)
A <- tcrossprod(a) #A is symmetrix positive-definite
b <- gpu.matrix(rnorm(3))

x_solve <- solve(A,b) #using solve to compare results
x_chol_solve <- chol_solve(t(chol(A)),b) #using chol_solve
#NOTE: notice that the input for chol_solve is the Cholesky decomposition
# of matrix A.


## End(Not run)


[Package GPUmatrix version 1.0.2 Index]