@@ -12,16 +12,16 @@ using SciMLBase
12
12
using NonlinearSolve
13
13
14
14
# Re-export algorithm type so that `using NonlinearSolve` brings it in when the
15
- # extension is loaded. (Matches convention in other extensions.)
15
+ # extension is loaded.
16
16
import .. NonlinearSolve: SciPyLeastSquares, SciPyRoot, SciPyRootScalar
17
17
using NonlinearSolveBase: construct_extension_function_wrapper
18
18
19
19
""" Internal: wrap a Julia residual function into a Python callable """
20
20
function _make_py_residual (f, p)
21
21
return pyfunc (x_py -> begin
22
- x = Vector {Float64} (x_py) # convert NumPy array → Julia Vector
22
+ x = Vector {Float64} (x_py)
23
23
r = f (x, p)
24
- return r # auto-convert back to NumPy
24
+ return r
25
25
end )
26
26
end
27
27
@@ -50,15 +50,13 @@ function SciMLBase.__solve(prob::SciMLBase.NonlinearLeastSquaresProblem, alg::Sc
50
50
bounds = nothing
51
51
end
52
52
53
- # Call SciPy
54
53
res = scipy_optimize. least_squares (py_f, collect (prob. u0);
55
54
method = alg. method,
56
55
loss = alg. loss,
57
56
max_nfev = maxiters,
58
57
bounds = bounds === nothing ? py_none : bounds,
59
58
kwargs... )
60
59
61
- # Extract solution
62
60
u_vec = Vector {Float64} (res. x)
63
61
resid = Vector {Float64} (res. fun)
64
62
@@ -97,7 +95,7 @@ function SciMLBase.__solve(prob::SciMLBase.NonlinearProblem, alg::SciPyRoot;
97
95
kwargs... )
98
96
99
97
u_vec = Vector {Float64} (res. x)
100
- f! (resid, u_vec) # update residual
98
+ f! (resid, u_vec)
101
99
102
100
u_out = prob. u0 isa Number ? u_vec[1 ] : reshape (u_vec, size (prob. u0))
103
101
@@ -137,4 +135,5 @@ function SciMLBase.__solve(prob::SciMLBase.IntervalNonlinearProblem, alg::SciPyR
137
135
original = res, stats = stats)
138
136
end
139
137
140
- end # module
138
+ end
139
+
0 commit comments