backend.utils

Utility functions for working with different backends.

To add support for a new backend, add a conversion function to the CONVERTERS list.

Kramer Harrison, 2024

Functions

is_torch_tensor(obj)

Checks if an object is a PyTorch tensor.

to_numpy(obj)

Converts input scalar or array to NumPy array, regardless of backend.

torch_to_numpy(obj)

is_torch_tensor(obj) bool[source]

Checks if an object is a PyTorch tensor.

Parameters:

obj – The object to check.

Returns:

True if the object is a PyTorch tensor, False otherwise.

Return type:

bool

to_numpy(obj: ScalarOrArrayT) NDArray[source]

Converts input scalar or array to NumPy array, regardless of backend.

torch_to_numpy(obj: Tensor) NDArray[source]