Jacobians

The supertype Jacobian comprises different ways of taking Jacobians:

We first start by showing JacobianAutodiff:

# the input and output dimensions of this function are the same
F(y::AbstractArray, x::AbstractArray, params) = y .= tanh.(x)
dim = 3
x = rand(dim)
jac = JacobianAutodiff{eltype(x)}(F, dim)
JacobianAutodiff{Float64, typeof(Main.F), ForwardDiff.JacobianConfig{Nothing, Float64, 3, Tuple{Vector{ForwardDiff.Dual{Nothing, Float64, 3}}, Vector{ForwardDiff.Dual{Nothing, Float64, 3}}}}, Vector{Float64}}(Main.F, ForwardDiff.JacobianConfig{Nothing, Float64, 3, Tuple{Vector{ForwardDiff.Dual{Nothing, Float64, 3}}, Vector{ForwardDiff.Dual{Nothing, Float64, 3}}}}((Partials(1.0, 0.0, 0.0), Partials(0.0, 1.0, 0.0), Partials(0.0, 0.0, 1.0)), (ForwardDiff.Dual{Nothing, Float64, 3}[Dual{Nothing}(6.9395310259799e-310,5.0e-324,6.93942019720464e-310,6.93948060171635e-310), Dual{Nothing}(6.9395395074084e-310,6.9395356235939e-310,6.93953674168507e-310,6.9394201964568e-310), Dual{Nothing}(6.9394201971904e-310,6.9395360965444e-310,6.93942200537107e-310,6.9394201971904e-310)], ForwardDiff.Dual{Nothing, Float64, 3}[Dual{Nothing}(6.9395310259799e-310,6.93942019347503e-310,6.9395430073022e-310,6.9394804592713e-310), Dual{Nothing}(1.388e-320,1.9469e-319,1.0885921621903e-311,7.746817145885188e-304), Dual{Nothing}(5.0e-324,6.9395352680113e-310,0.0,6.9394804592642e-310)])), [0.0, 0.0, 0.0])

When calling an instance of Jacobian we can use the function [compute_jacobian!]:

params = nothing
j = zeros(dim, dim)
compute_jacobian!(j, x, jac, params)
3×3 Matrix{Float64}:
 0.770907  0.0       0.0
 0.0       0.721643  0.0
 0.0       0.0       0.493302

This is equivalent to calling:

jac(j, x, params)
3×3 Matrix{Float64}:
 0.770907  0.0       0.0
 0.0       0.721643  0.0
 0.0       0.0       0.493302