Skip to content

fix(FiniteDiff): use fdhtype for hvp to match hessian accuracy#1022

Open
bdrhill wants to merge 2 commits into
JuliaDiff:mainfrom
bdrhill:bh/fix-finitediff-hvp
Open

fix(FiniteDiff): use fdhtype for hvp to match hessian accuracy#1022
bdrhill wants to merge 2 commits into
JuliaDiff:mainfrom
bdrhill:bh/fix-finitediff-hvp

Conversation

@bdrhill
Copy link
Copy Markdown

@bdrhill bdrhill commented May 21, 2026

Summary

  • Implements custom hvp, hvp!, gradient_and_hvp, and gradient_and_hvp! for AutoFiniteDiff
  • Uses fdhtype (default Val(:hcentral)) for the Hessian computation instead of the generic JVP-of-gradient fallback which used fdtype (default Val(:forward))
  • The forward-over-forward finite difference composition caused significant precision loss

Fixes #1012

Test plan

🤖 Generated with Claude Code

Route hvp through fdhtype (default Val(:hcentral)) instead of the
generic JVP-of-gradient fallback which used fdtype (default Val(:forward)).
The forward-over-forward finite difference composition loses precision.

Fixes JuliaDiff#1012

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bdrhill bdrhill requested a review from gdalle as a code owner May 21, 2026 22:13
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.15%. Comparing base (cbfeb7c) to head (fede0bd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1022      +/-   ##
==========================================
+ Coverage   98.14%   98.15%   +0.01%     
==========================================
  Files         138      138              
  Lines        8131     8194      +63     
==========================================
+ Hits         7980     8043      +63     
  Misses        151      151              
Flag Coverage Δ
DI 98.87% <100.00%> (+0.01%) ⬆️
DIT 96.22% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

- Fix matrix input handling by using vec/reshape for proper dimensions
- Enable hvp tests in test_differentiation (remove from excluded)
- Add step size tests for prepare_hvp
- Add explicit HVP accuracy tests for issue JuliaDiff#1012

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Bug(FiniteDiff): hvp accuracy under AutoFiniteDiff() defaults disagrees with hessian

1 participant