-
Notifications
You must be signed in to change notification settings - Fork 25
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
Sorting order of eigvals #47
Comments
I think this is because in GenericLinearAlgebra.jl/src/eigenGeneral.jl Lines 254 to 256 in 19b6c8d
default values aren't given to the keyword arguments, whereas in Base, e.g. they are. So I guess the fix would be to just use the same default values. One catch though is that the default sorting keyword argument in Base is |
Hmm, well it's not just the default keyword arguments, the sorting would need to be implemented too, because in GenericLinearAlgebra the keyword arguments get passed to GenericLinearAlgebra.jl/src/eigenGeneral.jl Line 258 in 19b6c8d
which only currently accepts |
Base has a function for sorting eigenvalues, this could be used straight up I believe |
Yes, but that was only added in 1.2 (in this PR: JuliaLang/julia#21598), so I think it's probably better to copy it into GenericLinearAlgebra so GenericLinearAlgebra can be used on 1.1 and 1.0 |
Oh, I guess it can be used as @static if VERSION > v"1.2.0-DEV.0" # Sort one more time to handle GenericLinearAlgebra not being updated
sort!(roots, by=LinearAlgebra.eigsortby)
end like in what you linked. I think there's still one more problem though: even Julia 1.0 and 1.1 sort eigenvalues of Hermitian matrices automatically, but GenericLinearAlgebra doesn't sort those eigenvalues either. So gating the sorting behind a 1.2 check would fix the complex-eigenvalue case but not the real eigenvalue case. |
Perhaps, but the sorting was only convention in Julia 1.2 and onwards, so the most compatible strategy would be to conditionally sort the eigenvalues based on the Julia version, like on the link I pasted above. A bit of a hassle though, I admit |
I think we wrote at the same time, haha. Yeah, I guess maximum agreement with Base would be to only sort in the non-Hermitian/non-symmetric case if the version is at least 1.2, but add a separate sorting for the real eigenvalues of Hermitian/symmetric matrices for 1.0 and 1.1 (which Julia would do on those versions because that's what the underlying LAPACK would do in that case). But since the in 1.0 and 1.1, in the non-Hermitian case the sorting is allowed to be anything, it seems fine to just sort in all cases the same way, and resolve both problems at once (the Hermitian and non-Hermitian case). |
I made a PR to fix this, and ended up going with what you suggested @baggepinnen, using the It turns out GenericLinearAlgebra already sorts the eigenvalues in the self-adjoint case; what I was seeing was that if a matrix is not wrapped in |
In julia v1.2, the order of eigenvalues are sorted differently
From NEWS.md
It would be great if GenericLinearAlgebra followed the same convention.
The text was updated successfully, but these errors were encountered: