Skip to content
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

WIP: Add specifications for computing eigenvalues and eigenvectors #113

Closed
wants to merge 3 commits into from

Conversation

kgryte
Copy link
Contributor

@kgryte kgryte commented Jan 14, 2021

This PR is currently a WIP.

This PR

  • specifies interfaces for computing eigenvalues and eigenvectors.
  • is derived from comparing signatures across array libraries.

Notes

  • This PR is blocked by lack of complex number support. Real-valued matrices may have complex-valued eigenvalues, so limiting inputs to real-valued arrays is not sufficient. Torch currently returns an nx2 eigenvalue matrix, where each row consists of a real and an imaginary component. This is a possibility, but would seem more prudent to hold off until complex number support is included in the spec.

  • In contrast to NumPy's UPLO keyword pattern (following LAPACK), this PR follows Torch and uses an upper keyword to have better consistency with other linalg spec'd functions.

  • Open question whether a separate eigvals API is needed in addition to eig. For example, in SciPy, can set left and right to False to only return eigenvalues. Presumably something similar could be done here to consolidate into a single API.

    • Answer: having dedicated APIs deemed better in order to avoid polymorphic output and to simplify API surfaces.
  • Open question whether, like SciPy, the spec should support returning either left or right or both eigenvectors. Supporting one or both is supported outside of the PyData ecosystem (e.g., in LAPACK and MATLAB).

    • Answer: same as previous answer.

@leofang
Copy link
Contributor

leofang commented Jan 14, 2021

Complex number support was raised in #102. I should have added eigensolvers being another big application there! 😞 Thanks for raising this need again, @kgryte.

@leofang
Copy link
Contributor

leofang commented Jan 14, 2021

One thought following the resolution #105 could be that we still accept this PR to define the signatures clearly, but say that the actual standardization will come along with the complex number support in the next version of Array API. This way the array libraries like CuPy which already support complex number can work out the support very quickly.

@leofang
Copy link
Contributor

leofang commented Jan 14, 2021

One thing interesting (which I mentioned in today's meeting) is that ROCm currently does not provide an eigensolver for general Hermitian matrices, only for tridiagonal matrices: https://rocsolver.readthedocs.io/en/latest/userguide_api.html#eigensolvers.

@rgommers
Copy link
Member

eigh has landed for PyTorch, with UPLO not upper: https://pytorch.org/docs/master/linalg.html#torch.linalg.eigh. linalg.eig is still going to take a little while though.

@rgommers
Copy link
Member

One thought following the resolution #105 could be that we still accept this PR to define the signatures clearly, but say that the actual standardization will come along with the complex number support in the next version of Array API. This way the array libraries like CuPy which already support complex number can work out the support very quickly.

Yes, working out the signatures that we expect to add to the next version makes sense to me.

@kgryte
Copy link
Contributor Author

kgryte commented Jan 25, 2021

@rgommers I am guessing that Torch's decision to use UPLO is for 1:1 NumPy compatibility? Not clear to me otherwise why this would be desirable over upper (or, in general, a keyword argument which accepts a boolean value).

@rgommers
Copy link
Member

@rgommers I am guessing that Torch's decision to use UPLO is for 1:1 NumPy compatibility? Not clear to me otherwise why this would be desirable over upper (or, in general, a keyword argument which accepts a boolean value).

Yes indeed, just for compat. API design wise UPLO makes no sense at all.

@rgommers rgommers added the API extension Adds new functions or objects to the API. label Mar 20, 2021
@rgommers rgommers force-pushed the main branch 3 times, most recently from 0607525 to 138e963 Compare April 19, 2021 20:25
@kgryte kgryte added this to the v2022 milestone Oct 4, 2021
@ilayn
Copy link

ilayn commented Feb 18, 2022

I have been doing the annual linalg check of SciPy overhaul and currently linalg.eig is underway.

It seems to me that uplo or lower=True is a LAPACK plumbing issue rather than a high-level user choice. In other words, to be able to use half of the array at the Python level is quite a rarity in my limited experience so far (CPU compute, dense arrays, <32gb size). I think it is much better to get it out of the way and let the users use low level LAPACK wrappers themselves directly for such usage.

At the face value this might seem like a regression but as I recently convinced myself about it, it really doesn't add anything interesting because the array is already allocated. In fact the rectangular packing or other ways of allocating the array is way more economical instead of forcing eig or eigh to serve every use case in every library. Hence I'd definitely recommend checking out the options for low level 1D storage of half triangle data should there be a need for this.

Similarly, eigvals and eigvalsh is, I think, just API clutter. eig and eigh is in my opinion just good enough with already left=False default. For the common usage eig(..., right=False) is not really a mind-bender or finger-twister to turn off the eigvector computation.

We have always been looking at these functions as the thin-wrappers of the LAPACK routines but I think we should clearly separate the UX of Python funcs eig, eigh, svd from the low-level plumbing that we the maintainers should be doing regardless. And I think we can do a lot in terms of usability and convenience. The more important issue is the unfortunate intermediate array creations for incompatible stride/memory layout arrays etc. But that is a whole another story.

I'm curious to what others think about this.

@rgommers rgommers mentioned this pull request Mar 14, 2022
@kgryte kgryte removed this from the v2022 milestone Dec 13, 2022
@leofang
Copy link
Contributor

leofang commented Dec 21, 2022

@kgryte I assume this PR has a successor and so can be closed?

@kgryte
Copy link
Contributor Author

kgryte commented Dec 21, 2022

@leofang Yeah, we should probably just close this one out and create a new PR for the relevant APIs, rather than try to retrofit the current PR.

@kgryte kgryte closed this Dec 21, 2022
@honno honno deleted the eig branch February 28, 2024 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API extension Adds new functions or objects to the API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants