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

impossible to differentiate over integer array

Open lliill opened this issue 5 years ago • 2 comments

l(xu) = sum(sqrt(i^2 + 1) for i in xu) xu = Vector(1:6) result = DiffResults.HessianResult(xu)

result = ForwardDiff.hessian!(result, l, xu) will give InexactError: Int64(Int64, 22.11744686954993)

Problem will be solve if xu = Vector{Float64}(1:6)

lliill avatar Apr 10 '19 15:04 lliill

You're right, this gives an error, but there is a good reason. The result is created from integers, but the output of the function is promoted to float.

Enforcing that the result keeps the same number types is a good thing for type-stability, and that's why I don't think it would be a good idea to change that

gdalle avatar Mar 15 '24 18:03 gdalle

Reopening because a warning in the docs might make sense

gdalle avatar Mar 15 '24 18:03 gdalle