code: def test_detrend():
      """Test custom detrend implementation."""
      point_number = 703
      features = 17
      signals, _, _ = generate_signals(
          n_features=features, length=point_number, same_variance=True
      )
      trends = generate_trends(n_features=features, length=point_number)
      x = signals + trends + 1
      original = x.copy()
  
      # Mean removal only (out-of-place)
      detrended = nisignal._detrend(x, inplace=False, type="constant")
      assert (
          abs(detrended.mean(axis=0)).max()
          < 15.0 * np.finfo(np.float64).eps
      )
  
      # out-of-place detrending. Use scipy as a reference implementation
      detrended = nisignal._detrend(x, inplace=False)
      detrended_scipy = scipy.signal.detrend(x, axis=0)
  
      # "x" must be left untouched
      np.testing.assert_almost_equal(original, x, decimal=14)
      assert (
          abs(detrended.mean(axis=0)).max()
          < 15.0 * np.finfo(np.float64).eps
      )
      np.testing.assert_almost_equal(
          detrended_scipy, detrended, decimal=14
      )
      # for this to work, there must be no trends at all in "signals"
      np.testing.assert_almost_equal(detrended, signals, decimal=14)
  
      # inplace detrending
      nisignal._detrend(x, inplace=True)
      assert abs(x.mean(axis=0)).max() < 15.0 * np.finfo(np.float64).eps
      # for this to work, there must be no trends at all in "signals"
      np.testing.assert_almost_equal(
          detrended_scipy, detrended, decimal=14
      )
      np.testing.assert_almost_equal(x, signals, decimal=14)
  
      length_1_signal = x[0]
      length_1_signal = length_1_signal[np.newaxis, :]
      np.testing.assert_array_equal(
          length_1_signal, nisignal._detrend(length_1_signal)
      )
  
      # Mean removal on integers
      detrended = nisignal._detrend(
          x.astype(np.int64), inplace=True, type="constant"
      )
      assert (
          abs(detrended.mean(axis=0)).max()
          < 20.0 * np.finfo(np.float64).eps
      )
  
imports: import os.path
  import numpy
  import pytest
  import scipy.signal
  from pandas import read_csv
  from nilearn import signal
  from nilearn.conftest import _rng
  from nilearn.signal import clean
label_desc: Use image node_id 6 for calling a global function with example usage: test_detrend() without return types