code: def mean_logdet(
      X=None,
      tol=10e-5,
      maxiter=50,
      init=None,
      sample_weight=None,
      covmats=None,
  ):
      r"""Mean of SPD/HPD matrices according to the log-det metric.
  
      Log-det mean is obtained by an iterative procedure where the update is:
  
      .. math::
          \mathbf{M} = \left( \sum_i w_i \ \left( 0.5 \mathbf{M}
                       + 0.5 \mathbf{X}_i \right)^{-1} \right)^{-1}
  
      Parameters
      ----------
      X : ndarray, shape (n_matrices, n, n)
          Set of SPD/HPD matrices.
      tol : float, default=10e-5
          The tolerance to stop the gradient descent.
      maxiter : int, default=50
          The maximum number of iterations.
      init : None | ndarray, shape (n, n), default=None
          A SPD/HPD matrix used to initialize the gradient descent.
          If None, the weighted Euclidean mean is used.
      sample_weight : None | ndarray, shape (n_matrices,), default=None
          Weights for each matrix. If None, it uses equal weights.
  
      Returns
      -------
      M : ndarray, shape (n, n)
          Log-det mean.
  
      See Also
      --------
      mean_covariance
      """
      X = _deprecate_covmats(covmats, X)
      n_matrices, _, _ = X.shape
      sample_weight = check_weights(sample_weight, n_matrices)
      if init is None:
          M = mean_euclid(X, sample_weight=sample_weight)
      else:
          M = init
  
      crit = np.finfo(np.float64).max
      for _ in range(maxiter):
          invX = np.linalg.inv(0.5 * X + 0.5 * M)
          J = np.einsum("a,abc->bc", sample_weight, invX)
          Mnew = np.linalg.inv(J)
  
          crit = np.linalg.norm(Mnew - M, ord="fro")
          M = Mnew
          if crit <= tol:
              break
      else:
          warnings.warn("Convergence not reached")
  
      return M
  
imports: from copy import deepcopy
  import numpy
  import warnings
  from .ajd import ajd_pham
  from .base import sqrtm, invsqrtm, logm, expm, powm
  from .distance import distance_riemann
  from .geodesic import geodesic_riemann
  from .utils import check_weights
label_desc: Use image node_id 8 for calling a global function with example usage: mean_logdet(X, tol, maxiter, init, sample_weight, covmats) and returns: M