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:
aarray_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, str, dtype object}, 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).

Default: None.

device{None, string, SyclDevice, SyclQueue, Device}, optional

An array API concept of device where the output array is created. device can be None, a oneAPI filter selector string, an instance of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a dpnp.tensor.Device object returned by dpnp.ndarray.device.

Default: None.

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:
outdpnp.ndarray

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

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