(np_type)
| 383 | np.int8, np.int16, np.int32, np.int64, |
| 384 | np.float16, np.float32, np.float64]) |
| 385 | def test_tensor_from_dlpack(np_type): |
| 386 | def make_array(): |
| 387 | base = np.arange(24, dtype=np_type).reshape((4, 6)) |
| 388 | array = base[::2, 1::2] |
| 389 | assert not array.flags['C_CONTIGUOUS'] |
| 390 | return array |
| 391 | |
| 392 | # Non-contiguous, strided slice: DLPack carries explicit strides, so this |
| 393 | # should not need a copy on export. |
| 394 | tensor = pa.Tensor.from_dlpack(make_array()) |
| 395 | assert isinstance(tensor, pa.Tensor) |
| 396 | gc.collect() # Attempts to free input array memory |
| 397 | np.testing.assert_array_equal(tensor.to_numpy(), make_array(), strict=True) |
| 398 | |
| 399 | |
| 400 | @requires_numpy_version("2.1.0") |
nothing calls this directly
no test coverage detected