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

Function test_read_tensor

python/pyarrow/tests/test_tensor.py:186–201  ·  view source on GitHub ↗
(tmpdir)

Source from the content-addressed store, hash-verified

184
185
186def test_read_tensor(tmpdir):
187 # Create and write tensor tensor
188 data = np.random.randn(10, 4)
189 tensor = pa.Tensor.from_numpy(data)
190 data_size = pa.ipc.get_tensor_size(tensor)
191 path = os.path.join(str(tmpdir), 'pyarrow-tensor-ipc-read-tensor')
192 write_mmap = pa.create_memory_map(path, data_size)
193 pa.ipc.write_tensor(tensor, write_mmap)
194 if sys.platform == 'emscripten':
195 # emscripten doesn't support multiple
196 # memory maps to same file
197 write_mmap.close()
198 # Try to read tensor
199 read_mmap = pa.memory_map(path, mode='r')
200 array = pa.ipc.read_tensor(read_mmap).to_numpy()
201 np.testing.assert_equal(data, array)
202
203
204def test_tensor_memoryview():

Callers

nothing calls this directly

Calls 2

joinMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected