-
Notifications
You must be signed in to change notification settings - Fork 146
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
Add single-pass value_and_derivative(s) functions #678
base: master
Are you sure you want to change the base?
Conversation
CI failures seem to be unrelated to these changes |
I wonder if |
If it's acceptable for that package to rely on these ForwardDiff internals, I don't mind making the change in there. Just, can we add a higher-order |
My bad. I got it wrong: that signature is for multiple function arguments; not for higher-order derivatives. There's a |
I had a few minutes to play around with making these changes in While implementing the changes in |
Gentle bump @devmotion; are you willing to consider adding these functions to this package? (regardless of whether equivalent functions go into AbstractDifferentiation too) |
IMO there is no need for duplicate definitions, in particular given that the long-term goal of AbstractDifferentation is to move the extensions to the relevant packages (i.e., Zygote, Tracker, ForwardDiff etc.). |
Closes #610.
Proposal
I propose adding a
value_and_derivative
function for easy single-pass computation of value and derivative that has the same signature asderivative
but returns a plain tuple. I also propose avalue_and_derivatives
function that also includes the second derivative. I'm not proposing methods for even higher order derivatives (honestly because I don't have a need for those), but if needed these could be added in the future via an optional argument (e.g. aVal{n}
) invalue_and_derivatives
.Rationale
The rationale is the one I presented in #610. To mention it here, using the
DiffResults
API (which is intended for these use cases) for very simple scalar derivatives is somewhat convoluted, crucially requiring knowledge of the return types of the differentiated function ahead of time instead of just being able to let the compiler deal with the types.This has caused implementations of functions like
value_and_derivative
to appear in other packages (including mine); but these have to rely on internals ofForwardDiff
(i.e.,Dual
and related functions), which is not ideal.Naming
I considered the names
value_and_derivative
andvalue_derivative
. I decided on the former as that's the name that was chosen in theAbstractDifferentiation
package.Background
Initially I wanted to register a wrapper package with this functionality, but Registry maintainers asked me to consider a PR here instead. I agree and I hope these changes can be merged here.