Skip to content

wrong derivative with array concatenation #145

Closed

Description

@andrewning

My code used to work in ReverseDiff 1.2.0 but the current version (1.4.2) returns the wrong derivatives. I've stripped away everything to a MWE:

import ForwardDiff
import ReverseDiff

struct Test{TF}
    a::TF
end

function func(x)
    tvec = Test.(x[1:2])
    a = [t.a for t in tvec]
    return sum([a; x[3]])
end

x = [1.0, 2.0, 3.0]
J1 = ForwardDiff.gradient(func, x)
J2 = ReverseDiff.gradient(func, x)

The answer should be [1, 1, 1], but ReverseDiff gives [0, 0, 1]. If I revert back to 1.2 then it works as expected. Trying different versions it seems that from 1.3 onward this no longer works.

Activity

  1. mohdibntarek commented on Sep 21, 2020

    @mohdibntarek
    Member

    I think I know what's happening here. I will work on a fix soon.

  2. devmotion commented on Sep 18, 2026

    @devmotion
    Member

    Fixed by #169. #300 will add a regression test.

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