Skip to content

Commit f4a7871

Browse files
committed
Don't specialize on original and stats for polyalg
1 parent 28edcd4 commit f4a7871

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NonlinearSolve"
22
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
33
authors = ["SciML"]
4-
version = "3.8.2"
4+
version = "3.8.3"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/default.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ end
156156
$(u_result_syms[i]) = $(sol_syms[i]).u
157157
end
158158
fu = get_fu($(cache_syms[i]))
159-
return SciMLBase.build_solution(
159+
return __build_solution_less_specialize(
160160
$(sol_syms[i]).prob, cache.alg, $(u_result_syms[i]),
161161
fu; retcode = $(sol_syms[i]).retcode, stats,
162162
original = $(sol_syms[i]), trace = $(sol_syms[i]).trace)
@@ -196,7 +196,8 @@ end
196196
copyto!(cache.u0, u)
197197
u = cache.u0
198198
end
199-
return SciMLBase.build_solution(cache.caches[idx].prob, cache.alg, u, fus[idx];
199+
return __build_solution_less_specialize(
200+
cache.caches[idx].prob, cache.alg, u, fus[idx];
200201
retcode, stats, cache.caches[idx].trace)
201202
end)
202203

@@ -283,7 +284,7 @@ for (probType, pType) in ((:NonlinearProblem, :NLS), (:NonlinearLeastSquaresProb
283284
else
284285
$(u_result_syms[i]) = $(cur_sol).u
285286
end
286-
return SciMLBase.build_solution(
287+
return __build_solution_less_specialize(
287288
prob, alg, $(u_result_syms[i]), $(cur_sol).resid;
288289
$(cur_sol).retcode, $(cur_sol).stats,
289290
original = $(cur_sol), trace = $(cur_sol).trace)
@@ -316,7 +317,7 @@ for (probType, pType) in ((:NonlinearProblem, :NLS), (:NonlinearLeastSquaresProb
316317
else
317318
$(u_result_syms[i]) = $(sol_syms[i]).u
318319
end
319-
return SciMLBase.build_solution(
320+
return __build_solution_less_specialize(
320321
prob, alg, $(u_result_syms[i]), $(sol_syms[i]).resid;
321322
$(sol_syms[i]).retcode, $(sol_syms[i]).stats,
322323
$(sol_syms[i]).trace, original = $(sol_syms[i]))

src/utils.jl

+13
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,16 @@ Determine the chunk size for ForwardDiff and PolyesterForwardDiff based on the i
176176
"""
177177
@inline pickchunksize(x) = pickchunksize(length(x))
178178
@inline pickchunksize(x::Int) = ForwardDiff.pickchunksize(x)
179+
180+
# Original is often determined on runtime information especially for PolyAlgorithms so it
181+
# is best to never specialize on that
182+
function __build_solution_less_specialize(prob::AbstractNonlinearProblem, alg, u, resid;
183+
retcode = ReturnCode.Default, original = nothing, left = nothing,
184+
right = nothing, stats = nothing, trace = nothing, kwargs...)
185+
T = eltype(eltype(u))
186+
N = ndims(u)
187+
188+
return SciMLBase.NonlinearSolution{T, N, typeof(u), typeof(resid), typeof(prob),
189+
typeof(alg), Any, typeof(left), Any, typeof(trace)}(
190+
u, resid, prob, alg, retcode, original, left, right, stats, trace)
191+
end

test/misc/polyalg_tests.jl

+3
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ end
224224

225225
@test all(!isnan, sol.u)
226226
@test !SciMLBase.successful_retcode(sol.retcode)
227+
@inferred solve(prob)
227228
end
228229

229230
@testitem "[OOP] Infeasible" setup=[InfeasibleFunction] begin
@@ -235,6 +236,7 @@ end
235236

236237
@test all(!isnan, sol.u)
237238
@test !SciMLBase.successful_retcode(sol.retcode)
239+
@inferred solve(prob)
238240

239241
u0 = @SVector [0.0, 0.0, 0.0]
240242
prob = NonlinearProblem(f1_infeasible, u0)
@@ -243,6 +245,7 @@ end
243245
sol = solve(prob)
244246
@test all(!isnan, sol.u)
245247
@test !SciMLBase.successful_retcode(sol.retcode)
248+
@inferred solve(prob)
246249
catch err
247250
@test err isa LinearAlgebra.SingularException
248251
end

0 commit comments

Comments
 (0)