code: def _slice_mostly_sorted(array, keep, rest, ind=None):
      """Slice dask array `array` that is almost entirely sorted already.
  
      We perform approximately `2 * len(keep)` slices on `array`.
      This is OK, since `keep` is small. Individually, each of these slices
      is entirely sorted.
  
      Parameters
      ----------
      array : dask.array.Array
      keep : ndarray[Int]
          This must be sorted.
      rest : ndarray[Bool]
      ind : ndarray[Int], optional
  
      Returns
      -------
      sliced : dask.array.Array
      """
      if ind is None:
          ind = np.arange(len(array))
      idx = np.argsort(np.concatenate([keep, ind[rest]]))
  
      slices = []
      if keep[0] > 0:  # avoid creating empty slices
          slices.append(slice(None, keep[0]))
      slices.append([keep[0]])
      windows = zip(keep[:-1], keep[1:])
  
      for l, r in windows:
          if r > l + 1:  # avoid creating empty slices
              slices.append(slice(l + 1, r))
          slices.append([r])
  
      if keep[-1] < len(array) - 1:  # avoid creating empty slices
          slices.append(slice(keep[-1] + 1, None))
      result = da.concatenate([array[idx[slice_]] for slice_ in slices])
      return result
  
file_path: dask-ml/dask_ml/cluster/spectral.py
imports: import logging
  import dask.array
  import numpy
  import sklearn.cluster
  from dask import delayed
  from scipy.linalg import pinv, svd
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.utils import check_random_state
  from .._utils import draw_seed
  from ..metrics.pairwise import PAIRWISE_KERNEL_FUNCTIONS, pairwise_kernels
  from ..utils import _format_bytes, _log_array, check_array
  from .k_means import KMeans
label_desc: Use image node_id 2 for calling a global function with example usage: _slice_mostly_sorted(array, keep, rest, ind) and returns: result