Interpret a buffer as a 1-dimensional array.
For full documentation refer to numpy.frombuffer.
buffer (buffer_like) -- An object that exposes the buffer interface.
dtype ({None, str, dtype object}, optional) -- Data-type of the returned array. Default is the default floating point data type for the device where the returned array is allocated.
count (int, optional) -- Number of items to read. -1 means all data in the buffer.
offset (int, 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
of dpctl.SyclDevice corresponding to a non-partitioned SYCL
device, an instance of dpctl.SyclQueue, or a
dpctl.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.
out -- A 1-dimensional array created from input buffer object.
dpnp.ndarray
Limitations
Parameter like is supported only with default value None.
Otherwise, the function raises NotImplementedError exception.
Notes
This uses numpy.frombuffer and coerces the result to a DPNP array.
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.
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')