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
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 05:40 +0000
1"""Eigenvalue utilities for general square matrices."""
3from __future__ import annotations
5import numpy as np
7from .exceptions import NonSquareMatrixError, NotAMatrixError
10def eigvals(matrix: np.ndarray) -> np.ndarray:
11 """Return the eigenvalues of a square matrix.
13 This routine supports general (non-symmetric) square matrices and may
14 return complex eigenvalues.
16 Args:
17 matrix: Square input matrix.
19 Returns:
20 Eigenvalues of ``matrix`` as returned by ``numpy.linalg.eigvals``.
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)
29 if matrix.shape[0] != matrix.shape[1]:
30 raise NonSquareMatrixError(matrix.shape[0], matrix.shape[1])
32 return np.linalg.eigvals(matrix)