Skip to content

Commit 7a5c7a8

Browse files
feat: implement NonlinearLeastSquaresProblem for System
1 parent d28bc3f commit 7a5c7a8

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/problems/nonlinearproblem.jl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,37 @@ end
6767
f, u0, p, StandardNonlinearProblem(); kwargs...))
6868
end
6969

70+
@fallback_iip_specialize function SciMLBase.NonlinearLeastSquaresProblem{iip, spec}(
71+
sys::System, u0map, parammap = DiffEqBase.NullParameters(); check_length = false,
72+
check_compatibility = true, kwargs...) where {iip, spec}
73+
check_complete(sys, NonlinearLeastSquaresProblem)
74+
check_compatibility && check_compatible_system(NonlinearLeastSquaresProblem, sys)
75+
76+
f, u0, p = process_SciMLProblem(NonlinearFunction{iip}, sys, u0map, parammap;
77+
check_length, kwargs...)
78+
79+
kwargs = process_kwargs(sys; kwargs...)
80+
# Call `remake` so it runs initialization if it is trivial
81+
return remake(NonlinearLeastSquaresProblem{iip}(f, u0, p; kwargs...))
82+
end
83+
7084
function check_compatible_system(
71-
T::Union{Type{NonlinearFunction}, Type{NonlinearProblem}}, sys::System)
85+
T::Union{Type{NonlinearFunction}, Type{NonlinearProblem},
86+
Type{NonlinearLeastSquaresProblem}}, sys::System)
7287
check_time_independent(sys, T)
7388
check_not_dde(sys)
7489
check_no_cost(sys, T)
7590
check_no_constraints(sys, T)
7691
check_no_jumps(sys, T)
7792
check_no_noise(sys, T)
7893
end
94+
95+
function calculate_resid_prototype(N, u0, p)
96+
u0ElType = u0 === nothing ? Float64 : eltype(u0)
97+
if SciMLStructures.isscimlstructure(p)
98+
u0ElType = promote_type(
99+
eltype(SciMLStructures.canonicalize(SciMLStructures.Tunable(), p)[1]),
100+
u0ElType)
101+
end
102+
return zeros(u0ElType, N)
103+
end

0 commit comments

Comments
 (0)