Skip to content

Use natural tangents in Matrix(::HermOrSym) rules - #856

Open
devmotion wants to merge 1 commit into
mainfrom
dmw/symherm-natural-tangents
Open

devmotion wants to merge 1 commit into
mainfrom
dmw/symherm-natural-tangents

Conversation

@devmotion

@devmotion devmotion commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

FiniteDifferences 0.12.35 (JuliaDiff/FiniteDifferences.jl#252, fixing JuliaDiff/FiniteDifferences.jl#164) changed to_vec(::Symmetric/Hermitian) so finite differencing gives natural tangents (Δ + Δ')/2. Before, it gave structural tangents that counted the off-diagonals twice. The Matrix(::HermOrSym) rules were written to match the old behaviour, so their tests fail with FD 0.12.35.

This PR makes the frule and rrule for Matrix/Array of a Symmetric/Hermitian project with ProjectTo(A), which returns the natural tangent. That replaces the hand-written _symherm_forward/_symherm_back logic in these rules. The _symmetric_back/_hermitian_back helpers stay for the Symmetric(A, uplo)/Hermitian(A, uplo) constructor rrule, whose pullback is not a projection.

Closes #475. Unblocks #783.

🤖 Generated with Claude Code

The frule and rrule for `Matrix`/`Array` of a `Symmetric`/`Hermitian` now
project with `ProjectTo(A)`, giving the natural tangent `(Δ + Δ')/2` instead
of the structural one that double-counted off-diagonals. This matches
FiniteDifferences 0.12.35, whose `to_vec(::Symmetric/Hermitian)` now yields
natural tangents. Re-enables the `prod` tests on `Symmetric` (#475).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.63%. Comparing base (69cd550) to head (f3ca8d4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #856      +/-   ##
==========================================
- Coverage   96.64%   96.63%   -0.02%     
==========================================
  Files          28       28              
  Lines        3605     3594      -11     
==========================================
- Hits         3484     3473      -11     
  Misses        121      121              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests for rrule(prod, ::Symmetric) are disabled because they fail

1 participant