create

Create tensors from other array-like data, and change device and type.

class AsTensor(dtype=None, device=None)[source]

Bases: ArgRepr

Partial of the top-level PyTorch function as_tensor.

Parameters:
  • dtype (dtype, optional) – Torch dtype of the tensor to create. Defaults to None

  • device (device, optional) – Torch device to create the tensor on. Defaults to None

__call__(data)[source]

Create a PyTorch tensor with the cached (keyword) arguments.

Parameters:

data – Any type of data a PyTorch tensor can be created from.

Returns:

A PyTorch tensor sharing the memory with data.

Return type:

Tensor

class Create(dtype=None, device=None, requires_grad=False, pin_memory=False)[source]

Bases: ArgRepr

Partial of the top-level PyTorch function tensor.

Parameters:
  • dtype (dtype, optional) – Torch dtype of the tensor to create. Defaults to None

  • device (device, optional) – Torch device to create the tensor on. Defaults to None

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Defaults to False.

  • pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Defaults to False.

__call__(data)[source]

Create a PyTorch tensor with the cached (keyword) arguments.

Parameters:

data – Any type of data a PyTorch tensor can be created from.

Returns:

A PyTorch tensor.

Return type:

Tensor

class To(target, *args, **kwargs)[source]

Bases: ArgRepr

Move or change a tensor or module to a different device or dtype.

Refer to the PyTorch documentation for more information.

Parameters:
  • target (device or dtype) – The device or dtype to move the tensor or module to.

  • *args – Additional argument to pass to the to method.

  • **kwargs – Additional keyword arguments to pass to the to method.

__call__(inp)[source]

Move or change a tensor or module to the specified target.

Parameters:

inp (Tensor or Module) – The input tensor or module to move or change to the target.

Returns:

The inp moved or changed to the cached target.

Return type:

Tensor or Module

from_dataframe(df)[source]

Convert a pandas dataframe to a PyTorch tensor.

This is simply wrapper around the top-level PyTorch function from_numpy function called on the dataframe’s values attribute.

Parameters:

df (DataFrame) – The pandas dataframe to convert.

Returns:

A PyTorch tensor sharing the memory with the dataframe’s data.

Return type:

Tensor