@@ -185,11 +185,14 @@ end
185
185
end )
186
186
end
187
187
188
- resids = map (x -> " $x .resid" , sol_syms)
188
+ resids = map (x -> Symbol (" $(x) _resid" ), sol_syms)
189
+ for (sym, resid) in zip (sol_syms, resids)
190
+ push! (calls, :($ (resid) = $ (sym). resid))
191
+ end
189
192
190
193
push! (calls,
191
194
quote
192
- resids = $ (Tuple (resids))
195
+ resids = tuple ( $ (Tuple (resids) ... ))
193
196
minfu, idx = findmin (DEFAULT_NORM, resids)
194
197
end )
195
198
198
201
quote
199
202
if idx == $ i
200
203
return SciMLBase. build_solution (prob, alg, $ (sol_syms[i]). u,
201
- $ (sol_syms[i]). resid; $ (sol_syms[i]). retcode, $ (sol_syms[i]). stats,
202
- original = $ (sol_syms[i]))
204
+ $ (sol_syms[i]). resid; $ (sol_syms[i]). retcode, $ (sol_syms[i]). stats)
203
205
end
204
206
end )
205
207
end
@@ -210,53 +212,54 @@ end
210
212
211
213
# # General shared polyalg functions
212
214
213
- function perform_step! (cache:: Union {RobustMultiNewtonCache,
214
- FastShortcutNonlinearPolyalgCache})
215
- current = cache. current
216
- 1 ≤ current ≤ length (cache. caches) || error (" Current choices shouldn't get here!" )
217
-
218
- current_cache = cache. caches[current]
219
- while not_terminated (current_cache)
220
- perform_step! (current_cache)
215
+ @generated function SciMLBase. solve! (cache:: Union {RobustMultiNewtonCache{iip, N},
216
+ FastShortcutNonlinearPolyalgCache{iip, N}}) where {iip, N}
217
+ calls = [
218
+ quote
219
+ 1 ≤ cache. current ≤ length (cache. caches) ||
220
+ error (" Current choices shouldn't get here!" )
221
+ end ,
222
+ ]
223
+
224
+ cache_syms = [gensym (" cache" ) for i in 1 : N]
225
+ sol_syms = [gensym (" sol" ) for i in 1 : N]
226
+ for i in 1 : N
227
+ push! (calls,
228
+ quote
229
+ $ (cache_syms[i]) = cache. caches[$ (i)]
230
+ if $ (i) == cache. current
231
+ $ (sol_syms[i]) = SciMLBase. solve! ($ (cache_syms[i]))
232
+ if SciMLBase. successful_retcode ($ (sol_syms[i]))
233
+ stats = $ (sol_syms[i]). stats
234
+ u = $ (sol_syms[i]). u
235
+ fu = get_fu ($ (cache_syms[i]))
236
+ return SciMLBase. build_solution ($ (sol_syms[i]). prob, cache. alg, u,
237
+ fu; retcode = ReturnCode. Success, stats,
238
+ original = $ (sol_syms[i]))
239
+ end
240
+ cache. current = $ (i + 1 )
241
+ end
242
+ end )
221
243
end
222
244
223
- return nothing
224
- end
225
-
226
- function SciMLBase. solve! (cache:: Union {RobustMultiNewtonCache,
227
- FastShortcutNonlinearPolyalgCache})
228
- current = cache. current
229
- 1 ≤ current ≤ length (cache. caches) || error (" Current choices shouldn't get here!" )
230
-
231
- current_cache = cache. caches[current]
232
- while current ≤ length (cache. caches) # && !all(terminated[current:end])
233
- sol_tmp = solve! (current_cache)
234
- SciMLBase. successful_retcode (sol_tmp) && break
235
- current += 1
236
- cache. current = current
237
- current_cache = cache. caches[current]
245
+ resids = map (x -> Symbol (" $(x) _resid" ), cache_syms)
246
+ for (sym, resid) in zip (cache_syms, resids)
247
+ push! (calls, :($ (resid) = get_fu ($ (sym))))
238
248
end
249
+ push! (calls,
250
+ quote
251
+ retcode = ReturnCode. MaxIters
239
252
240
- if current ≤ length (cache. caches)
241
- retcode = ReturnCode. Success
242
-
243
- stats = cache. caches[current]. stats
244
- u = cache. caches[current]. u
245
- fu = get_fu (cache. caches[current])
246
-
247
- return SciMLBase. build_solution (cache. caches[1 ]. prob, cache. alg, u, fu;
248
- retcode, stats)
249
- else
250
- retcode = ReturnCode. MaxIters
253
+ fus = tuple ($ (Tuple (resids)... ))
254
+ minfu, idx = findmin (cache. caches[1 ]. internalnorm, fus)
255
+ stats = cache. caches[idx]. stats
256
+ u = cache. caches[idx]. u
251
257
252
- fus = get_fu .(cache. caches)
253
- minfu, idx = findmin (cache. caches[1 ]. internalnorm, fus)
254
- stats = cache. caches[idx]. stats
255
- u = cache. caches[idx]. u
258
+ return SciMLBase. build_solution (cache. caches[idx]. prob, cache. alg, u,
259
+ fus[idx]; retcode, stats)
260
+ end )
256
261
257
- return SciMLBase. build_solution (cache. caches[idx]. prob, cache. alg, u, fus[idx];
258
- retcode, stats)
259
- end
262
+ return Expr (:block , calls... )
260
263
end
261
264
262
265
function SciMLBase. reinit! (cache:: Union {RobustMultiNewtonCache,
0 commit comments