code: def grad_geometric_mean(mats, init=None, max_iter=10, tol=1e-7):
      """Return the norm of the covariant derivative at each iteration step of
      geometric_mean. See its docstring for details.
  
      Norm is intrinsic norm on the tangent space of the manifold of symmetric
      positive definite matrices.
  
      Returns
      -------
      grad_norm : list of float
          Norm of the covariant derivative in the tangent space at each step.
      """
      mats = np.array(mats)
  
      # Initialization
      gmean = init or np.mean(mats, axis=0)
  
      norm_old = np.inf
      step = 1.0
      grad_norm = []
      for _ in range(max_iter):
          # Computation of the gradient
          vals_gmean, vecs_gmean = linalg.eigh(gmean)
          gmean_inv_sqrt = _form_symmetric(
              np.sqrt, 1.0 / vals_gmean, vecs_gmean
          )
          whitened_mats = [
              gmean_inv_sqrt.dot(mat).dot(gmean_inv_sqrt)
              for mat in mats
          ]
          logs = [
              _map_eigenvalues(np.log, w_mat) for w_mat in whitened_mats
          ]
  
          # Covariant derivative is - gmean.dot(logs_mean)
          logs_mean = np.mean(logs, axis=0)
  
          # Norm of the covariant derivative on
          # the tangent space at point gmean
          norm = np.linalg.norm(logs_mean)
  
          # Update of the minimizer
          vals_log, vecs_log = linalg.eigh(logs_mean)
          gmean_sqrt = _form_symmetric(np.sqrt, vals_gmean, vecs_gmean)
          gmean = gmean_sqrt.dot(
              _form_symmetric(np.exp, vals_log * step, vecs_log)
          ).dot(gmean_sqrt)
  
          # Update the norm and the step size
          if norm < norm_old:
              norm_old = norm
          if norm > norm_old:
              step = step / 2.0
              norm = norm_old
  
          grad_norm.append(norm / gmean.size)
          if tol is not None and norm / gmean.size < tol:
              break
  
      return grad_norm
  
imports: import copy
  import warnings
  from math import cosh, exp, log, sinh, sqrt
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from pandas import DataFrame
  from scipy import linalg
  from sklearn.covariance import EmpiricalCovariance, LedoitWolf
  from nilearn._utils.extmath import is_spd
  from nilearn.connectome.connectivity_matrices import ConnectivityMeasure, _check_spd, _check_square, _form_symmetric, _geometric_mean, _map_eigenvalues, prec_to_partial, sym_matrix_to_vec, vec_to_sym_matrix
  from nilearn.tests.test_signal import generate_signals
label_desc: Use image node_id 17 for calling a global function with example usage: grad_geometric_mean(mats, init, max_iter, tol) and returns: grad_norm