dpnp.copy

dpnp.copy(a, order='K', subok=False, device=None, usm_type=None, sycl_queue=None)[source]

Return an array copy of the given object.

For full documentation refer to numpy.copy.

Parameters:
  • a (array_like) -- Input data, in any form that can be converted to an array. This includes scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists, and ndarrays.

  • order ({"C", "F", "A", "K"}, optional) -- Memory layout of the newly output array. Default: "K".

  • device ({None, string, SyclDevice, SyclQueue}, optional) -- An array API concept of device where the output array is created. The device can be None (the default), an OneAPI filter selector string, an instance of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a Device object returned by dpnp.dpnp_array.dpnp_array.device property.

  • usm_type ({None, "device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array. Default is None.

  • sycl_queue ({None, SyclQueue}, optional) -- A SYCL queue to use for output array allocation and copying.

Limitations

Parameter subok is supported only with default value False. Otherwise, the function raises NotImplementedError exception.

Returns:

out -- Array interpretation of a.

Return type:

dpnp.ndarray

See also

dpnp.ndarray.copy

Preferred method for creating an array copy

Notes

This is equivalent to:

>>> dpnp.array(a, copy=True)

Examples

Create an array x, with a reference y and a copy z:

>>> import dpnp as np
>>> x = np.array([1, 2, 3])
>>> y = x
>>> z = np.copy(x)

Note that, when we modify x, y will change, but not z:

>>> x[0] = 10
>>> x[0] == y[0]
array(True)
>>> x[0] == z[0]
array(False)

Creating an array on a different device or with a specified usm_type

>>> x0 = np.array([1, 2, 3])
>>> x = np.copy(x0) # default case
>>> x, x.device, x.usm_type
(array([1, 2, 3]), Device(level_zero:gpu:0), 'device')
>>> y = np.copy(x0, device="cpu")
>>> y, y.device, y.usm_type
(array([1, 2, 3]), Device(opencl:cpu:0), 'device')
>>> z = np.copy(x0, usm_type="host")
>>> z, z.device, z.usm_type
(array([1, 2, 3]), Device(level_zero:gpu:0), 'host')