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

Function test_HostBuffer

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

Source from the content-addressed store, hash-verified

328
329@pytest.mark.parametrize("size", [0, 1, 1000])
330def test_HostBuffer(size):
331 arr, buf = make_random_buffer(size)
332 assert arr.tobytes() == buf.to_pybytes()
333 hbuf = cuda.new_host_buffer(size)
334 np.frombuffer(hbuf, dtype=np.uint8)[:] = arr
335 assert hbuf.size == size
336 assert hbuf.is_cpu
337 assert arr.tobytes() == hbuf.to_pybytes()
338 for i in range(size):
339 assert hbuf[i] == arr[i]
340 for s in [
341 slice(None),
342 slice(size//4, size//2),
343 ]:
344 assert hbuf[s].to_pybytes() == arr[s].tobytes()
345
346 sbuf = hbuf.slice(size//4, size//2)
347 assert sbuf.parent == hbuf
348
349 del hbuf
350
351 with pytest.raises(TypeError,
352 match="Do not call HostBuffer's constructor directly"):
353 cuda.HostBuffer()
354
355
356@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