dpnp.ascontiguousarray

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

Return a contiguous array (ndim >= 1) in memory (C order).

For full documentation refer to numpy.ascontiguousarray.

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

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

  • sycl_queue ({None, SyclQueue}, optional) -- A SYCL queue to use for output array allocation and copying. The sycl_queue can be passed as None (the default), which means to get the SYCL queue from device keyword if present or to use a default queue. Default: None.

Returns:

out -- Contiguous array of same shape and content as a, with type dtype if specified.

Return type:

dpnp.ndarray

Limitations

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

See also

dpnp.asfortranarray

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

dpnp.require

Return an ndarray that satisfies requirements.

dpnp.ndarray.flags

Information about the memory layout of the array.

Examples

>>> import dpnp as np
>>> x = np.ones((2, 3), order='F')
>>> x.flags['F_CONTIGUOUS']
True

Calling ascontiguousarray makes a C-contiguous copy:

>>> y = np.ascontiguousarray(x)
>>> y.flags['F_CONTIGUOUS']
True
>>> x is y
False

Now, starting with a C-contiguous array:

>>> x = np.ones((2, 3), order='C')
>>> x.flags['C_CONTIGUOUS']
True

Then, calling ascontiguousarray returns the same object:

>>> y = np.ascontiguousarray(x)
>>> x is y
True

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

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