code: def kernel_riemann(X, Y=None, *, Cref=None, reg=1e-10):
      r"""Affine-invariant Riemannian kernel between two sets of SPD matrices.
  
      Calculates the affine-invariant Riemannian kernel matrix :math:`\mathbf{K}`
      of inner products of two sets :math:`\mathbf{X}` and :math:`\mathbf{Y}` of
      SPD matrices in :math:`\mathbb{R}^{n \times n}` on tangent space at
      :math:`\mathbf{C}_\text{ref}` by calculating pairwise products [1]_:
  
      .. math::
          \mathbf{K}_{i,j} = \text{tr}( \log( \mathbf{C}_\text{ref}^{-1/2}
          \mathbf{X}_i \mathbf{C}_\text{ref}^{-1/2} )
          \log( \mathbf{C}_\text{ref}^{-1/2} \mathbf{Y}_j
          \mathbf{C}_\text{ref}^{-1/2}) )
  
      Parameters
      ----------
      X : ndarray, shape (n_matrices_X, n, n)
          First set of SPD matrices.
      Y : None | ndarray, shape (n_matrices_Y, n, n), default=None
          Second set of SPD matrices. If None, Y is set to X.
      Cref : None | ndarray, shape (n, n), default=None
          Reference point for the tangent space and inner product calculation.
          If None, Cref is calculated as the Riemannian mean of X.
      reg : float, default=1e-10
          Regularization parameter to mitigate numerical errors in kernel
          matrix estimation.
  
      Returns
      -------
      K : ndarray, shape (n_matrices_X, n_matrices_Y)
          The affine-invariant Riemannian kernel matrix between X and Y.
  
      Notes
      -----
      .. versionadded:: 0.3
  
      See Also
      --------
      kernel
  
      References
      ----------
      .. [1] `Classification of covariance matrices using a Riemannian-based
          kernel for BCI applications
          <https://hal.archives-ouvertes.fr/hal-00820475/>`_
          A. Barachant, S. Bonnet, M. Congedo and C. Jutten. Neurocomputing,
          Elsevier, 2013, 112, pp.172-178.
      """
  
      def kernelfct(X, Cref):
          if Cref is None:
              Cref = mean_riemann(X)
  
          C_invsq = invsqrtm(Cref)
          X_ = logm(C_invsq @ X @ C_invsq)
          return X_
  
      return _apply_matrix_kernel(kernelfct, X, Y, Cref=Cref, reg=reg)
  
file_path: pyRiemann/pyriemann/utils/kernel.py
imports: import numpy
  from .base import invsqrtm, logm
  from .mean import mean_riemann
label_desc: Use image node_id 3 for calling a global function with example usage: kernel_riemann(X, Y) and returns: _apply_matrix_kernel, X_