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

Consider sorting eigenvalues and singular values #897

Open
Andlon opened this issue May 20, 2021 · 5 comments
Open

Consider sorting eigenvalues and singular values #897

Andlon opened this issue May 20, 2021 · 5 comments

Comments

@Andlon
Copy link
Collaborator

Andlon commented May 20, 2021

Currently, there are no guarantees about ordering of eigenvalues and singular vectors returned by nalgebra's decompositions. A common convention throughout mathematical literature is to assume that eigenvalues and singular values are ordered in descending order. Many other mathematical libraries also do this. By following the same convention we would ease porting efforts from other languages into nalgebra code. Recently, a user had this exact issue when porting code from numpy (see #893).

The simplest way to achieve this is to compute a permutation of the eigenvalues/singular values and then apply the permutation also to the columns/rows of the accompanying orthogonal matrices (if computed). While this should have negligible overhead for larger matrices since the decomposition itself is O(n^3), it is not clear to me if perhaps this has some non-trivial cost for small matrices. In this case, we should benchmark and perhaps consider providing means to opt out of this behavior if users are concerned about performance.

@Andlon
Copy link
Collaborator Author

Andlon commented Jun 21, 2021

Very closely related: #349.

@nestordemeure
Copy link
Contributor

While this should have negligible overhead for larger matrices since the decomposition itself is O(n^3)

It might have a large memory overhead if nalgebra doesn't have an in-place permutation operation.

@Andlon
Copy link
Collaborator Author

Andlon commented Sep 1, 2021

While this should have negligible overhead for larger matrices since the decomposition itself is O(n^3)

It might have a large memory overhead if nalgebra doesn't have an in-place permutation operation.

I don't think so - computing and storing a permutation would only require O(n) memory, compared to O(n^2) for storingthe eigenvalue/singular value decomposition. Or perhaps I misunderstand you!

What we do need to take care with, however, is allocation. In particular we would need to make sure that computing/storing/applying this permutation does not require heap allocation for small matrices. That is however already similar/analogous to how we e.g. deal with permutations in LU.

@timjb
Copy link

timjb commented Feb 6, 2022

This issue should be closed because #1081 has been merged, right?

@Andlon
Copy link
Collaborator Author

Andlon commented Feb 7, 2022

@timjb: singular values are now sorted, but IIRC, eigenvalues are not yet sorted (unless I missed a PR for this!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants