From facf227afd577cf8d7bee7a1c1bb885b18fb53a0 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sun, 6 Apr 2025 12:50:36 +0200 Subject: [PATCH] Safely initialize the inplace Jacobian cache This fixes support for BigFloat in LsqFit.jl, ForwardDiff.jl requires that the array is initialized. --- src/objective_types/oncedifferentiable.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/objective_types/oncedifferentiable.jl b/src/objective_types/oncedifferentiable.jl index 69c3345..f19abc0 100644 --- a/src/objective_types/oncedifferentiable.jl +++ b/src/objective_types/oncedifferentiable.jl @@ -79,6 +79,12 @@ function OnceDifferentiable(f, x_seed::AbstractArray, F::AbstractArray, DF::Abst return OnceDifferentiable(fF, dfF, fdfF, x_seed, F, DF) else F2 = similar(F) + # Note that we fill the array to ensure that no elements are + # uninitialized, e.g. in the case of BigFloat which is not an isbits + # type. ForwardDiff requires that the array is fully initialized: + # https://github.com/JuliaDiff/ForwardDiff.jl/issues/740 + fill!(F2, zero(eltype(F2))) + backend = get_adtype(autodiff, chunk) jac_prep = DI.prepare_jacobian(f, F2, backend, x_seed) function j!(_j, _x)