get_array_and_backend

odl.get_array_and_backend(x, must_be_contiguous=False)

Convenience function for getting an ArrayBackend from an array-like argument.

Parameters

xArray-Like.

It can be a np.ndarray, a torch.Tensor, an ODL Tensor or a ProductSpaceElement. Object to return the ArrayBackend and actual underlying array from.

must_be_contiguousbool

Boolean flag to indicate whether or not to make the array contiguous.

Returns

xactual array

-> unwrapped from the LinearSpaceElement -> returned as is if it was already an array.

backend : ODL ArrayBackend object

Examples

>>> array, backend = get_array_and_backend(np.zeros(2))
>>> array
array([ 0.,  0.])
>>> backend
ArrayBackend(impl=numpy)
>>> array, backend = get_array_and_backend([1,2,3])
Traceback (most recent call last):
ValueError: f"The registered array backends are ['numpy']. The argument provided is a list, check that the backend you want to use is supported and has been correctly instanciated."