unilab.utils.tensor

Generic array <-> torch conversion utilities.

Functions

to_numpy(x)

Convert torch tensor or numpy-like input to numpy.

to_torch(x, device)

Convert numpy-like input to torch on the target device.

unilab.utils.tensor.to_torch(x, device)[source]

Convert numpy-like input to torch on the target device.

Supports torch tensors, numpy arrays, and any array exposing __dlpack__.

Parameters:

device (str | device)

Return type:

Tensor

unilab.utils.tensor.to_numpy(x)[source]

Convert torch tensor or numpy-like input to numpy.

Return type:

ndarray