@@ -412,8 +412,16 @@ function build_explicit_observed_function(sys, ts;
412
412
ts = [ts]
413
413
end
414
414
ts = unwrap .(ts)
415
+ issplit = has_index_cache (sys) && get_index_cache (sys) != = nothing
415
416
if is_dde (sys)
416
- ts = map (x -> delay_to_function (sys, x), ts)
417
+ if issplit
418
+ ts = map (
419
+ x -> delay_to_function (
420
+ sys, x; history_arg = issplit ? MTKPARAMETERS_ARG : DEFAULT_PARAMS_ARG),
421
+ ts)
422
+ else
423
+ ts = map (x -> delay_to_function (sys, x), ts)
424
+ end
417
425
end
418
426
419
427
vars = Set ()
@@ -491,7 +499,8 @@ function build_explicit_observed_function(sys, ts;
491
499
for i in 1 : maxidx
492
500
eq = obs[i]
493
501
if is_dde (sys)
494
- eq = delay_to_function (sys, eq)
502
+ eq = delay_to_function (
503
+ sys, eq; history_arg = issplit ? MTKPARAMETERS_ARG : DEFAULT_PARAMS_ARG)
495
504
end
496
505
lhs = eq. lhs
497
506
rhs = eq. rhs
@@ -518,12 +527,14 @@ function build_explicit_observed_function(sys, ts;
518
527
else
519
528
dvs = (dvs,)
520
529
end
530
+ p_start = param_only ? 1 : (length (dvs) + 1 )
521
531
if inputs === nothing
522
532
args = param_only ? [ps... , ivs... ] : [dvs... , ps... , ivs... ]
523
533
else
524
534
inputs = unwrap .(inputs)
525
535
ipts = DestructuredArgs (inputs, inbounds = ! checkbounds)
526
536
args = param_only ? [ipts, ps... , ivs... ] : [dvs... , ipts, ps... , ivs... ]
537
+ p_start += 1
527
538
end
528
539
pre = get_postprocess_fbody (sys)
529
540
@@ -534,19 +545,27 @@ function build_explicit_observed_function(sys, ts;
534
545
wrap_array_vars (sys, ts; ps = _ps, inputs) .∘
535
546
wrap_parameter_dependencies (sys, isscalar)
536
547
end
548
+ mtkparams_wrapper = wrap_mtkparameters (sys, isscalar, p_start)
549
+ if mtkparams_wrapper isa Tuple
550
+ oop_mtkp_wrapper = mtkparams_wrapper[1 ]
551
+ else
552
+ oop_mtkp_wrapper = mtkparams_wrapper
553
+ end
554
+
537
555
# Need to keep old method of building the function since it uses `output_type`,
538
556
# which can't be provided to `build_function`
539
557
oop_fn = Func (args, [],
540
558
pre (Let (obsexprs,
541
559
isscalar ? ts[1 ] : MakeArray (ts, output_type),
542
- false ))) |> array_wrapper[1 ] |> toexpr
560
+ false ))) |> array_wrapper[1 ] |> oop_mtkp_wrapper |> toexpr
543
561
oop_fn = expression ? oop_fn : eval_or_rgf (oop_fn; eval_expression, eval_module)
544
562
545
563
if ! isscalar
546
564
iip_fn = build_function (ts,
547
565
args... ;
548
566
postprocess_fbody = pre,
549
- wrap_code = array_wrapper .∘ wrap_assignments (isscalar, obsexprs),
567
+ wrap_code = array_wrapper .∘ wrap_assignments (isscalar, obsexprs) .∘
568
+ mtkparams_wrapper,
550
569
expression = Val{true })[2 ]
551
570
if ! expression
552
571
iip_fn = eval_or_rgf (iip_fn; eval_expression, eval_module)
0 commit comments