code: def slice_array(x, y, idx, r=0):
      """Build training array index and slice data."""
      if idx == "all":
          idx = None
  
      if idx:
          # Check if the idx is a tuple and if so, whether it can be made
          # into a simple slice
          if isinstance(idx[0], tuple):
              if len(idx[0]) > 1:
                  # Advanced indexing is required. This will trigger a copy
                  # of the slice in question to be made
                  simple_slice = False
                  idx = np.hstack(
                      [np.arange(t0 - r, t1 - r) for t0, t1 in idx]
                  )
                  x = _safe_slice(x, idx)
                  y = _safe_slice(y, idx)
              else:
                  # The tuple is of the form ((a, b),) and can be made
                  # into a simple (a, b) tuple for which basic slicing applies
                  # which allows a view to be returned instead of a copy
                  simple_slice = True
                  idx = idx[0]
          else:
              # Index tuples of the form (a, b) allows simple slicing
              simple_slice = True
  
          if simple_slice:
              x = x[slice(idx[0] - r, idx[1] - r)]
              y = (
                  y[slice(idx[0] - r, idx[1] - r)]
                  if y is not None
                  else y
              )
  
      # Cast as ndarray to avoid passing memmaps to estimators
      if y is not None and isinstance(y, np.memmap):
          y = y.view(type=np.ndarray)
      if not issparse(x) and isinstance(x, np.memmap):
          x = x.view(type=np.ndarray)
  
      return x, y
  
file_path: mlens/mlens/parallel/_base_functions.py
imports: from __future__ import division
  import os
  import warnings
  from scipy.sparse import issparse
  import numpy
  from ..utils import pickle_load, pickle_save, load
  from ..utils.exceptions import MetricWarning, ParameterChangeWarning
label_desc: Use image node_id 8 for calling a global function with example usage: slice_array(x, y, idx, r) and returns: x,  y