code: def get_by_index(src_gpu, ind):
      """
      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 : pycuda.gpuarray.GPUArray
          GPUArray with length of `ind` and dtype of `src_gpu` containing
          selected values.
  
      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.
      """
  
      # Only support 1D index arrays:
      assert len(np.shape(ind)) == 1
      assert issubclass(ind.dtype.type, numbers.Integral)
      N = len(ind)
      if not isinstance(ind, gpuarray.GPUArray):
          ind = gpuarray.to_gpu(ind)
      dest_gpu = gpuarray.empty(N, dtype=src_gpu.dtype)
  
      # Manually handle empty index array because it will cause the kernel to
      # fail if processed:
      if N == 0:
          return dest_gpu
      try:
          func = get_by_index.cache[(src_gpu.dtype, ind.dtype)]
      except KeyError:
          data_ctype = tools.dtype_to_ctype(src_gpu.dtype)
          ind_ctype = tools.dtype_to_ctype(ind.dtype)
          v = "{data_ctype} *dest, {ind_ctype} *ind, {data_ctype} *src".format(
              data_ctype=data_ctype, ind_ctype=ind_ctype
          )
          func = elementwise.ElementwiseKernel(
              v, "dest[i] = src[ind[i]]"
          )
          get_by_index.cache[(src_gpu.dtype, ind.dtype)] = func
      func(dest_gpu, ind, src_gpu, range=slice(0, N, 1))
      return dest_gpu
  
imports: from __future__ import absolute_import, division
  import atexit
  import numbers
  from string import Template
  import pycuda.driver
  import pycuda.gpuarray
  import pycuda.elementwise
  import pycuda.reduction
  import pycuda.scan
  import pycuda.tools
  from pycuda.tools import context_dependent_memoize, dtype_to_ctype
  from pycuda.compiler import SourceModule
  from pytools import memoize
  import numpy
  from .None import cuda
  from .None import cublas
  import sys
  import operator
label_desc: Use image node_id 19 for calling a global function with example usage: get_by_index(src_gpu, ind) and returns: dest_gpu, dest_gpu