Skip to content

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

Open
@Saransh-cpp

Description

@Saransh-cpp

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.

Activity

added this to the v2025 milestone on Apr 9, 2025
kgryte

kgryte commented on Apr 9, 2025

@kgryte
Contributor

@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.

Saransh-cpp

Saransh-cpp commented on Apr 9, 2025

@Saransh-cpp
Author

Thanks, opening a PR!

linked a pull request that will close this issue on Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @kgryte@Saransh-cpp

      Issue actions

        Wrong return type for `linalg.eigh` in function signature · Issue #922 · data-apis/array-api