Skip to content

Wrong return type for linalg.eigh in function signature #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Saransh-cpp opened this issue Apr 7, 2025 · 2 comments · May be fixed by #924
Open

Wrong return type for linalg.eigh in function signature #922

Saransh-cpp opened this issue Apr 7, 2025 · 2 comments · May be fixed by #924
Labels
bug Something isn't working. topic: Linear Algebra Linear algebra. topic: Static Typing Static typing.
Milestone

Comments

@Saransh-cpp
Copy link

eigh returns a Tuple[array] according to the function signature -

def eigh(x: array, /) -> Tuple[array]:

but it actually returns a NamedTuple (hence, Tuple[array, array]) -

Returns
-------
out: Tuple[array]
a namedtuple (``eigenvalues``, ``eigenvectors``) whose
- first element must have the field name ``eigenvalues`` (corresponding to :math:`\operatorname{diag}\Lambda` above) and must be an array consisting of computed eigenvalues. The array containing the eigenvalues must have shape ``(..., M)`` and must have a real-valued floating-point data type whose precision matches the precision of ``x`` (e.g., if ``x`` is ``complex128``, then ``eigenvalues`` must be ``float64``).
- second element have have the field name ``eigenvectors`` (corresponding to :math:`Q` above) and must be an array where the columns of the inner most matrices contain the computed eigenvectors. These matrices must be orthogonal. The array containing the eigenvectors must have shape ``(..., M, M)`` and must have the same data type as ``x``.

which causes problems with type checkers.

Is this intentional or is it a bug? I'd be happy to submit a quick patch to fix the function signature.

@kgryte kgryte added bug Something isn't working. topic: Linear Algebra Linear algebra. labels Apr 9, 2025
@kgryte kgryte added this to the v2025 milestone Apr 9, 2025
@kgryte
Copy link
Contributor

kgryte commented Apr 9, 2025

@Saransh-cpp Yes, this does appear to be a bug. Feel free to submit a patch. We'll likely need to backport, as well, to prior revisions.

@kgryte kgryte added the topic: Static Typing Static typing. label Apr 9, 2025
@Saransh-cpp
Copy link
Author

Thanks, opening a PR!

@Saransh-cpp Saransh-cpp linked a pull request Apr 9, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. topic: Linear Algebra Linear algebra. topic: Static Typing Static typing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants