HI, i’m looking to implement an implace hessian of a vector-valued function, for example:
f(x) = [x[1],x[2],sin(x[1]),sum(x)]
The ForwardDiff Documentation gives an out of place example (slightly wrong, as size(f(x)) !=size(x)
in the general case:
julia> function vector_hessian(f, x)
n = length(x)
out = ForwardDiff.jacobian(x -> ForwardDiff.jacobian(f, x), x)
return reshape(out, n, n, n)
end
the problem arrives when you use a inplace version of the same function:
function f!(res,x)
res .= [x[1],x[2],sin(x[1]),sum(x)]
end
the problem with nested inplace jacobians is that the result of the intermediate jacobian is a dual, and its very difficult to create a cache storage.
Anybody has encountered something like that? how can i create an efficient cache for this type of function?