This should actually work - I believe you’ve run into a ReverseDiff bug. Definitely worth filing an issue! It seems like ReverseDiff isn’t promoting element types correctly for operations between, for example, Array{<:Dual}
and TrackedArray{<:Float}
.
It’s actually quite tough to get these kind of promotion rules right without a tagging system for Dual
s, so in some cases, ReverseDiff employed hand-wavy hacks for steering the behavior of nested perturbations. While these stopgap solutions didn’t directly cause this particular bug, the lack of a robust solution makes these kind of bugs hard to prevent. Fortunately, now that ForwardDiff’s Dual
type supports a tagging system, I can cook up a rigorous implementation of the correct behavior.
As an aside, ReverseDiff’s @forward
macro only covers scalar derivatives at the moment, but I’d like it to eventually handle gradients and Jacobians as well. ReverseDiff is undergoing an extensive overhaul this summer, so stay tuned…