Closed
Description
using ForwardDiff
function seed_duals(x::AbstractArray{V},::Type{T},::ForwardDiff.Chunk{N} = ForwardDiff.Chunk(x,typemax(Int64))) where {V,T,N}
seeds = ForwardDiff.construct_seeds(ForwardDiff.Partials{N,V})
duals = [ForwardDiff.Dual{T}(x[i],seeds[i]) for i in eachindex(x)]
end
function g(x)
x[1]^3*x[2]^3
end
x = [2.0, 3.0]
v = [4.0, 5.0]
ForwardDiff.gradient(g,x)'*v # 2376
ForwardDiff.hessian(g,x)*v # 2916 2016
test1 = seed_duals(Dual{Nothing}.(x,v),Nothing)
ForwardDiff.partials.(g(test1).partials)
test2 = Dual{Nothing}.(seed_duals(x,Nothing),v)
g(test2).partials[1].partials
Does these make sense?
Metadata
Metadata
Assignees
Labels
No labels