@@ -4,7 +4,8 @@ $(TYPEDSIGNATURES)
4
4
Generate `NonlinearSystem`, dependent variables, and parameters from an `NonlinearProblem`.
5
5
"""
6
6
function modelingtoolkitize (
7
- prob:: NonlinearProblem ; u_names = nothing , p_names = nothing , kwargs... )
7
+ prob:: Union{NonlinearProblem, NonlinearLeastSquaresProblem} ;
8
+ u_names = nothing , p_names = nothing , kwargs... )
8
9
p = prob. p
9
10
has_p = ! (p isa Union{DiffEqBase. NullParameters, Nothing})
10
11
@@ -37,13 +38,18 @@ function modelingtoolkitize(
37
38
end
38
39
39
40
if DiffEqBase. isinplace (prob)
40
- rhs = ArrayInterface. restructure (prob. u0, similar (vars, Num))
41
+ if prob isa NonlinearLeastSquaresProblem
42
+ rhs = ArrayInterface. restructure (prob. f. resid_prototype, similar (prob. f. resid_prototype, Num))
43
+ else
44
+ rhs = ArrayInterface. restructure (prob. u0, similar (vars, Num))
45
+ end
41
46
prob. f (rhs, vars, params)
47
+ eqs = vcat ([0.0 ~ rhs[i] for i in 1 : length (prob. f. resid_prototype)]. .. )
42
48
else
43
49
rhs = prob. f (vars, params)
50
+ out_def = prob. f (prob. u0, prob. p)
51
+ eqs = vcat ([0.0 ~ rhs[i] for i in 1 : length (out_def)]. .. )
44
52
end
45
- out_def = prob. f (prob. u0, prob. p)
46
- eqs = vcat ([0.0 ~ rhs[i] for i in 1 : length (out_def)]. .. )
47
53
48
54
sts = vec (collect (vars))
49
55
_params = params
0 commit comments