Skip to content

Commit 1b73799

Browse files
committed
feat: allow NLLS for ImplicitDiscreteProblem
1 parent e4f41ac commit 1b73799

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/ImplicitDiscreteSolve/src/solve.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ function initialize!(integrator, cache::IDSolveCache)
2222
else
2323
(u_next, p) -> f(u_next, p.u, p.p, p.t_next)
2424
end
25-
nlls = length(f.resid_prototype) == length(integrator.u)
25+
nlls = !isnothing(f.resid_prototype) && (length(f.resid_prototype) == length(integrator.u))
2626

2727
prob = if nlls
28-
NonlinearLeastSquaresProblem{isinplace(f)}(_f, cache.state.u, cache.state)
28+
NonlinearLeastSquaresProblem{isinplace(f)}(NonlinearFunction(_f; resid_prototype = f.resid_prototype), cache.state.u, cache.state)
2929
else
3030
NonlinearProblem{isinplace(f)}(_f, cache.state.u, cache.state)
3131
end
@@ -48,9 +48,10 @@ function _initialize_dae!(integrator, prob::ImplicitDiscreteProblem,
4848
else
4949
(u_next, p) -> f(u_next, p.u, p.p, p.t_next)
5050
end
51-
nlls = length(f.resid_prototype) == length(integrator.u)
51+
52+
nlls = !isnothing(f.resid_prototype) && (length(f.resid_prototype) == length(integrator.u))
5253
prob = if nlls
53-
NonlinearLeastSquaresProblem{isinplace(f)}(_f, cache.state.u, cache.state)
54+
NonlinearLeastSquaresProblem{isinplace(f)}(NonlinearFunction(_f; resid_prototype = f.resid_prototype), cache.state.u, cache.state)
5455
else
5556
NonlinearProblem{isinplace(f)}(_f, cache.state.u, cache.state)
5657
end

0 commit comments

Comments
 (0)