Skip to content

ReverseDiff doesn't work for noop f(x)=x #59

@pkofod

Description

@pkofod
julia> x_seed = [1.0]
1-element Array{Float64,1}:
 1.0

julia> f(x) = x
f (generic function with 1 method)

julia> gcfg = ReverseDiff.GradientConfig(x_seed)
ReverseDiff.GradientConfig

julia> g! = (x, out) -> ReverseDiff.gradient!(out, f, x, gcfg)
(::#17) (generic function with 1 method)

julia> g!([1.0], [0.0])
1-element Array{Float64,1}:
 0.0

julia> f(x) = 1.0*x
f (generic function with 1 method)

julia> g!([1.0], [0.0])
1-element Array{Float64,1}:
 1.0

julia> f(x) = 3.0*x
f (generic function with 1 method)

julia> g!([1.0], [0.0])
1-element Array{Float64,1}:
 3.0

Granted, not the most interesting function in the world, but there must be something that you're missing here, since it doesn't think the function changes with 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