Skip to content

Incorrect gradient with cascaded reshape, linear equation solver operations #506

Closed
@semihakbayrak

Description

@semihakbayrak

For the following function A(η::Array) = η[1:2]'*(reshape(η[2+1:end],(2,2))\η[1:2]), I observed a weird behaviour with ForwardDiff. Suppose that we want to evaluate the gradient at x = [2.0, 2.0, 1.0, 0.0, 0.0, 1.0]. Then ForwardDiff.gradient(A,x) returns the output [4.0, 4.0, -4.0, 0.0, -4.0, -4.0]. However, I would expect 4th element of the gradient to be -4.0. If I change the vector x slightly as [2.0, 2.0, 1.0, 0.00001, 0.00001, 1.0], then the gradient turns out to be correct and I get the output [3.999960000399996, 3.999960000399996, -3.9999200011999845, -3.9999200011999845, -3.9999200011999845, -3.9999200011999845].

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