MCPcopy Create free account
hub / github.com/apache/arrow / test_tensor_memoryview

Function test_tensor_memoryview

python/pyarrow/tests/test_tensor.py:204–226  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202
203
204def test_tensor_memoryview():
205 # Tensors support the PEP 3118 buffer protocol
206 for dtype, expected_format in [(np.int8, '=b'),
207 (np.int64, '=q'),
208 (np.uint64, '=Q'),
209 (np.float16, 'e'),
210 (np.float64, 'd'),
211 ]:
212 data = np.arange(10, dtype=dtype)
213 dtype = data.dtype
214 lst = data.tolist()
215 tensor = pa.Tensor.from_numpy(data)
216 m = memoryview(tensor)
217 assert m.format == expected_format
218 assert m.shape == data.shape
219 assert m.strides == data.strides
220 assert m.ndim == 1
221 assert m.nbytes == data.nbytes
222 assert m.itemsize == data.itemsize
223 assert m.itemsize * 8 == tensor.type.bit_width
224 assert np.frombuffer(m, dtype).tolist() == lst
225 del tensor, data
226 assert np.frombuffer(m, dtype).tolist() == lst

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected