DiffResults.jl
DiffResults.jl copied to clipboard
impossible to differentiate over integer array
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)
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
Reopening because a warning in the docs might make sense