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

Function make_random_buffer

python/pyarrow/tests/test_cuda_numba_interop.py:62–78  ·  view source on GitHub ↗

Return a host or device buffer with random data.

(size, target='host', dtype='uint8', ctx=None)

Source from the content-addressed store, hash-verified

60
61
62def make_random_buffer(size, target='host', dtype='uint8', ctx=None):
63 """Return a host or device buffer with random data.
64 """
65 dtype = np.dtype(dtype)
66 if target == 'host':
67 assert size >= 0
68 buf = pa.allocate_buffer(size*dtype.itemsize)
69 arr = np.frombuffer(buf, dtype=dtype)
70 arr[:] = np.random.randint(low=0, high=255, size=size,
71 dtype=np.uint8)
72 return arr, buf
73 elif target == 'device':
74 arr, buf = make_random_buffer(size, target='host', dtype=dtype)
75 dbuf = ctx.new_buffer(size * dtype.itemsize)
76 dbuf.copy_from_host(buf, position=0, nbytes=buf.size)
77 return arr, dbuf
78 raise ValueError('invalid target value')
79
80
81@pytest.mark.parametrize("c", range(len(context_choice_ids)),

Callers 4

test_from_objectFunction · 0.70
test_pyarrow_memallocFunction · 0.70
test_numba_contextFunction · 0.70
test_pyarrow_jitFunction · 0.70

Calls 1

dtypeMethod · 0.80

Tested by

no test coverage detected