Загрузка
Creates a 1-dimensional Tensor from an object that implements
the Python buffer protocol.
Skips the first offset bytes in the buffer, and interprets the rest of
the raw bytes as a 1-dimensional tensor of type dtype with count
elements.
Note that either of the following must be true:
1. count is a positive non-zero number, and the total number of bytes
in the buffer is more than offset plus count times the size
(in bytes) of dtype.
2. count is negative, and the length (number of bytes) of the buffer
subtracted by the offset is a multiple of the size (in bytes) of
dtype.
The returned tensor and buffer share the same memory. Modifications to the tensor will be reflected in the buffer and vice versa. The returned tensor is not resizable.
buffer (object) – a Python object that exposes the buffer interface.
dtype (torch.dtype) – the desired data type of returned tensor.
count (int, optional) – the number of desired elements to be read. If negative, all the elements (until the end of the buffer) will be read. Default: -1.
offset (int, optional) – the number of bytes to skip at the start of the buffer. Default: 0.
Example:
>>> import array
>>> a = array.array('i', [1, 2, 3])
>>> t = torch.frombuffer(a, dtype=torch.int32)
>>> t
requires_grad (bool, optional) – If autograd should record operations on the
returned tensor. Default: False.