dpnp.frombuffer¶
- dpnp.frombuffer(buffer, dtype=<class 'float'>, count=-1, offset=0, *, like=None, device=None, usm_type='device', sycl_queue=None)[source]¶
Interpret a buffer as a 1-dimensional array.
For full documentation refer to
numpy.frombuffer.- Parameters:
- bufferbuffer_like
An object that exposes the buffer interface.
- dtype{None, str, dtype object}, optional
Data-type of the returned array. If
None, uses a default floating point data type for the device on which the returned array is allocated.Default:
float.- countint, optional
Number of items to read.
-1means all data in the buffer.Default:
-1.- offsetint, optional
Start reading the buffer from this offset (in bytes).
Default:
0.- 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
A 1-dimensional array created from input buffer object.
Limitations
Parameter like is supported only with default value
None. Otherwise, the function raisesNotImplementedErrorexception.See also
dpnp.fromfileConstruct array from data in a text or binary file.
dpnp.fromiterConstruct array from an iterable object.
dpnp.fromstringConstruct array from the text data in a string.
ndarray.tobytesConstruct Python bytes from the raw data bytes in the array.
Notes
This uses
numpy.frombufferand coerces the result to a DPNP array.Examples
>>> import dpnp as np >>> s = b'\x01\x02\x03\x04' >>> np.frombuffer(s, dtype=np.int32) array([67305985], dtype=int32) >>> np.frombuffer(b'\x01\x02\x03\x04\x05', dtype='u1', count=3) array([1, 2, 3], dtype=uint8)
Creating an array on a different device or with a specified usm_type
>>> x = np.frombuffer(s, dtype=np.int32) # default case >>> x.device, x.usm_type (Device(level_zero:gpu:0), 'device')
>>> y = np.frombuffer(s, dtype=np.int32, device='cpu') >>> y.device, y.usm_type (Device(opencl:cpu:0), 'device')
>>> z = np.frombuffer(s, dtype=np.int32, usm_type="host") >>> z.device, z.usm_type (Device(level_zero:gpu:0), 'host')