code: def test_group_sparse_covariance_with_probe_function(rng):
      signals, _, _ = generate_group_sparse_gaussian_graphs(
          density=0.1,
          n_subjects=5,
          n_features=10,
          min_n_samples=100,
          max_n_samples=151,
          random_state=rng,
      )
  
      alpha = 0.1
  
      class Probe:
          def __init__(self):
              self.objective = []
  
          def __call__(
              self,
              emp_covs,
              n_samples,
              alpha,
              max_iter,
              tol,
              n,
              omega,
              omega_diff,
          ):
              if n >= 0:
                  _, objective = group_sparse_scores(
                      omega, n_samples, emp_covs, alpha
                  )
                  self.objective.append(objective)
  
      # Use a probe to test for number of iterations and decreasing objective.
      probe = Probe()
      _, omega = group_sparse_covariance(
          signals,
          alpha,
          max_iter=4,
          tol=None,
          verbose=0,
          probe_function=probe,
      )
      objective = probe.objective
      # check number of iterations
      assert len(objective) == 4
  
      # np.testing.assert_array_less is a strict comparison.
      # Zeros can occur in np.diff(objective).
      assert np.all(np.diff(objective) <= 0)
      assert omega.shape == (10, 10, 5)
  
file_path: nilearn/nilearn/connectome/tests/test_group_sparse_cov.py
imports: import numpy
  import pytest
  from nilearn._utils.data_gen import generate_group_sparse_gaussian_graphs
  from nilearn.connectome import GroupSparseCovariance, GroupSparseCovarianceCV
  from nilearn.connectome.group_sparse_cov import group_sparse_covariance, group_sparse_scores
label_desc: Use image node_id 2 for calling a global function with example usage: test_group_sparse_covariance_with_probe_function(rng) without return types