code: def upper(X):
      r"""Return the weighted upper triangular part of matrices.
  
      This function computes the minimal representation of a matrix in tangent
      space [1]_: it keeps the upper triangular part of the symmetric/Hermitian
      matrix and vectorizes it by applying unity weight for diagonal elements and
      :math:`\sqrt{2}` weight for out-of-diagonal elements.
  
      Parameters
      ----------
      X : ndarray, shape (..., n, n)
          Symmetric/Hermitian matrices.
  
      Returns
      -------
      T : ndarray, shape (..., n * (n + 1) / 2)
          Weighted upper triangular parts of symmetric/Hermitian matrices.
  
      Notes
      -----
      .. versionadded:: 0.4
  
      References
      ----------
      .. [1] `Pedestrian detection via classification on Riemannian manifolds
          <https://ieeexplore.ieee.org/document/4479482>`_
          O. Tuzel, F. Porikli, and P. Meer. IEEE Transactions on Pattern
          Analysis and Machine Intelligence, Volume 30, Issue 10, October 2008.
      """
      n = X.shape[-1]
      if X.shape[-2] != n:
          raise ValueError("Matrices must be square")
      idx = np.triu_indices_from(np.empty((n, n)))
      coeffs = (np.sqrt(2) * np.triu(np.ones((n, n)), 1) + np.eye(n))[
          idx
      ]
      T = coeffs * X[..., idx[0], idx[1]]
      return T
  
file_path: pyRiemann/pyriemann/utils/tangentspace.py
imports: import numpy
  from .base import sqrtm, invsqrtm, logm, expm
  from .mean import mean_covariance
label_desc: Use image node_id 8 for calling a global function with example usage: upper(X) and returns: T