torch_tensor: Converts R objects to a torch tensor

View source: R/tensor.R

torch_tensorR Documentation

Converts R objects to a torch tensor

Description

Converts R objects to a torch tensor

Usage

torch_tensor(
  data,
  dtype = NULL,
  device = NULL,
  requires_grad = FALSE,
  pin_memory = FALSE
)

Arguments

data

an R atomic vector, matrix or array

dtype

a torch_dtype instance

device

a device creted with torch_device()

requires_grad

if autograd should record operations on the returned tensor.

pin_memory

If set, returned tensor would be allocated in the pinned memory.

Examples

if (torch_is_installed()) {
torch_tensor(c(1, 2, 3, 4))
torch_tensor(c(1, 2, 3, 4), dtype = torch_int())
}

torch documentation built on Jan. 24, 2023, 1:05 a.m.