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

Function test_non_cpu_array

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

Source from the content-addressed store, hash-verified

4376
4377
4378def test_non_cpu_array():
4379 cuda = pytest.importorskip("pyarrow.cuda", exc_type=ImportError)
4380 ctx = cuda.Context(0)
4381
4382 data = np.arange(4, dtype=np.int32)
4383 validity = np.array([True, False, True, False], dtype=np.bool_)
4384 cuda_data_buf = ctx.buffer_from_data(data)
4385 cuda_validity_buf = ctx.buffer_from_data(validity)
4386 arr = pa.Array.from_buffers(pa.int32(), 4, [None, cuda_data_buf])
4387 arr2 = pa.Array.from_buffers(pa.int32(), 4, [None, cuda_data_buf])
4388 arr_with_nulls = pa.Array.from_buffers(
4389 pa.int32(), 4, [cuda_validity_buf, cuda_data_buf])
4390
4391 # Supported
4392 arr.validate()
4393 assert arr.offset == 0
4394 assert arr.buffers() == [None, cuda_data_buf]
4395 assert arr.device_type == pa.DeviceAllocationType.CUDA
4396 assert arr.is_cpu is False
4397 assert len(arr) == 4
4398 assert arr.slice(2, 2).offset == 2
4399 assert repr(arr)
4400 assert str(arr)
4401
4402 # TODO support DLPack for CUDA
4403 with pytest.raises(NotImplementedError):
4404 arr.__dlpack__()
4405 with pytest.raises(NotImplementedError):
4406 arr.__dlpack_device__()
4407
4408 # Not Supported
4409 with pytest.raises(NotImplementedError):
4410 arr.diff(arr2)
4411 with pytest.raises(NotImplementedError):
4412 arr.cast(pa.int64())
4413 with pytest.raises(NotImplementedError):
4414 arr.view(pa.int64())
4415 with pytest.raises(NotImplementedError):
4416 arr.sum()
4417 with pytest.raises(NotImplementedError):
4418 arr.unique()
4419 with pytest.raises(NotImplementedError):
4420 arr.dictionary_encode()
4421 with pytest.raises(NotImplementedError):
4422 arr.value_counts()
4423 with pytest.raises(NotImplementedError):
4424 arr_with_nulls.null_count
4425 with pytest.raises(NotImplementedError):
4426 arr.nbytes
4427 with pytest.raises(NotImplementedError):
4428 arr.get_total_buffer_size()
4429 with pytest.raises(NotImplementedError):
4430 [i for i in iter(arr)]
4431 with pytest.raises(NotImplementedError):
4432 arr == arr2
4433 with pytest.raises(NotImplementedError):
4434 arr.is_null()
4435 with pytest.raises(NotImplementedError):

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected