I’ve distilled my use case into a simple example. Essentially, I have an outer function that takes an input and generates a scalar from an inner function. I want ForwardDiff to treat this scalar as a constant when taking the derivative of the outer function, but ForwardDiff is (correctly) tracing the input through the inner function. How can I get ForwardDiff to “ignore” the inner function? I’ve tried deep-copying, but that doesn’t do the trick. Some example code:
using ForwardDiff function f1(x) return g(x) end function f2(x) scalar = deepcopy(g(x)); return scalar; end function g(x) return x^2 end ForwardDiff.derivative(f1,3) # => 6 ForwardDiff.derivative(f2,3) # => 6, want this to be 0
f2, I want ForwardDiff to great
g(x) as a constant, and thus the derivative with respect to
x should be zero. Thanks in advance for any help!