Repository navigation
Conversation
At Hermitian `A`, the `eigen`/`eigvals` rules for `StridedMatrix` delegated to the rules for `Hermitian(A)`. The resulting (co)tangents were those of `x -> eigen(Hermitian(x))`, which only reads the upper triangle, so they were wrong for unstructured matrices (FluxML/Zygote.jl#1369). Now the eigenvalue (co)tangents are `uᵢ' ΔA uᵢ` and `U Diagonal(Δλ) U'`, with the type of the primal eigenvalues. The eigenvectors are only differentiable along Hermitian directions (phase convention of the Hermitian solver), so their (co)tangents use the Hermitian part. This also fixes the failures on Julia 1.14, where LinearAlgebra.jl#1717 made eigenvalues of complex matrices complex also for Hermitian matrices, and removes a `Core.Box` in the `eigen` pullback that broke inference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #853 +/- ##
==========================================
+ Coverage 96.57% 96.64% +0.06%
==========================================
Files 28 28
Lines 3618 3604 -14
==========================================
- Hits 3494 3483 -11
+ Misses 124 121 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Reuse the cotangent buffer for the product with the eigenvectors in the `eigen` pullback for Hermitian matrices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
devmotion
marked this pull request as ready for review
October 23, 2026 21:46
devmotion
commented
Oct 23, 2026
This branch has not been deployed
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.
At a Hermitian
A, theeigen/eigvalsfrules and rrules forStridedMatrixdelegated to the rules forHermitian(A). Their (co)tangents are those ofx -> eigen(Hermitian(x)), which reads only the upper triangle ofx. That is wrong for unstructured matrices: the rrules returned upper-triangular cotangents and the frules ignored the lower triangle ofΔA(FluxML/Zygote.jl#1369).This PR:
uᵢ' ΔA uᵢand cotangentsU Diagonal(Δλ) U', with the type of the primal eigenvalues (so they are only projected onto the reals when the primal eigenvalues are real-typed).A,eigenuses the Hermitian solver, whose eigenvectors follow a different phase convention than those of non-Hermitian matrices. They are therefore only differentiable along Hermitian directions, so the rules use the Hermitian part of the eigenvector (co)tangents (and the Hermitian phase convention).V'instead ofV \sinceVis unitary);_sorteig!_fwdbecame unused and is removed.pre): LinearAlgebra.jl#1717 made eigenvalues of complex matrices complex-typed also on the Hermitian path, so the old rules returned real tangents for complex primals. It also exposed aCore.Boxin theeigenpullback (self-recursive thunk method), which made theeigvalsrrule non-inferable; the pullback is now a single method.eigvals(whenever the eigenvalue type admits all directions) and ofeigen ∘ hermitianpartfor eigenvectors, with non-HermitianΔA, instead ofx -> eigen(Matrix(Hermitian(x))). Includes a regression test for Zygote#1369 (∇ sum(eigvals(A)) == I).Supersedes #841 (thanks @CarloLucibello for the analysis there), which fixed the values-only rrule for real matrices.
Verified locally:
rulesets/LinearAlgebra/factorizationpasses on Julia 1.10, 1.13 and 1.14.0-alpha1 (the new tests fail against the released version).🤖 Generated with Claude Code