Coverage for src / cvx / linalg / eigvals.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-19 05:40 +0000

1"""Eigenvalue utilities for general square matrices.""" 

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from .exceptions import NonSquareMatrixError, NotAMatrixError 

8 

9 

10def eigvals(matrix: np.ndarray) -> np.ndarray: 

11 """Return the eigenvalues of a square matrix. 

12 

13 This routine supports general (non-symmetric) square matrices and may 

14 return complex eigenvalues. 

15 

16 Args: 

17 matrix: Square input matrix. 

18 

19 Returns: 

20 Eigenvalues of ``matrix`` as returned by ``numpy.linalg.eigvals``. 

21 

22 Raises: 

23 NotAMatrixError: If *matrix* is not two-dimensional. 

24 NonSquareMatrixError: If *matrix* is not square. 

25 """ 

26 if matrix.ndim != 2: 

27 raise NotAMatrixError(matrix.ndim) 

28 

29 if matrix.shape[0] != matrix.shape[1]: 

30 raise NonSquareMatrixError(matrix.shape[0], matrix.shape[1]) 

31 

32 return np.linalg.eigvals(matrix)