JuliaDiff / FiniteDiff.jl

Fast non-allocating calculations of gradients, Jacobians, and Hessians with sparsity support
http://juliadiff.org/FiniteDiff.jl/
Other
247 stars 38 forks source link

Cannot reuse `HessianCache` for another value of `x` #185

Closed gdalle closed 5 months ago

gdalle commented 5 months ago
julia> using FiniteDiff

julia> f(x) = sum(abs2, x)
f (generic function with 1 method)

julia> x1, x2 = float.(1:4), float.(5:8);

julia> FiniteDiff.finite_difference_hessian(f, x1, FiniteDiff.HessianCache(x1))
4×4 LinearAlgebra.Symmetric{Float64, Matrix{Float64}}:
 2.0  0.0  0.0  0.0
 0.0  2.0  0.0  0.0
 0.0  0.0  2.0  0.0
 0.0  0.0  0.0  2.0

julia> FiniteDiff.finite_difference_hessian(f, x1, FiniteDiff.HessianCache(x2))
4×4 LinearAlgebra.Symmetric{Float64, Matrix{Float64}}:
 1.61061e10  0.0  0.0  0.0
 0.0         2.0  0.0  0.0
 0.0         0.0  2.0  0.0
 0.0         0.0  0.0  2.0
gdalle commented 5 months ago

Awesome, thanks! Can we tag a release?

ChrisRackauckas commented 5 months ago

Tagged a half hour before you asked https://github.com/JuliaRegistries/General/pull/105009