From 16d66b1933c6b562dc3aada375cc6d51c97a6e54 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sat, 5 Oct 2024 10:25:55 -0400 Subject: [PATCH 1/3] fix: don't use similar on prototype --- Project.toml | 2 +- src/internal/jacobian.jl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index d8ec44ac1..1651aab2a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NonlinearSolve" uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" authors = ["SciML"] -version = "3.15.0" +version = "3.15.1" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/src/internal/jacobian.jl b/src/internal/jacobian.jl index 390c0947f..0ab1286d1 100644 --- a/src/internal/jacobian.jl +++ b/src/internal/jacobian.jl @@ -92,13 +92,13 @@ function JacobianCache(prob, alg, f::F, fu_, u, p; stats, autodiff = nothing, end end else - jac_proto = if eltype(f.jac_prototype) <: Bool - similar(f.jac_prototype, promote_type(eltype(fu), eltype(u))) + if eltype(f.jac_prototype) <: Bool + jac_proto = similar(f.jac_prototype, promote_type(eltype(fu), eltype(u))) + fill!(jac_proto, false) + jac_proto else - similar(f.jac_prototype) + f.jac_prototype end - fill!(jac_proto, false) - jac_proto end end From b5981e2c8fed67b3071a787022aa277efb6be2d3 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sat, 5 Oct 2024 10:33:48 -0400 Subject: [PATCH 2/3] fix: use a copy --- src/internal/jacobian.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/internal/jacobian.jl b/src/internal/jacobian.jl index 0ab1286d1..0f885de47 100644 --- a/src/internal/jacobian.jl +++ b/src/internal/jacobian.jl @@ -92,12 +92,11 @@ function JacobianCache(prob, alg, f::F, fu_, u, p; stats, autodiff = nothing, end end else + # NOTE: don't use similar because that might lead to an unwrapped array if eltype(f.jac_prototype) <: Bool - jac_proto = similar(f.jac_prototype, promote_type(eltype(fu), eltype(u))) - fill!(jac_proto, false) - jac_proto + promote_type(eltype(fu), eltype(u)).(f.jac_prototype) else - f.jac_prototype + copy(f.jac_prototype) end end end From 834516a74acea89793562a7bf380d276a696cb48 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sat, 5 Oct 2024 14:05:52 -0400 Subject: [PATCH 3/3] fix: partial revert of previous fix --- src/internal/helpers.jl | 5 ++--- src/internal/jacobian.jl | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/internal/helpers.jl b/src/internal/helpers.jl index afc24ce5b..5334f11dc 100644 --- a/src/internal/helpers.jl +++ b/src/internal/helpers.jl @@ -1,9 +1,8 @@ # Evaluate the residual function at a given point function evaluate_f(prob::AbstractNonlinearProblem{uType, iip}, u) where {uType, iip} - (; f, u0, p) = prob + (; f, p) = prob if iip - fu = f.resid_prototype === nothing ? zero(u) : - promote_type(eltype(u), eltype(f.resid_prototype)).(f.resid_prototype) + fu = f.resid_prototype === nothing ? zero(u) : similar(f.resid_prototype) f(fu, u, p) else fu = f(u, p) diff --git a/src/internal/jacobian.jl b/src/internal/jacobian.jl index 0f885de47..b78eb7383 100644 --- a/src/internal/jacobian.jl +++ b/src/internal/jacobian.jl @@ -92,11 +92,10 @@ function JacobianCache(prob, alg, f::F, fu_, u, p; stats, autodiff = nothing, end end else - # NOTE: don't use similar because that might lead to an unwrapped array if eltype(f.jac_prototype) <: Bool - promote_type(eltype(fu), eltype(u)).(f.jac_prototype) + similar(f.jac_prototype, promote_type(eltype(fu), eltype(u))) else - copy(f.jac_prototype) + similar(f.jac_prototype) end end end