I’m attempting to use ForwardDiff in a function that involves several instances of pre-allocating vectors. I’ve boiled the function down to the cause of the bug
using ForwardDiff function f(x) tmp = zeros(2) for i in 1:2 tmp[i] = x[i] * i end return tmp end ForwardDiff.jacobian(f, [4.7 5.7])
Any ideas on how I can fix this issue? In this case, rewriting the function as
function f(x) tmp = [x * 1 x * 2] return tmp end
fixes the problem, but in my use case, this solution isn’t feasible since the size of the output vector depends on other inputs.