skcuda.misc.get_by_index¶
-
skcuda.misc.
get_by_index
(src_gpu, ind)[source]¶ Get values in a GPUArray by index.
Parameters: - src_gpu (pycuda.gpuarray.GPUArray) – GPUArray instance from which to extract values.
- ind (pycuda.gpuarray.GPUArray or numpy.ndarray) – Array of element indices to set. Must have an integer dtype.
Returns: res_gpu – GPUArray with length of ind and dtype of src_gpu containing selected values.
Return type: 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.