| 184 | |
| 185 | |
| 186 | def 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 | |
| 204 | def test_tensor_memoryview(): |