Use non-mutating eigen in expT! to avoid corrupting the Lanczos diagonal - #278
Open
KristofferC wants to merge 2 commits into
Open
Use non-mutating eigen in expT! to avoid corrupting the Lanczos diagonal#278KristofferC wants to merge 2 commits into
eigen in expT! to avoid corrupting the Lanczos diagonal#278KristofferC wants to merge 2 commits into
Conversation
LAPACK stegr! overwrites its diagonal input, and α is a view into Ks.H, so eigen! corrupted α[1:j] for all subsequent Lanczos iterations, giving wrong results and spurious early termination in error-estimate mode since v1.34.0. The pre-SciML#258 workspace path copied α first; non-mutating eigen restores that behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Inside the testset (a local scope), the assignment `w = similar(v)` in the inner function `fullexp` captures and overwrites the testset-local `w` holding the expv result, so `norm(w - w′)` compared the dense exponential with itself and was always exactly 0. Rename the inner variable so the test actually checks the Krylov result. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since v1.34.0,
expT!callseigen!(SymTridiagonal(α, β))whereαis a view intoKs.H. LAPACK'sstegr!overwrites its diagonal input, so each call corruptsα[1:j]— every subsequent Lanczos iteration in the error-estimate variant ofexpv!then diagonalizes garbage, giving wrong results and spurious early termination on all Julia versions. The pre-#258 workspace path was unaffected because it copied first (copyto!(sw.dv, α)); #258 replaced it with the mutatingeigen!. Using non-mutatingeigenrestores correctness.Evidence (Julia 1.12, seeded n=300 Hermitian, the "Alternative Lanczos expv Interface" setup, error vs dense
exp):-19.894705577535643 - 210.2630548621702im-18.6848732770996 - 210.70186885565363imWhy CI never caught this: the "Alternative Lanczos expv Interface" testset is vacuous. Inside the testset (a local scope), the inner function
does not create a local
w— it captures and overwrites the testset-localwholding theexpvresult.δw = norm(w - w′)then compares the dense exponential with itself (w === w′), soδwis exactly0.0no matter how wrongexpvis. The second commit renames the inner variable so the test actually checks the Krylov result; with the fix here the honest testset passes (and it fails against current master, err ≈ 13 vs the 1e-10 tolerance).🤖 Generated with Claude Code