dpnp.empty

dpnp.empty(shape, *, dtype=None, order='C', like=None, device=None, usm_type='device', sycl_queue=None)[source]

Return a new array of given shape and type, without initializing entries.

For full documentation refer to numpy.empty.

Parameters:
shape{int, sequence of ints}

Shape of the new array, e.g., (2, 3) or 2.

dtype{None, str, dtype object}, optional

The desired dtype for the array, e.g., dpnp.int32. If None, uses a default floating point data type for the device on which the input array is allocated.

Default: None.

order{None, "C", "F"}, optional

Memory layout of the newly output array.

Default: "C".

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: "device".

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

Array of uninitialized data of the given shape, dtype, and order.

Limitations

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

See also

dpnp.empty_like

Return an empty array with shape and type of input.

dpnp.ones

Return a new array setting values to one.

dpnp.zeros

Return a new array setting values to zero.

dpnp.full

Return a new array of given shape filled with value.

Examples

>>> import dpnp as np
>>> np.empty(4)
array([9.03088525e-312, 9.03088525e-312, 9.03088525e-312, 9.03088525e-312])

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

>>> x = np.empty((3, 3)) # default case
>>> x.shape, x.device, x.usm_type
((3, 3), Device(level_zero:gpu:0), 'device')
>>> y = np.empty((3, 3), device="cpu")
>>> y.shape, y.device, y.usm_type
((3, 3), Device(opencl:cpu:0), 'device')
>>> z = np.empty((3, 3), usm_type="host")
>>> z.shape, z.device, z.usm_type
((3, 3), Device(level_zero:gpu:0), 'host')