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

1"""Symmetric/Hermitian eigendecomposition helpers with NaN-aware filtering.""" 

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from .valid import valid 

8 

9 

10def eigh(matrix: np.ndarray) -> tuple[np.ndarray, np.ndarray]: 

11 """Compute eigendecomposition of a real symmetric or Hermitian matrix. 

12 

13 Rows and columns with non-finite diagonal entries are excluded before 

14 decomposition. 

15 

16 Args: 

17 matrix: Square symmetric/Hermitian input matrix. 

18 

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) 

25 

26 

27def eigvalsh(matrix: np.ndarray) -> np.ndarray: 

28 """Return eigenvalues of a real symmetric or Hermitian matrix. 

29 

30 Rows and columns with non-finite diagonal entries are excluded before 

31 decomposition. 

32 

33 Args: 

34 matrix: Square symmetric/Hermitian input matrix. 

35 

36 Returns: 

37 Eigenvalues of the valid submatrix in ascending order. 

38 """ 

39 eigenvalues, _ = eigh(matrix) 

40 return eigenvalues