Skip to content

Support for ReverseDiff #37

@amrods

Description

@amrods

It'd be great to add support for ReverseDiff. ForwardDiff is great, and even FiniteDiff works fine. But with ReverseDiff I get an error:

using ComponentArrays
using ForwardDiff
using ReverseDiff
using FiniteDiff
using Parameters: @unpack

ca = ComponentArray(x = [1, 2], θ = [1.0, 100.0], deg = 2)

function F(ca)
    @unpack x, θ, deg = ca
    (θ[1] - x[1])^deg + θ[2] * (x[2] - x[1]^deg)^deg
end

gradsF = ForwardDiff.gradient(ca -> F(ca), ca).x
gradsFD = FiniteDiff.finite_difference_gradient(ca -> F(ca), ca).x
gradsR = ReverseDiff.gradient(ca -> F(ca), ca).x
# ERROR: type TrackedArray has no field x

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