Skip to content

Perturbation Confusion II: The Tag Wars #313

Open

Description

@jrevels

@vtjnash was able to rewrite the classic perturbation confusion example into a form that thwarts ForwardDiff's tag generation:

julia> using ForwardDiff

julia> const D = ForwardDiff.derivative
derivative (generic function with 4 methods)

julia> struct Confuse
                whoami::Bool
                x
              end

julia> function (c::Confuse)(xy)
                if c.whoami
                  return xy * D(Confuse(false, xy), 1)
                else
                  return c.x + xy
                end
              end

julia> D(Confuse(true, 0), 1) # this should be 1
2

Essentially, since the function type is constant whether or not the function recursively differentiates itself, ForwardDiff generates the same tag for the nested call that it generates for the outer call.

So it seems that sufficiently unique tags cannot be generated from local type information alone...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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