code: def test_sample_mask():
      """Test sample_mask related feature."""
      signals, _, confounds = generate_signals(
          n_features=11, n_confounds=5, length=40
      )
  
      sample_mask = np.arange(signals.shape[0])
      scrub_index = [2, 3, 6, 7, 8, 30, 31, 32]
      sample_mask = np.delete(sample_mask, scrub_index)
      sample_mask_binary = np.full(signals.shape[0], True)
      sample_mask_binary[scrub_index] = False
  
      scrub_clean = clean(
          signals, confounds=confounds, sample_mask=sample_mask
      )
      assert scrub_clean.shape[0] == sample_mask.shape[0]
  
      # test the binary mask
      scrub_clean_bin = clean(
          signals, confounds=confounds, sample_mask=sample_mask_binary
      )
      np.testing.assert_equal(scrub_clean_bin, scrub_clean)
  
      # list of sample_mask for each run
      runs = np.ones(signals.shape[0])
      runs[: signals.shape[0] // 2] = 0
      sample_mask_sep = [np.arange(20), np.arange(20)]
      scrub_index = [[6, 7, 8], [10, 11, 12]]
      sample_mask_sep = [
          np.delete(sm, si)
          for sm, si in zip(sample_mask_sep, scrub_index)
      ]
      scrub_sep_mask = clean(
          signals,
          confounds=confounds,
          sample_mask=sample_mask_sep,
          runs=runs,
      )
      assert scrub_sep_mask.shape[0] == signals.shape[0] - 6
  
      # test for binary mask per run
      sample_mask_sep_binary = [
          np.full(signals.shape[0] // 2, True),
          np.full(signals.shape[0] // 2, True),
      ]
      sample_mask_sep_binary[0][scrub_index[0]] = False
      sample_mask_sep_binary[1][scrub_index[1]] = False
      scrub_sep_mask = clean(
          signals,
          confounds=confounds,
          sample_mask=sample_mask_sep_binary,
          runs=runs,
      )
      assert scrub_sep_mask.shape[0] == signals.shape[0] - 6
  
      # 1D sample mask with runs labels
      with pytest.raises(
          ValueError, match=r"Number of sample_mask \(\d\) not matching"
      ):
          clean(signals, sample_mask=sample_mask, runs=runs)
  
      # invalid input for sample_mask
      with pytest.raises(TypeError, match="unhandled type"):
          clean(signals, sample_mask="not_supported")
  
      # sample_mask too long
      with pytest.raises(
          IndexError, match="more timepoints than the current run"
      ):
          clean(
              signals, sample_mask=np.hstack((sample_mask, sample_mask))
          )
  
      # list of sample_mask with one that's too long
      invalid_sample_mask_sep = [np.arange(10), np.arange(30)]
      with pytest.raises(
          IndexError, match="more timepoints than the current run"
      ):
          clean(signals, sample_mask=invalid_sample_mask_sep, runs=runs)
  
      # list of sample_mask  with invalid indexing in one
      sample_mask_sep[-1][-1] = 100
      with pytest.raises(IndexError, match="invalid index"):
          clean(signals, sample_mask=sample_mask_sep, runs=runs)
  
      # invalid index in 1D sample_mask
      sample_mask[-1] = 999
      with pytest.raises(IndexError, match=r"invalid index \[\d*\]"):
          clean(signals, sample_mask=sample_mask)
  
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 21 for calling a global function with example usage: test_sample_mask() without return types