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

Function test_dlpack_copy_is_writeable

python/pyarrow/tests/test_dlpack.py:319–331  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

317@requires_numpy_version("2.2.5")
318@check_bytes_allocated
319def test_dlpack_copy_is_writeable():
320 # NumPy did not set the writeable flag on DLPack imports before 2.2.5.
321 arr = pa.array([1, 2, 3], type=pa.int32())
322
323 # Arrow arrays are immutable, so a shared export is read-only
324 shared = np.from_dlpack(DLPackForwarder(arr, max_version=(1, 3)))
325 assert not shared.flags.writeable
326
327 # A copy is solely owned by the consumer, who may mutate it
328 copied = np.from_dlpack(DLPackForwarder(arr, max_version=(1, 3), copy=True))
329 assert copied.flags.writeable
330 copied[0] = 100
331 assert arr.to_pylist() == [1, 2, 3]
332
333
334def test_dlpack_not_supported():

Callers

nothing calls this directly

Calls 2

DLPackForwarderClass · 0.85
arrayMethod · 0.45

Tested by

no test coverage detected