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
Lanczos algorithm for symmetric/Hermitian matrices #370
Conversation
One aspect of |
Let's please fix up the interface in this PR. |
That would change one matrix multiply to O(n) instead of O(n^3) via the dense multiply and also save some memory (which is arguably more important for PDEs). I would do this if it isn't difficult. |
Oh I'm not aware of this. I was reading the docs on matrix factorizations (e.g. https://docs.julialang.org/en/latest/NEWS.html#Deprecated-or-removed-1 The lesson for me then is I should start reading the v0.7 docs and pay attention to the changes :P Speaking of which, need to remind myself that |
Yes. |
Codecov Report
@@ Coverage Diff @@
## master #370 +/- ##
==========================================
+ Coverage 83.63% 83.67% +0.03%
==========================================
Files 75 75
Lines 21589 21615 +26
==========================================
+ Hits 18057 18087 +30
+ Misses 3532 3528 -4
Continue to review full report at Codecov.
|
Initially I just changed all The reason is that in order to optimize And of course |
Yup sounds good. |
Performance comparison: using OrdinaryDiffEq: KrylovSubspace, getH, arnoldi!, expv! n = 1000
m = 50
srand(0)
A = full(Hermitian(randn(n, n)))
Aperm = A + 1e-10 * randn(n, n) # No longer Hermitian
b = randn(n)
t = 1e-3
Ks = KrylovSubspace{Float64}(n, m)
Ksperm = KrylovSubspace{Float64}(n, m)
w = similar(b)
wperm = similar(b)
arnoldi_cache = similar(b)
expv_cache = zeros(m, m); Arnoldi/Lanczos iteration step: @time arnoldi!(Ks, A, b; m=m, cache=arnoldi_cache);
@time arnoldi!(Ksperm, Aperm, b; m=m, cache=arnoldi_cache);
ishermitian(getH(Ks))
ishermitian(getH(Ksperm))
@time expv!(w, t, Ks, cache=expv_cache);
@time expv!(wperm, t, Ksperm, cache=expv_cache);
w ≈ wperm
Again, in the Arnoldi/Lanczos step the difference is small because Lanczos only saves some O(n) operations while the bottleneck lies in |
Most likely, yes. Also large BandedMatrix, TridiagonalMatrix, etc. types. |
For symmetric/Hermitian
A
, we know that Arnoldi iteration will produce anH
that is also real symmetric. The Lanczos algorithm improves upon Arnoldi by not calculating the zero elements of the upper part ofH
, thus saving time.Note that the difference in time is not big: Arnoldi/Lanczos iteration is, after all, bounded in time by
A_mul_B!
. What Lanczos saves is just a bunch of dot products andaxpy!
updates.Nevertheless, it's still valuable to have
lanczos!
around because it guarantees the resultsKs[:H]
is real symmetric, which can speed up later calculations. For example,expm
is able to use diagonalization for Hermitian matrices: