dpnp.asanyarray

dpnp.asanyarray(a, dtype=None, order=None, *, like=None, device=None, usm_type=None, sycl_queue=None)[source]

Convert the input to an dpnp.ndarray.

For full documentation refer to numpy.asanyarray.

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.

  • dtype ({None, dtype}, optional) -- The desired dtype for the array. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary).

  • 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.

Returns:

out -- Array interpretation of a.

Return type:

dpnp.ndarray

Limitations

Parameter like is supported only with default value None. Otherwise, the function raises NotImplementedError exception.

See also

dpnp.asarray

Similar function which always returns ndarrays.

dpnp.ascontiguousarray

Convert input to a contiguous array.

dpnp.asfarray

Convert input to a floating point ndarray.

dpnp.asfortranarray

Convert input to an ndarray with column-major memory order.

dpnp.asarray_chkfinite

Similar function which checks input for NaNs and Infs.

dpnp.fromiter

Create an array from an iterator.

dpnp.fromfunction

Construct an array by executing a function on grid positions.

Examples

>>> import dpnp as np
>>> np.asanyarray([1, 2, 3])
array([1, 2, 3])

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

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