dpnp.from_dlpack

dpnp.from_dlpack(obj, /, *, device=None, copy=None)[source]

Create a dpnp array from a Python object implementing the __dlpack__ protocol.

See https://dmlc.github.io/dlpack/latest/ for more details.

Parameters:
  • obj (object) -- A Python object representing an array that implements the __dlpack__ and __dlpack_device__ methods.

  • device ({dpctl.SyclDevice, dpctl.SyclQueue,) -- dpctl.tensor.Device, tuple, None}, optional Array API concept of a device where the output array is to be placed. device can be None, an oneAPI filter selector string, an instance of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, a dpctl.tensor.Device object returned by dpctl.tensor.usm_ndarray.device, or a 2-tuple matching the format of the output of the __dlpack_device__ method, an integer enumerator representing the device type followed by an integer representing the index of the device. Default: None.

  • {bool (copy) --

    Boolean indicating whether or not to copy the input.

    • If copy``is ``True`, the input will always be copied.

    • If False, a BufferError will be raised if a copy is deemed necessary.

    • If None, a copy will be made only if deemed necessary, otherwise, the existing memory buffer will be reused.

    Default: None.

  • None} --

    Boolean indicating whether or not to copy the input.

    • If copy``is ``True`, the input will always be copied.

    • If False, a BufferError will be raised if a copy is deemed necessary.

    • If None, a copy will be made only if deemed necessary, otherwise, the existing memory buffer will be reused.

    Default: None.

  • optional --

    Boolean indicating whether or not to copy the input.

    • If copy``is ``True`, the input will always be copied.

    • If False, a BufferError will be raised if a copy is deemed necessary.

    • If None, a copy will be made only if deemed necessary, otherwise, the existing memory buffer will be reused.

    Default: None.

Returns:

out -- Returns a new dpnp array containing the data from another array (obj) with the __dlpack__ method on the same device as object.

Return type:

dpnp_array

Raises:
  • TypeError: -- if obj does not implement __dlpack__ method

  • ValueError: -- if the input array resides on an unsupported device