@@ -1152,14 +1152,20 @@ function get_concrete_problem(prob::NonlinearProblem, isadapt; kwargs...)
11521152 p = get_concrete_p (prob, kwargs)
11531153 u0 = get_concrete_u0 (prob, isadapt, nothing , kwargs)
11541154 u0 = promote_u0 (u0, p, nothing )
1155- remake (prob; u0 = u0, p = p)
1155+ f_promote = promote_f (
1156+ prob. f, Val (SciMLBase. specialization (prob. f)), u0, p
1157+ )
1158+ remake (prob; u0 = u0, p = p, f = f_promote)
11561159end
11571160
11581161function get_concrete_problem (prob:: NonlinearLeastSquaresProblem , isadapt; kwargs... )
11591162 p = get_concrete_p (prob, kwargs)
11601163 u0 = get_concrete_u0 (prob, isadapt, nothing , kwargs)
11611164 u0 = promote_u0 (u0, p, nothing )
1162- remake (prob; u0 = u0, p = p)
1165+ f_promote = promote_f (
1166+ prob. f, Val (SciMLBase. specialization (prob. f)), u0, p
1167+ )
1168+ remake (prob; u0 = u0, p = p, f = f_promote)
11631169end
11641170
11651171function get_concrete_problem (prob:: AbstractEnsembleProblem , isadapt; kwargs... )
@@ -1252,28 +1258,47 @@ function promote_f(f::F, ::Val{specialize}, u0, p, t) where {F, specialize}
12521258 f = @set f. jac_prototype = similar (f. jac_prototype, uElType)
12531259 end
12541260
1255- @static if VERSION >= v " 1.8-"
1256- f = if f isa ODEFunction && isinplace (f) && ! (f. f isa AbstractSciMLOperator) &&
1257- # Some reinitialization code still uses NLSolvers stuff which doesn't
1258- # properly tag, so opt-out if potentially a mass matrix DAE
1259- f. mass_matrix isa UniformScaling &&
1260- # Jacobians don't wrap, so just ignore those cases
1261- f. jac === nothing &&
1262- ((specialize === SciMLBase. AutoSpecialize && eltype (u0) != = Any &&
1263- RecursiveArrayTools. recursive_unitless_eltype (u0) === eltype (u0) &&
1264- one (t) === oneunit (t) &&
1265- hasmethod (ArrayInterface. promote_eltype,
1266- Tuple{Type{typeof (u0)}, Type{dualgen (eltype (u0))}}) &&
1267- hasmethod (promote_rule,
1268- Tuple{Type{eltype (u0)}, Type{dualgen (eltype (u0))}}) &&
1269- hasmethod (promote_rule,
1270- Tuple{Type{eltype (u0)}, Type{typeof (t)}})) ||
1271- (specialize === SciMLBase. FunctionWrapperSpecialize &&
1272- ! (f. f isa FunctionWrappersWrappers. FunctionWrappersWrapper)))
1273- return unwrapped_f (f, wrapfun_iip (f. f, (u0, u0, p, t)))
1274- else
1275- return f
1276- end
1261+ f = if f isa ODEFunction && isinplace (f) && ! (f. f isa AbstractSciMLOperator) &&
1262+ # Some reinitialization code still uses NLSolvers stuff which doesn't
1263+ # properly tag, so opt-out if potentially a mass matrix DAE
1264+ f. mass_matrix isa UniformScaling &&
1265+ # Jacobians don't wrap, so just ignore those cases
1266+ f. jac === nothing &&
1267+ ((specialize === SciMLBase. AutoSpecialize && eltype (u0) != = Any &&
1268+ RecursiveArrayTools. recursive_unitless_eltype (u0) === eltype (u0) &&
1269+ one (t) === oneunit (t) &&
1270+ hasmethod (ArrayInterface. promote_eltype,
1271+ Tuple{Type{typeof (u0)}, Type{dualgen (eltype (u0))}}) &&
1272+ hasmethod (promote_rule,
1273+ Tuple{Type{eltype (u0)}, Type{dualgen (eltype (u0))}}) &&
1274+ hasmethod (promote_rule,
1275+ Tuple{Type{eltype (u0)}, Type{typeof (t)}})) ||
1276+ (specialize === SciMLBase. FunctionWrapperSpecialize &&
1277+ ! (f. f isa FunctionWrappersWrappers. FunctionWrappersWrapper)))
1278+ return unwrapped_f (f, wrapfun_iip (f. f, (u0, u0, p, t)))
1279+ else
1280+ return f
1281+ end
1282+ end
1283+
1284+ function promote_f (f:: NonlinearFunction , :: Val{specialize} , u0, p) where {specialize}
1285+ # Ensure our jacobian will be of the same type as u0
1286+ uElType = u0 === nothing ? Float64 : eltype (u0)
1287+ if isdefined (f, :jac_prototype ) && f. jac_prototype isa AbstractArray
1288+ f = @set f. jac_prototype = similar (f. jac_prototype, uElType)
1289+ end
1290+
1291+ f = if isinplace (f) && ! (f. f isa AbstractSciMLOperator) &&
1292+ f. jac === nothing &&
1293+ ((specialize === SciMLBase. AutoSpecialize && eltype (u0) != = Any &&
1294+ RecursiveArrayTools. recursive_unitless_eltype (u0) === eltype (u0) &&
1295+ hasmethod (ArrayInterface. promote_eltype,
1296+ Tuple{Type{typeof (u0)}, Type{dualgen (eltype (u0))}}) &&
1297+ hasmethod (promote_rule,
1298+ Tuple{Type{eltype (u0)}, Type{dualgen (eltype (u0))}})) ||
1299+ (specialize === SciMLBase. FunctionWrapperSpecialize &&
1300+ ! (f. f isa FunctionWrappersWrappers. FunctionWrappersWrapper)))
1301+ return unwrapped_f (f, wrapfun_iip (f. f, (u0, u0, p)))
12771302 else
12781303 return f
12791304 end
0 commit comments