@@ -283,6 +283,16 @@ function hessian_sparsity(sys::NonlinearSystem)
283
283
unknowns (sys)) for eq in equations (sys)]
284
284
end
285
285
286
+ function calculate_resid_prototype (N, u0, p)
287
+ u0ElType = u0 === nothing ? Float64 : eltype (u0)
288
+ if SciMLStructures. isscimlstructure (p)
289
+ u0ElType = promote_type (
290
+ eltype (SciMLStructures. canonicalize (SciMLStructures. Tunable (), p)[1 ]),
291
+ u0ElType)
292
+ end
293
+ return zeros (u0ElType, N)
294
+ end
295
+
286
296
"""
287
297
```julia
288
298
SciMLBase.NonlinearFunction{iip}(sys::NonlinearSystem, dvs = unknowns(sys),
@@ -337,13 +347,7 @@ function SciMLBase.NonlinearFunction{iip}(sys::NonlinearSystem, dvs = unknowns(s
337
347
if length (dvs) == length (equations (sys))
338
348
resid_prototype = nothing
339
349
else
340
- u0ElType = u0 === nothing ? Float64 : eltype (u0)
341
- if SciMLStructures. isscimlstructure (p)
342
- u0ElType = promote_type (
343
- eltype (SciMLStructures. canonicalize (SciMLStructures. Tunable (), p)[1 ]),
344
- u0ElType)
345
- end
346
- resid_prototype = zeros (u0ElType, length (equations (sys)))
350
+ resid_prototype = calculate_resid_prototype (length (equations (sys)), u0, p)
347
351
end
348
352
349
353
NonlinearFunction {iip} (f,
0 commit comments