Coverage for src / cvx / linalg / eigh.py: 100%
9 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 05:40 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 05:40 +0000
1"""Symmetric/Hermitian eigendecomposition helpers with NaN-aware filtering."""
3from __future__ import annotations
5import numpy as np
7from .valid import valid
10def eigh(matrix: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
11 """Compute eigendecomposition of a real symmetric or Hermitian matrix.
13 Rows and columns with non-finite diagonal entries are excluded before
14 decomposition.
16 Args:
17 matrix: Square symmetric/Hermitian input matrix.
19 Returns:
20 A tuple ``(eigenvalues, eigenvectors)`` as returned by ``np.linalg.eigh``
21 on the valid submatrix. Eigenvalues are sorted in ascending order.
22 """
23 _, submatrix = valid(matrix)
24 return np.linalg.eigh(submatrix)
27def eigvalsh(matrix: np.ndarray) -> np.ndarray:
28 """Return eigenvalues of a real symmetric or Hermitian matrix.
30 Rows and columns with non-finite diagonal entries are excluded before
31 decomposition.
33 Args:
34 matrix: Square symmetric/Hermitian input matrix.
36 Returns:
37 Eigenvalues of the valid submatrix in ascending order.
38 """
39 eigenvalues, _ = eigh(matrix)
40 return eigenvalues