skcuda.misc.get_by_index

skcuda.misc.get_by_index(src_gpu, ind)[source]

Get values in a GPUArray by index.

Parameters:
Returns:

res_gpu – GPUArray with length of ind and dtype of src_gpu containing selected values.

Return type:

pycuda.gpuarray.GPUArray

Examples

>>> import pycuda.gpuarray as gpuarray
>>> import pycuda.autoinit
>>> import numpy as np
>>> import misc
>>> src = np.random.rand(5).astype(np.float32)
>>> src_gpu = gpuarray.to_gpu(src)
>>> ind = gpuarray.to_gpu(np.array([0, 2, 4]))
>>> res_gpu = misc.get_by_index(src_gpu, ind)
>>> np.allclose(res_gpu.get(), src[[0, 2, 4]])
True

Notes

Only supports 1D index arrays.

May not be efficient for certain index patterns because of lack of inability to coalesce memory operations.