Skip to content

Commit c838cf2

Browse files
Convert NLLS to OptpRob
1 parent ffe68ae commit c838cf2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/problems/basic_problems.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,14 @@ function OptimizationProblem(f, args...; kwargs...)
688688
OptimizationProblem{true}(OptimizationFunction{true}(f), args...; kwargs...)
689689
end
690690

691+
function OptimizationProblem(prob::NonlinearLeastSquaresProblem; kwargs...)
692+
if isinplace(prob)
693+
throw(ArgumentError("Converting NonlinearLeastSquaresProblem to OptimizationProblem is not supported with in-place functions yet."))
694+
end
695+
optf = OptimizationFunction(sum prob.f, grad = (Jv, u, p) -> prob.f.jvp(Jv, prob.f(u, p), u, p), kwargs...)
696+
return OptimizationProblem(optf, prob.u0, prob.p; prob.kwargs..., kwargs...)
697+
end
698+
691699
isinplace(f::OptimizationFunction{iip}) where {iip} = iip
692700
isinplace(f::OptimizationProblem{iip}) where {iip} = iip
693701

0 commit comments

Comments
 (0)