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

Function test_HostBuffer

python/pyarrow/tests/test_cuda.py:338–361  ·  view source on GitHub ↗
(size)

Source from the content-addressed store, hash-verified

336
337@pytest.mark.parametrize("size", [0, 1, 1000])
338def test_HostBuffer(size):
339 arr, buf = make_random_buffer(size)
340 assert arr.tobytes() == buf.to_pybytes()
341 hbuf = cuda.new_host_buffer(size)
342 np.frombuffer(hbuf, dtype=np.uint8)[:] = arr
343 assert hbuf.size == size
344 assert hbuf.is_cpu
345 assert arr.tobytes() == hbuf.to_pybytes()
346 for i in range(size):
347 assert hbuf[i] == arr[i]
348 for s in [
349 slice(None),
350 slice(size//4, size//2),
351 ]:
352 assert hbuf[s].to_pybytes() == arr[s].tobytes()
353
354 sbuf = hbuf.slice(size//4, size//2)
355 assert sbuf.parent == hbuf
356
357 del hbuf
358
359 with pytest.raises(TypeError,
360 match="Do not call HostBuffer's constructor directly"):
361 cuda.HostBuffer()
362
363
364@pytest.mark.parametrize("size", [0, 1, 1000])

Callers

nothing calls this directly

Calls 3

sliceFunction · 0.85
make_random_bufferFunction · 0.70
sliceMethod · 0.45

Tested by

no test coverage detected