code: def _blockwise_slice(arr, idx):
      
      objs = []
      offsets = np.hstack([0, np.cumsum(arr.chunks[0])[:-1]])
  
      for i, (x, idx2) in enumerate(
          zip(arr.to_delayed().ravel(), idx.to_delayed().ravel())
      ):
          idx3 = idx2 - offsets[i]
          objs.append(x[idx3])
  
      shapes = idx.chunks[0]
      if arr.ndim == 2:
          P = arr.shape[1]
          shapes = [(x, P) for x in shapes]
      else:
          shapes = [(x,) for x in shapes]
  
      sliced = da.concatenate(
          [
              da.from_delayed(x, shape=shape, dtype=arr.dtype)
              for x, shape in zip(objs, shapes)
          ]
      )
      return sliced
docs: Slice an array that is blockwise-aligned with idx.
  
      Parameters
      ----------
      arr : Dask array
      idx : Dask array
          Should have the following properties
  
          * Same blocks as `arr` along the first dimension
          * Contains only integers
          * Each block's values should be between ``[0, len(block))``
  
      Returns
      -------
      sliced : dask.Array