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

Function make_random_buffer

python/pyarrow/tests/test_cuda.py:99–119  ·  view source on GitHub ↗

Return a host or device buffer with random data.

(size, target='host')

Source from the content-addressed store, hash-verified

97
98
99def make_random_buffer(size, target='host'):
100 """Return a host or device buffer with random data.
101 """
102 if target == 'host':
103 assert size >= 0
104 buf = pa.allocate_buffer(size)
105 assert buf.size == size
106 arr = np.frombuffer(buf, dtype=np.uint8)
107 assert arr.size == size
108 arr[:] = np.random.randint(low=1, high=255, size=size, dtype=np.uint8)
109 assert arr.sum() > 0 or size == 0
110 arr_ = np.frombuffer(buf, dtype=np.uint8)
111 np.testing.assert_equal(arr, arr_)
112 return arr, buf
113 elif target == 'device':
114 arr, buf = make_random_buffer(size, target='host')
115 dbuf = global_context.new_buffer(size)
116 assert dbuf.size == size
117 dbuf.copy_from_host(buf, position=0, nbytes=size)
118 return arr, dbuf
119 raise ValueError('invalid target value')
120
121
122@pytest.mark.parametrize("size", [0, 1, 1000])

Callers 15

test_context_from_objectFunction · 0.70
test_CudaBufferFunction · 0.70
test_HostBufferFunction · 0.70
test_copy_to_hostFunction · 0.70
test_copy_from_deviceFunction · 0.70
test_copy_from_hostFunction · 0.70
test_buffer_deviceFunction · 0.70
test_writesFunction · 0.70
test_BufferReaderFunction · 0.70

Calls 1

sumMethod · 0.45

Tested by

no test coverage detected