-
Notifications
You must be signed in to change notification settings - Fork 16
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
manual "backend" #634
Comments
It can definitely be done but it's a bit off the beaten path. struct ManualBackend <: ADTypes.AbstractADType end
function myfunc(x)
# stuff
end
function DI.derivative(::typeof(myfunc), ::ManualBackend, x)
# explicit formula
end
function DI.value_and_derivative(::typeof(myfunc), ::ManualBackend, x)
# explicit formula
end
# other variants or other operators Does that make sense to you? |
Yes, it makes sense, I was thinking of something like this, but using a wrapper struct ManualBackendDifferentiable{TV,TD,TVD,...}
value::TV
derivative::TD
value_and_derivative::TVD
...
end
function DI.value_and_derivative(mbd::ManualBackendDifferentiable, ::ManualBackend, x)
(; value_and_derivative, value, derivative) = mbd
if value_and_derivative === nothing
value(x), derivative(x)
else
value_and_derivative(x)
end
end and similar, allowing to user to supply the required parts separately or together.
I fully agree, the advantage would be exposing just one interface (that of DI) while still allowing the user to do this. That said, in case the need arises this can be done for specific derivative combinations very easily in user code on an ad-hoc basis. So maybe a simple example in the manual would be enough for a start. |
I had the wrapper idea too at first, but why ask the user to provide their own |
I am transitioning my packages to use DifferentiationInterface. I would like allow the user to specify derivatives manually though: either for testing purposes, or for simple problems where it makes sense.
Can this be done with DI in its current state? (sorry if I missed something obvious, I read the docs and part of the source)
The text was updated successfully, but these errors were encountered: