Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler defaults without FiniteDifferences special cases #96

Merged
merged 3 commits into from
Sep 21, 2023

Conversation

devmotion
Copy link
Member

IMO the AbstractFiniteDifference special cases in the default definitions are confusing (see #94...) and lead to code that is less idiomatic and more difficult to optimize.

With increasing dimensionality, avoiding one additional computation of the primal matters less and less, and hence this PR proposes to disentangle the computation of the primal and the jacobian/Hessian/etc. Moreover, also with these changes one can improve performance for individual backends, if possible and desired, by defining a more optimized value_and_jacobian etc.

An additional advantage for higher-order calls value_and_hessian and value_gradient_and_hessian is that it is sufficient to call gradient instead of value_and_gradient.

@codecov
Copy link

codecov bot commented Jul 29, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -1.30% ⚠️

Comparison is base (3c18e86) 84.12% compared to head (4c55550) 82.82%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #96      +/-   ##
==========================================
- Coverage   84.12%   82.82%   -1.30%     
==========================================
  Files           8        8              
  Lines         466      425      -41     
==========================================
- Hits          392      352      -40     
+ Misses         74       73       -1     
Files Changed Coverage Δ
src/AbstractDifferentiation.jl 78.18% <100.00%> (-0.28%) ⬇️

... and 3 files with indirect coverage changes

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

@gdalle
Copy link
Member

gdalle commented Sep 20, 2023

I'm strongly in favor of more simplicity at the expense of a little performance.
I think there might be a conflict with #93 though, gonna try to do the merge

@devmotion
Copy link
Member Author

Ah, missed that there's a merge conflict. I'll fix it.

@devmotion
Copy link
Member Author

The merge conflicts are fixed, the PR is ready for review 🙂

Copy link
Member

@gdalle gdalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, apart from the deletion in the @primitive macro, which I don't understand.
Although to be fair I don't understand the macro as a whole. Why do we only have 2 out of 5 (now 4) ..._and_friends functions defined in the package? Where are the rest?

src/AbstractDifferentiation.jl Show resolved Hide resolved
@devmotion devmotion merged commit 9e7e07b into master Sep 21, 2023
@devmotion devmotion deleted the dw/simpler_default branch September 21, 2023 21:03
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.

2 participants