Tracker.jl icon indicating copy to clipboard operation
Tracker.jl copied to clipboard

Incorrect hessian returned for `prod`

Open sethaxen opened this issue 2 years ago • 1 comments

The (i,j)th element of the Hessian of y=prod(x) is y/x[i]/x[j] for i ≠ j and 0 for i==j, i.e. its diagonal is zero. However,

julia> x = randn(3)
3-element Vector{Float64}:
  0.11546090256645888
  2.4121509171945448
 -1.6103562544798857

julia> Tracker.hessian(prod, x)
Tracked 3×3 Matrix{Float64}:
 33.6428  0.0        0.0
  0.0     0.0770819  0.0
  0.0     0.0        0.172949

I believe this stems from the custom rule Tracker uses for prod.

sethaxen avatar Jan 27 '22 10:01 sethaxen