Skip to content

auto_hesvec #134

Closed
Closed
@ArnoStrouwen

Description

@ArnoStrouwen
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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions