ForwardDiff.jl: Compute J_f(x) * f(x)

There are some discussions how to compute the Jacobian-vector product J_f(x) * y for a function f efficiently with ForwardDiff.jl, e.g., Calculating J_f(x) . y efficiently · Issue #319 · JuliaDiff/ForwardDiff.jl · GitHub
I have a use case where I would like to use the value f(x) for the vector y. Using the approach described there, I basically need to compute f(x) first and then the Jacobian-vector product J_f(x) * f(x). However, the latter will also compute f(x) as part of the expression, of course.

Does anybody know a more efficient way to compute the special Jacobian-vector product J_f(x) * f(x) using ForwardDiff.jl?

1 Like

I’m not sure there will be an extra trick here, since you’d need to compute f(x) before the AD pass in order to seed it properly.

1 Like

That’s my current guess, too, but I’m not an AD expert. That’s why I ask. There are sometimes really clever tricks people come up with, in particular in Julia forums like this :slightly_smiling_face:

1 Like