Creates a torch tensor.

tensor(x, ...)

Arguments

x

an R object or a torch tensor.

dtype

the desired data type of returned tensor. Default: if NULL, infers data type from x.

device

the desired device of returned tensor. Default: if NULL, uses the current device for the default tensor type (see tch_set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

requires_grad

If autograd should record operations on the returned tensor. Default: FALSE.

Examples

x <- tensor(1:10) x
#> tensor #> 1 #> 2 #> 3 #> 4 #> 5 #> 6 #> 7 #> 8 #> 9 #> 10 #> [ Variable[CPUIntType]{10} ]
y <- tensor(x, dtype = "double") y
#> tensor #> 1 #> 2 #> 3 #> 4 #> 5 #> 6 #> 7 #> 8 #> 9 #> 10 #> [ Variable[CPUDoubleType]{10} ]