Coverage for src/cvx/linalg/decomposition/eigvals.py: 100%
12 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"""Eigenvalue utilities for general square matrices."""
3from __future__ import annotations
5from typing import cast
7import numpy as np
8import numpy.typing as npt
10from ..core.exceptions import NonSquareMatrixError, NotAMatrixError
11from ..core.types import Matrix, Vector
14def eigvals(matrix: Matrix) -> Vector | npt.NDArray[np.complex128]:
15 """Return the eigenvalues of a square matrix.
17 This routine supports general (non-symmetric) square matrices and may
18 return complex eigenvalues.
20 Args:
21 matrix: Square input matrix.
23 Returns:
24 Eigenvalues of ``matrix`` as returned by ``numpy.linalg.eigvals``.
26 Raises:
27 NotAMatrixError: If *matrix* is not two-dimensional.
28 NonSquareMatrixError: If *matrix* is not square.
29 """
30 if matrix.ndim != 2:
31 raise NotAMatrixError(matrix.ndim, func="eigvals")
33 if matrix.shape[0] != matrix.shape[1]:
34 raise NonSquareMatrixError(matrix.shape[0], matrix.shape[1])
36 return cast("Vector | npt.NDArray[np.complex128]", np.linalg.eigvals(matrix))