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