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

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

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from ..core.types import Matrix, Vector 

8from ..core.valid import valid 

9 

10 

11def eigh(matrix: Matrix) -> tuple[Vector, Matrix]: 

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

13 

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

15 decomposition. 

16 

17 Args: 

18 matrix: Square symmetric/Hermitian input matrix. 

19 

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) 

26 

27 

28def eigvalsh(matrix: Matrix) -> Vector: 

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

30 

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

32 decomposition. 

33 

34 Args: 

35 matrix: Square symmetric/Hermitian input matrix. 

36 

37 Returns: 

38 Eigenvalues of the valid submatrix in ascending order. 

39 """ 

40 eigenvalues, _ = eigh(matrix) 

41 return eigenvalues