Create torch Tensor from R object

tensor_from_r(x, dtype = NULL, device = NULL, requires_grad = FALSE)

Arguments

x

an R vector, matrix or array.

dtype

dtype

device

device

requires_grad

requires_grad

Note

it uses the R type when creating the tensor.

Examples

tensor_from_r(1:10)
#> tensor #> 1 #> 2 #> 3 #> 4 #> 5 #> 6 #> 7 #> 8 #> 9 #> 10 #> [ Variable[CPUIntType]{10} ]
tensor_from_r(array(runif(8), dim = c(2, 2, 2)))
#> tensor #> (1,.,.) = #> 0.0110 0.9199 #> 0.6219 0.9158 #> #> (2,.,.) = #> 0.7833 0.3254 #> 0.8661 0.0805 #> [ Variable[CPUFloatType]{2,2,2} ]
tensor_from_r(matrix(c(TRUE, FALSE), nrow = 3, ncol = 4))
#> tensor #> 1 0 1 0 #> 0 1 0 1 #> 1 0 1 0 #> [ Variable[CPUByteType]{3,4} ]