diag {GPUmatrix}R Documentation

diag

Description

This function mimics the base function 'diag' to operate on gpu.matrix-class objects: "extract or replace the diagonal of a matrix, or constructs a diagonal matrix."

Usage


## S4 method for signature 'gpu.matrix.tensorflow'
diag(x)
## S4 method for signature 'gpu.matrix.torch'
diag(x)
## S4 replacement method for signature 'gpu.matrix.tensorflow,numeric'
diag(x) <- value
## S4 replacement method for signature 'gpu.matrix.torch,numeric'
diag(x) <- value

Arguments

x

a gpu.matrix.

value

either a single value or a vector of length equal to that of the current diagonal.

Value

Output corresponding to the base function diag: If input x is a gpu.matrix-class object then diag{x} returns a numeric object with the diagonal of the matrix x (this output is not a gpu.matrix-class object).

The replacement form diag(x) <- value sets the diagonal of the matrix x to the given value(s).

See Also

For more information see: diag

Examples


if(installTorch()){

  a <- gpu.matrix(rnorm(9),nrow=3,ncol=3)

  diag(a) #shows the diagonal of matrix a

  diag(a) <- c(10,0,100) #set the diagonal of matrix a
  a

}






[Package GPUmatrix version 1.0.2 Index]