Gradients
The supertype Gradient comprises different ways of taking gradients:
We first start by showing GradientAutodiff:
f(x::AbstractArray) = sum(x .^ 2)
x = rand(3)
grad = GradientAutodiff(f, x)GradientAutodiff{Float64, typeof(Main.f), ForwardDiff.GradientConfig{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3, Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3}}}}(Main.f, ForwardDiff.GradientConfig{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3, Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(Main.f), Float64}, 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{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3}[Dual{ForwardDiff.Tag{typeof(Main.f), Float64}}(6.9223801607803e-310,5.0e-324,6.9223352690971e-310,6.922333995818e-310), Dual{ForwardDiff.Tag{typeof(Main.f), Float64}}(6.92233526908444e-310,6.9223858078736e-310,6.92238867355793e-310,6.92233526887733e-310), Dual{ForwardDiff.Tag{typeof(Main.f), Float64}}(6.92233526906863e-310,6.9223340561992e-310,6.92233405629004e-310,6.92233526906863e-310)]))Every struct derived from Gradient (including GradientAutodiff) has an associated functor:
grad(x)3-element Vector{Float64}:
1.042427591070766
1.1736135149066969
1.7817573961855622