From e6194443d9e7e544a803b6c9c99e2d24785e650a Mon Sep 17 00:00:00 2001 From: ChrisRackauckas Date: Sat, 9 Aug 2025 06:05:17 -0400 Subject: [PATCH] Fix reltol type instability in Newton solver The issue was that reltol could be either a scalar (when adaptive=false) or the value from integrator.opts.reltol (which could be scalar or vector). This runtime branch caused type instability. The fix checks both conditions at once to ensure reltol is only set to eps(eltype(dz)) when it would actually be a scalar, avoiding the type instability when reltol is a vector. Fixes part of issue #2819 --- lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl index 00c633ba8d..0a4f07200c 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl @@ -246,10 +246,10 @@ end update_coefficients!(W, ustep, p, tstep; dtgamma = γW, transform = true) end - if integrator.opts.adaptive - reltol = integrator.opts.reltol - else + if !integrator.opts.adaptive && !(integrator.opts.reltol isa AbstractArray) reltol = eps(eltype(dz)) + else + reltol = integrator.opts.reltol end if is_always_new(nlsolver) || (iter == 1 && new_W)