-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Explicit transform for eigs - bugfix generalized eigenvalue problems #27428
Conversation
I forgot explanation: I had to change matvecA!(y, x) = mul!(y, A, x) to matvecA! = (y, x) -> mul!(y, A, x) because I wanted to change the function at a later point. Maybe someone knows if this change can have implications on performance? |
It seems it passes all unit tests except this: srand(127)
n = 10
k = 3
A = randn(n,n); A = A'A
B = randn(n,k); B = B*B'
@test sort(eigs(A, B, nev = k, sigma = 1.0)[1]) ≈ sort(eigvals(A, B)[1:k]) It fails when it tries to sort complex numbers. With It can be easily "fixed" by changing the test to @test sort(eigs(A, B, nev = k, sigma = 1.0,explicittransform=false)[1]) ≈ sort(eigvals(A, B)[1:k]) I do realize that returning different types based on kwarg-values is text-book type instability. The only fix I can think of is to take another parameter to eigs(A,B;params)=_eigs(Complex128,A,B;params...);
eigs(T,A,B;params)=_eigs(T,A,B;params...);
function _eigs{T}(::Type{T},A,B;nev::Integer=6, ncv::Integer=max(20,2*nev+1), which=:LM,
tol=0.0, maxiter::Integer=300, sigma=nothing, v0::Vector=zeros(eltype(A),(0,)),
ritzvec::Bool=true, explicittransform=:AUTO)
... Not sure how severe is this problem is. Ideas appreciated. |
|
Ah. Yes indeed. Also, the older discussion in JuliaLang/LinearAlgebra.jl#279 suggests that making it type stable is non-trivial. |
…igenvalue problems even if not definite
If the values of this argument are |
@@ -69,9 +69,11 @@ eigs(A, B; kwargs...) = _eigs(A, B; kwargs...) | |||
function _eigs(A, B; | |||
nev::Integer=6, ncv::Integer=max(20,2*nev+1), which=:LM, | |||
tol=0.0, maxiter::Integer=300, sigma=nothing, v0::Vector=zeros(eltype(A),(0,)), | |||
ritzvec::Bool=true) | |||
ritzvec::Bool=true, explicittransform=nothing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly better to put a Union{Bool, Nothing}
type annotation on this then 😀
Sounds better indeed. Should be fixed now. I'm not so experienced in contributing in this way, want me to add tests? Squash commits? |
@jarlebring Thanks for preparing this PR Sorry for the lag of response. It's on my todo but I've had to look into other tasks before getting to this. Hopefully, I'll find the time for a review later this week. |
@jarlebring As you might have noticed, we have moved ARPACK bindings to Arpack.jl (which partly has contributed to the delay in reviewing this PR) such that developement of our ARPACK wrappers won't be tied to the developement cycles of the main repo. Would you mind moving this PR to Arpack.jl instead. Then we should be able to merge it shortly. |
Sounds good. See new PR in JuliaLinearAlgebra. Hope I understood you correctly. |
Here is an attempt to resolve the bug in JuliaLang/LinearAlgebra.jl#488 (or rather the bug reported in the comments in JuliaLang/LinearAlgebra.jl#488). As pointed out in the issue discussion,
eigs
is currently broken for generalized eigenvalue problems unlessB
is positive or negative definite, e.g., it normally does not work for non-symmetricB
.The code introduces an
explicittransform
kwarg which provides the possibility to do shift-and-invert in the julia code, or (as before) let ARPACK do it. If you do shift-and-invert in the julia code the problem does not occur. Theexplicittransform
kwarg defaults to:AUTO
which tries to determine if it is a good idea to let ARPACK do the shift-and-invert or do it in julia-code. This way the previous behaviour is accessible to any user usingexplicittransform=false
.I have tried to keep the code such that the meaning of
which
andsigma
is independent ifexplicittransform
is true or false, which created a bit more if-statements than one might expect, but the advantage is that you get consistent meaning like this:After hopefully some discussion on this here I can add it to the function description.