code: def distance(A, B, metric="riemann", squared=False):
      """Distance between matrices according to a metric.
  
      Compute the distance between two matrices A and B according to a metric
      [1]_, or between a set of matrices A and another matrix B.
  
      Parameters
      ----------
      A : ndarray, shape (n, n) or shape (n_matrices, n, n)
          First matrix, or set of matrices.
      B : ndarray, shape (n, n)
          Second matrix.
      metric : string, default='riemann'
          The metric for distance, can be: 'euclid', 'harmonic', 'kullback',
          'kullback_right', 'kullback_sym', 'logdet', 'logeuclid', 'riemann',
          'wasserstein', or a callable function.
      squared : bool, default False
          Return squared distance.
  
          .. versionadded:: 0.5
  
      Returns
      -------
      d : float or ndarray, shape (n_matrices, 1)
          Distance between A and B.
  
      References
      ----------
      .. [1] `Review of Riemannian distances and divergences, applied to
          SSVEP-based BCI
          <https://hal.archives-ouvertes.fr/LISV/hal-03015762v1>`_
          S. Chevallier, E. K. Kalunga, Q. Barthélemy, E. Monacelli.
          Neuroinformatics, Springer, 2021, 19 (1), pp.93-106
      """
      distance_function = _check_distance_function(metric)
  
      shape_A, shape_B = A.shape, B.shape
      if shape_A == shape_B:
          d = distance_function(A, B, squared=squared)
      elif len(shape_A) == 3 and len(shape_B) == 2:
          d = np.empty((shape_A[0], 1))
          for i in range(shape_A[0]):
              d[i] = distance_function(A[i], B, squared=squared)
      else:
          raise ValueError("Inputs have incompatible dimensions.")
  
      return d
  
imports: import numpy
  from scipy.linalg import eigvalsh, solve
  from sklearn.metrics import euclidean_distances
  from .base import logm, sqrtm, invsqrtm
label_desc: Use image node_id 13 for calling a global function with example usage: distance(A, B, metric, squared) and returns: d