Fix matrix-function primal type for Hermitian{<:Real} on Julia 1.12#840
Open
CarloLucibello wants to merge 1 commit into
Open
Fix matrix-function primal type for Hermitian{<:Real} on Julia 1.12#840CarloLucibello wants to merge 1 commit into
CarloLucibello wants to merge 1 commit into
Conversation
Julia 1.12 changed real-valued matrix functions of `Hermitian{<:Real}`
(e.g. `exp`, `log`, `sqrt`, `cos`) to return `Hermitian` instead of
`Symmetric`. `_matfun` unconditionally wrapped the real-eltype result as
`Symmetric`, so the rrule/frule primal no longer matched `f(A)`
(FluxML/Zygote.jl#1592).
Wrap the result in the same type as the input when the output is real,
keeping `Symmetric` for the complex-valued case (e.g. `acosh` of
eigenvalues < 1), which Julia still returns as `Symmetric` for both
`Symmetric` and `Hermitian` real inputs. The behavior is unchanged on
Julia < 1.12. The inference assertions in the matrix-function tests are
updated accordingly.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
|
Ref #833 As mentioned in #833 (comment), AD doesn't guarantee that primal values are exactly identical to the values obtained without AD. So it's unclear why |
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.
Summary
Julia 1.12 changed real-valued matrix functions of
Hermitian{<:Real}(e.g.exp,log,sqrt,cos,sin, ...) to returnHermitianinstead ofSymmetric:_matfununconditionally wrapped the real-eltype result asSymmetric, so therrule/fruleprimal no longer matchedf(A). This surfaced as a type mismatch downstream — see FluxML/Zygote.jl#1592:Fix
In
_matfun, when the input is real, wrap the result in the sameSymmetric/Hermitiantype as the input when the output is real. The complex-valued case (e.g.acoshof eigenvalues< 1) is still wrapped asSymmetric, which is what Julia returns for both realSymmetricandHermitianinputs. Behavior on Julia < 1.12 is unchanged (alwaysSymmetric).The inference assertions in the matrix-function tests are updated to expect the input wrapper type on 1.12+.
Testing
Pkg.test(test_args=["symmetric"])passes on Julia 1.12 (5499 tests, 0 errors).🤖 Generated with Claude Code