dpnp.fromiter¶
- dpnp.fromiter(iter, dtype, count=-1, *, like=None, device=None, usm_type='device', sycl_queue=None)[source]¶
Create a new 1-dimensional array from an iterable object.
For full documentation refer to
numpy.fromiter.- Parameters:
- iteriterable object
An iterable object providing data for the array.
- dtype{None, str, dtype object}
The data-type of the returned array.
- countint, optional
The number of items to read from iterable. The default is -1, which means all data is read.
Default:
-1.- 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 ofdpctl.SyclDevicecorresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue, or adpnp.tensor.Deviceobject returned bydpnp.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
The output array.
Limitations
Parameter like is supported only with default value
None. Otherwise, the function raisesNotImplementedErrorexception.See also
dpnp.frombufferConstruct array from the buffer data.
dpnp.fromfileConstruct array from data in a text or binary file.
dpnp.fromstringConstruct array from the text data in a string.
Notes
This uses
numpy.fromiterand coerces the result to a DPNP array.Examples
>>> import dpnp as np >>> iterable = (a * a for a in range(5)) >>> np.fromiter(iterable, float) array([ 0., 1., 4., 9., 16.])
Creating an array on a different device or with a specified usm_type
>>> x = np.fromiter(iterable, np.int32) # default case >>> x.device, x.usm_type (Device(level_zero:gpu:0), 'device')
>>> y = np.fromiter(iterable, np.int32, device='cpu') >>> y.device, y.usm_type (Device(opencl:cpu:0), 'device')
>>> z = np.fromiter(iterable, np.int32, usm_type="host") >>> z.device, z.usm_type (Device(level_zero:gpu:0), 'host')