code: def _detrend(signals, inplace=False, type="linear", n_batches=10):
      """Detrend columns of input array.
  
      Signals are supposed to be columns of `signals`.
      This function is significantly faster than :func:`scipy.signal.detrend`
      on this case and uses a lot less memory.
  
      Parameters
      ----------
      signals : :class:`numpy.ndarray`
          This parameter must be two-dimensional.
          Signals to detrend. A signal is a column.
  
      inplace : :obj:`bool`, default=False
          Tells if the computation must be made inplace or not.
  
      type : {"linear", "constant"}, default="linear"
          Detrending type, either "linear" or "constant".
          See also :func:`scipy.signal.detrend`.
  
      n_batches : :obj:`int`, optional
          Number of batches to use in the computation.
  
          .. note::
              Tweaking this value can lead to variation of memory usage
              and computation time. The higher the value, the lower the
              memory consumption.
  
      Returns
      -------
      detrended_signals : :class:`numpy.ndarray`
          Detrended signals. The shape is that of ``signals``.
  
      Notes
      -----
      If a signal of length 1 is given, it is returned unchanged.
      """
      signals = as_float_array(signals, copy=not inplace)
      if signals.shape[0] == 1:
          warnings.warn(
              "Detrending of 3D signal has been requested but "
              "would lead to zero values. Skipping."
          )
          return signals
  
      signals -= np.mean(signals, axis=0)
      if type == "linear":
          # Keeping "signals" dtype avoids some type conversion further down,
          # and can save a lot of memory if dtype is single-precision.
          regressor = np.arange(signals.shape[0], dtype=signals.dtype)
          regressor -= regressor.mean()
          std = np.sqrt((regressor**2).sum())
          # avoid numerical problems
          if not std < np.finfo(np.float64).eps:
              regressor /= std
          regressor = regressor[:, np.newaxis]
  
          # No batching for small arrays
          if signals.shape[1] < 500:
              n_batches = 1
  
          # This is fastest for C order.
          for batch in gen_even_slices(signals.shape[1], n_batches):
              signals[:, batch] -= (
                  np.dot(regressor[:, 0], signals[:, batch]) * regressor
              )
      return signals
  
imports: import warnings
  import numpy
  import pandas
  from scipy import linalg, signal
  from scipy.interpolate import CubicSpline
  from sklearn.utils import as_float_array, gen_even_slices
  from nilearn._utils import fill_doc, stringify_path
  from nilearn._utils.numpy_conversions import as_ndarray, csv_to_array
  from nilearn._utils.param_validation import check_run_sample_masks
label_desc: Use image node_id 4 for calling a global function with example usage: _detrend(signals, inplace, type, n_batches) and returns: signals, signals