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:
  • buffer (buffer_like) -- An object that exposes the buffer interface.

  • dtype (data-type, 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}, 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 of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a Device object returned by dpnp.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 -- A 1-dimensional array created from input buffer object.

Return type:

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.fromfile

Construct array from data in a text or binary file.

dpnp.fromiter

Construct array from an iterable object.

dpnp.fromstring

Construct array from the text data in a string.

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')