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:
iter (iterable object) -- An iterable object providing data for the array.
dtype (data-type) -- The data-type of the returned array.
count (int, optional) -- The number of items to read from iterable. The default is -1, which means all data is read.
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 ofdpctl.SyclDevice
corresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue
, or a Device object returned bydpnp.dpnp_array.dpnp_array.device
property.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:
out -- The output array.
- Return type:
dpnp.ndarray
Limitations
Parameter like is supported only with default value
None
. Otherwise, the function raisesNotImplementedError
exception.Notes
This uses
numpy.fromiter
and coerces the result to a DPNP array.See also
dpnp.frombuffer
Construct array from the buffer data.
dpnp.fromfile
Construct array from data in a text or binary file.
dpnp.fromstring
Construct array from the text data in a string.
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')