Skip to content

Incorrect computation of Hessian of squared euclidean norm #303

Description

@jomi2801

The computation of the Hessian of the squared euclidean norm results in an interesting output:

using ForwardDiff;
f(x::Vector) = .5*norm(x, 2)^2;
x = zeros(2);
ForwardDiff.hessian(f, x)

which is

 0.0  0.0
 0.0  1.0

However, the codes

f(x::Vector) = .5*x[1]^2 + .5*x[2]^2;
ForwardDiff.hessian(f, x)

and

f(x::Vector) = .5*dot(x, x);
ForwardDiff.hessian(f, x)

provide the correct result. Why is that?

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