code: def _select_by_peak_distance(peaks, priority, distance):
      """
      Evaluate which peaks fulfill the distance condition.
  
      Parameters
      ----------
      peaks : ndarray
          Indices of peaks in `vector`.
      priority : ndarray
          An array matching `peaks` used to determine priority of each peak. A
          peak with a higher priority value is kept over one with a lower one.
      distance : np.float64
          Minimal distance that peaks must be spaced.
  
      Returns
      -------
      keep : ndarray[bool]
          A boolean mask evaluating to true where `peaks` fulfill the distance
          condition.
  
      Notes
      -----
      Declaring the input arrays as C-contiguous doesn't seem to have performance
      advantages.
      """
      peaks_size = peaks.shape[0]
      # Round up because actual peak distance can only be natural number
      distance_ = cupy.ceil(distance)
      keep = cupy.ones(
          peaks_size, dtype=cupy.bool_
      )  # Prepare array of flags
  
      # Create map from `i` (index for `peaks` sorted by `priority`) to `j`
      # (index for `peaks` sorted by position). This allows to iterate `peaks`
      # and `keep` with `j` by order of `priority` while still maintaining the
      # ability to step to neighbouring peaks with (`j` + 1) or (`j` - 1).
      priority_to_position = cupy.argsort(priority)
  
      # Highest priority first -> iterate in reverse order (decreasing)
  
      # NOTE: There's not an alternative way to do this procedure in a parallel
      # fashion, since discarding a peak requires to know if there's a valid
      # neighbour that subsumes it, which in turn requires to know
      # if that neighbour is valid. If it was to done in parallel, there would be
      # tons of repeated computations per peak, thus increasing the total runtime
      # per peak compared to a sequential implementation.
      for i in range(peaks_size - 1, -1, -1):
          # "Translate" `i` to `j` which points to current peak whose
          # neighbours are to be evaluated
          j = priority_to_position[i]
          if keep[j] == 0:
              # Skip evaluation for peak already marked as "don't keep"
              continue
  
          k = j - 1
          # Flag "earlier" peaks for removal until minimal distance is exceeded
          while 0 <= k and peaks[j] - peaks[k] < distance_:
              keep[k] = 0
              k -= 1
  
          k = j + 1
          # Flag "later" peaks for removal until minimal distance is exceeded
          while k < peaks_size and peaks[k] - peaks[j] < distance_:
              keep[k] = 0
              k += 1
      return keep
  
imports: import math
  import cupy
  from cupy._core._scalar import get_typename
  from cupy_backends.cuda.api import runtime
  from cupyx import jit
label_desc: Use image node_id 7 for calling a global function with example usage: _select_by_peak_distance(peaks, priority, distance) and returns: keep