I use ForwardDiff.jacobian
in the following way:
function _jacobian_ad_forward(p, t0, u0_ode, du_ode, config)
J = ForwardDiff.jacobian(du_ode, u0_ode, config) do du_ode, u_ode
f!(du_ode, u_ode, p, t0)
end
return J
end
where my Jacobian J
is typically very sparse.
I am aware of SparseDiffTools.jl which offers a sparse Jacobian computation based on a to-be-supplied sparsity pattern.
To my understanding SparseDiffTools.jl
does computations then only for the non-zero entries according to the sparsity pattern.
In my case, obtaining the sparsity pattern is not easy without major refactoring of the code behind f
.
Also, the actual computation of the Jacobian is not too time consuming, I am more worried about the memory requirements for storing entire J
.
Thus, my question: Is it possible to use ForwardDiff.jacobian
(or a related function) such that only the non-zero outcomes are stored (in a sparse format)?