I just learned about Automatic Differentiation and of course need to give it a go using Julia
I have a function defined as:
Wendland(q) = aD*(1-q/2)^4 * (2*q+1)
Where aD in my case is 696.
And its derivative w.r.t. q:
WendlandDerivative(q) = aD*((5/8)*q*(q-2)^3)
By using ForwardDiff and Benchmark package I confirm that I get the same answers but vastly different timings:
using BenchmarkTools using ForwardDiff aD = 696 Wendland(q) = aD*(1-q/2)^4 * (2*q+1) WendlandDerivative(q) = aD*((5/8)*q*(q-2)^3) #Define derivative function using ForwardDiff df = x -> ForwardDiff.derivative(Wendland, x) # Benchmarks @btime WendlandDerivative(u) setup=(u=1.1) 24.397 ns (2 allocations: 32 bytes) -348.82649999999984 @btime df(u) setup=(u=1.1) 121.287 ns (6 allocations: 160 bytes) -348.8264999999999
Am I doing something wrong; perhaps this is not the intented use case of AD? It perhaps works better on scale (i.e. arrays) than for just producing the derivative function and evaluating it a few times?