New differentiation rules for ForwardDiff

differentiation

#1

Is there currently an “official” way to add differentiation rules to be used by ForwardDiff?
This was discussed a few months ago here:


which pointed to DiffRules.@define_diffrule.
I managed to get my new rule to work with

using DiffRules: @define_diffrule
using ForwardDiff
@define_diffrule Main.q(s,r) = :(Main.qs($s,$r)), :(Main.qr($s,$r))
ForwardDiff.eval(ForwardDiff.binary_dual_definition(:Main,:q))

but that seems a bit hacky. Is there a better way?

My reason for defining a rule manually is that q is not auto-differentiable and I have several functions defined in terms of q that I would like to automatically differentiate using the “manually” computed derivatives of q.