Skip to content

Commit 1980fa6

Browse files
feat: add proper remake for DDEProblem
1 parent 0e2a089 commit 1980fa6

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

src/remake.jl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,79 @@ function remake(func::Union{SDEFunction, SDDEFunction};
425425
return T{isinplace(func)}(f, g; props..., kwargs...)
426426
end
427427

428+
function remake(prob::DDEProblem; f = missing, h = missing, u0 = missing,
429+
tspan = missing, p = missing, constant_lags = missing,
430+
dependent_lags = missing, order_discontinuity_t0 = missing,
431+
neutral = missing, kwargs = missing, interpret_symbolicmap = true,
432+
use_defaults = false, build_initializeprob = true, _kwargs...)
433+
if tspan === missing
434+
tspan = prob.tspan
435+
end
436+
437+
newu0, newp = updated_u0_p(prob, u0, p, tspan[1]; interpret_symbolicmap, use_defaults)
438+
439+
if build_initializeprob
440+
initialization_data = remake_initialization_data(
441+
prob.f.sys, prob.f, u0, tspan[1], p, newu0, newp)
442+
else
443+
initialization_data = nothing
444+
end
445+
446+
if f === missing
447+
f = prob.f
448+
elseif !(f isa DDEFunction)
449+
f = remake(prob.f; f = f)
450+
end
451+
f = remake(f; initialization_data)
452+
453+
h = coalesce(h, prob.h)
454+
constant_lags = coalesce(constant_lags, prob.constant_lags)
455+
dependent_lags = coalesce(dependent_lags, prob.dependent_lags)
456+
order_discontinuity_t0 = coalesce(order_discontinuity_t0, prob.order_discontinuity_t0)
457+
neutral = coalesce(neutral, prob.neutral)
458+
459+
iip = isinplace(prob)
460+
461+
if kwargs === missing
462+
DDEProblem{iip}(f,
463+
newu0,
464+
h,
465+
tspan,
466+
newp;
467+
constant_lags,
468+
dependent_lags,
469+
order_discontinuity_t0,
470+
neutral,
471+
prob.kwargs...,
472+
_kwargs...)
473+
else
474+
DDEProblem{iip}(f, newu0, h, tspan, newp; constant_lags, dependent_lags,
475+
order_discontinuity_t0, neutral, kwargs...)
476+
end
477+
end
478+
479+
function remake(func::DDEFunction;
480+
f = missing,
481+
mass_matrix = missing,
482+
analytic = missing,
483+
sys = missing,
484+
kwargs...)
485+
props = getproperties(func)
486+
props = @delete props.f
487+
@reset props.mass_matrix = coalesce(mass_matrix, func.mass_matrix)
488+
@reset props.analytic = coalesce(analytic, func.analytic)
489+
@reset props.sys = coalesce(sys, func.sys)
490+
491+
if f === missing
492+
f = func.f
493+
end
494+
if f isa AbstractSciMLFunction
495+
f = f.f
496+
end
497+
498+
return DDEFunction{isinplace(func)}(f; props..., kwargs...)
499+
end
500+
428501
"""
429502
remake(prob::OptimizationProblem; f = missing, u0 = missing, p = missing,
430503
lb = missing, ub = missing, int = missing, lcons = missing, ucons = missing,

0 commit comments

Comments
 (0)