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

Function test_non_cpu_array

python/pyarrow/tests/test_array.py:4561–4643  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4559
4560
4561def test_non_cpu_array():
4562 cuda = pytest.importorskip("pyarrow.cuda", exc_type=ImportError)
4563 ctx = cuda.Context(0)
4564
4565 data = np.arange(4, dtype=np.int32)
4566 validity = np.array([True, False, True, False], dtype=np.bool)
4567 cuda_data_buf = ctx.buffer_from_data(data)
4568 cuda_validity_buf = ctx.buffer_from_data(validity)
4569 arr = pa.Array.from_buffers(pa.int32(), 4, [None, cuda_data_buf])
4570 arr2 = pa.Array.from_buffers(pa.int32(), 4, [None, cuda_data_buf])
4571 arr_with_nulls = pa.Array.from_buffers(
4572 pa.int32(), 4, [cuda_validity_buf, cuda_data_buf])
4573
4574 # Supported
4575 arr.validate()
4576 assert arr.offset == 0
4577 assert arr.buffers() == [None, cuda_data_buf]
4578 assert arr.device_type == pa.DeviceAllocationType.CUDA
4579 assert arr.is_cpu is False
4580 assert len(arr) == 4
4581 assert arr.slice(2, 2).offset == 2
4582 assert repr(arr)
4583 assert str(arr)
4584
4585 # TODO support DLPack for CUDA
4586 with pytest.raises(NotImplementedError):
4587 arr.__dlpack__()
4588 with pytest.raises(NotImplementedError):
4589 arr.__dlpack_device__()
4590
4591 # Not Supported
4592 with pytest.raises(NotImplementedError):
4593 arr.diff(arr2)
4594 with pytest.raises(NotImplementedError):
4595 arr.cast(pa.int64())
4596 with pytest.raises(NotImplementedError):
4597 arr.view(pa.int64())
4598 with pytest.raises(NotImplementedError):
4599 arr.sum()
4600 with pytest.raises(NotImplementedError):
4601 arr.unique()
4602 with pytest.raises(NotImplementedError):
4603 arr.dictionary_encode()
4604 with pytest.raises(NotImplementedError):
4605 arr.value_counts()
4606 with pytest.raises(NotImplementedError):
4607 arr_with_nulls.null_count
4608 with pytest.raises(NotImplementedError):
4609 arr.nbytes
4610 with pytest.raises(NotImplementedError):
4611 arr.get_total_buffer_size()
4612 with pytest.raises(NotImplementedError):
4613 [i for i in iter(arr)]
4614 with pytest.raises(NotImplementedError):
4615 arr == arr2
4616 with pytest.raises(NotImplementedError):
4617 arr.is_null()
4618 with pytest.raises(NotImplementedError):

Callers

nothing calls this directly

Calls 15

lenFunction · 0.85
buffersMethod · 0.80
is_nullMethod · 0.80
filterMethod · 0.80
arrayMethod · 0.45
validateMethod · 0.45
sliceMethod · 0.45
__dlpack__Method · 0.45
__dlpack_device__Method · 0.45
castMethod · 0.45
viewMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected