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

Function test_tensor_from_dlpack

python/pyarrow/tests/test_dlpack.py:385–397  ·  view source on GitHub ↗
(np_type)

Source from the content-addressed store, hash-verified

383 np.int8, np.int16, np.int32, np.int64,
384 np.float16, np.float32, np.float64])
385def 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")

Callers

nothing calls this directly

Calls 1

make_arrayFunction · 0.85

Tested by

no test coverage detected