dpnp.require

dpnp.require(a, dtype=None, requirements=None, *, like=None)[source]

Return a dpnp.ndarray of the provided type that satisfies requirements.

This function is useful to be sure that an array with the correct flags is returned for passing to compiled code (perhaps through ctypes).

For full documentation refer to numpy.require.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- The input array to be converted to a type-and-requirement-satisfying array.

  • dtype ({None, data-type}, optional) -- The required data-type. If None preserve the current dtype.

  • requirements ({None, str, sequence of str}, optional) --

    The requirements list can be any of the following:

    • 'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array

    • 'C_CONTIGUOUS' ('C') - ensure a C-contiguous array

    • 'WRITABLE' ('W') - ensure a writable array

Returns:

out -- Array with specified requirements and type if given.

Return type:

dpnp.ndarray

Limitations

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

See also

dpnp.asarray

Convert input to an ndarray.

dpnp.asanyarray

Convert to an ndarray, but pass through ndarray subclasses.

dpnp.ascontiguousarray

Convert input to a contiguous array.

dpnp.asfortranarray

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

dpnp.ndarray.flags

Information about the memory layout of the array.

Notes

The returned array will be guaranteed to have the listed requirements by making a copy if needed.

Examples

>>> import dpnp as np
>>> x = np.arange(6).reshape(2, 3)
>>> x.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  WRITEABLE : True
>>> y = np.require(x, dtype=np.float32, requirements=['W', 'F'])
>>> y.flags
  C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  WRITEABLE : True