@@ -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,22 @@ function modelingtoolkitize(
37
38
end
38
39
39
40
if DiffEqBase. isinplace (prob)
40
- rhs = ArrayInterface. restructure (prob. u0, similar (vars, Num))
41
- prob. f (rhs, vars, params)
41
+ if prob isa NonlinearLeastSquaresProblem
42
+ rhs = ArrayInterface. restructure (
43
+ prob. f. resid_prototype, similar (prob. f. resid_prototype, Num))
44
+ prob. f (rhs, vars, params)
45
+ eqs = vcat ([0.0 ~ rhs[i] for i in 1 : length (prob. f. resid_prototype)]. .. )
46
+ else
47
+ rhs = ArrayInterface. restructure (prob. u0, similar (vars, Num))
48
+ prob. f (rhs, vars, params)
49
+ eqs = vcat ([0.0 ~ rhs[i] for i in 1 : length (rhs)]. .. )
50
+ end
51
+
42
52
else
43
53
rhs = prob. f (vars, params)
54
+ out_def = prob. f (prob. u0, prob. p)
55
+ eqs = vcat ([0.0 ~ rhs[i] for i in 1 : length (out_def)]. .. )
44
56
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
57
48
58
sts = vec (collect (vars))
49
59
_params = params
0 commit comments