{ } Raw JSON

bundles / scipy 1.17.1 / scipy / _lib / array_api_compat / common / _helpers / to_device

function

scipy._lib.array_api_compat.common._helpers:to_device

source: /scipy/_lib/array_api_compat/common/_helpers.py :836

Signature

def   to_device ( x : Array device : Device / stream : int | Any | None = None )  →  Array

Summary

Copy the array from the device on which it currently resides to the specified device.

Extended Summary

This is equivalent to x.to_device(device, stream=stream) according to the standard. This helper is included because some array libraries do not have the to_device method.

Parameters

x: array

array instance from an array API compatible library.

device: device

a device object (see the Device Support section of the array API specification).

stream: int | Any | None

stream object to use during copy. In addition to the types supported in array.__dlpack__, implementations may choose to support any library-specific stream object with the caveat that any code using such an object would not be portable.

Returns

: out: array

an array with the same data and data type as x and located on the specified device.

Notes

For NumPy, this function effectively does nothing since the only supported device is the CPU. For CuPy, this method supports CuPy CUDA Device <cupy.cuda.Device> and Stream <cupy.cuda.Stream> objects. For PyTorch, this is the same as x.to(device) <torch.Tensor.to> (the stream argument is not supported in PyTorch).

See also

device

Hardware device the array data resides on.

Aliases

  • scipy.differentiate.xpx._delegation._funcs._compat.to_device