Skip to content

Commit 204690b

Browse files
Merge pull request #1149 from AayushSabharwal/as/null-sol-resid-prototype
feat: pass `resid_prototype` as `u` to null oop `NonlinearLeastSquaresProblem`
2 parents 1edfd29 + 2dd9348 commit 204690b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/solve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ function build_null_solution(
776776
resid = isnothing(prob.f.resid_prototype) ? Float64[] : copy(prob.f.resid_prototype)
777777
prob.f(resid, prob.u0, prob.p)
778778
else
779-
resid = prob.f(prob.u0, prob.p)
779+
resid = prob.f(prob.f.resid_prototype, prob.p)
780780
end
781781

782782
if success

test/downstream/null_de.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ModelingToolkit, OrdinaryDiffEq, SteadyStateDiffEq, Test
2+
using StaticArrays
23
using ModelingToolkit: t_nounits as t, D_nounits as D
34
using ForwardDiff
45

@@ -77,3 +78,12 @@ sol = solve(unsatprob) # Success
7778
@test_nowarn ForwardDiff.derivative(x_at_1_num, 1.0)
7879
@test_nowarn ForwardDiff.derivative(x_at_1_anal, 1.0)
7980
end
81+
82+
@testset "Null OOP NonlinearLeastSquaresProblem" begin
83+
fn = NonlinearFunction{false}(; resid_prototype = SA[1.0]) do u, p
84+
return zero(u)
85+
end
86+
prob = NonlinearLeastSquaresProblem(fn, nothing)
87+
sol = solve(prob)
88+
@test sol.resid isa SVector{1, Float64}
89+
end

0 commit comments

Comments
 (0)