Skip to content

Commit 009d8b8

Browse files
Merge pull request #3339 from AayushSabharwal/as/observed-inbounds
fix: respect `checkbounds` in `build_explicit_observed_function`
2 parents f497ae0 + 42f36c5 commit 009d8b8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/systems/diffeqs/odesystem.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,15 @@ function build_explicit_observed_function(sys, ts;
629629
oop_fn = Func(args, [],
630630
pre(Let(obsexprs,
631631
return_value,
632-
false))) |> array_wrapper[1] |> oop_mtkp_wrapper |> toexpr
632+
false)), [Expr(:meta, :propagate_inbounds)]) |> array_wrapper[1] |> oop_mtkp_wrapper |> toexpr
633+
634+
if !checkbounds
635+
oop_fn.args[end] = quote
636+
@inbounds begin
637+
$(oop_fn.args[end])
638+
end
639+
end
640+
end
633641
oop_fn = expression ? oop_fn : eval_or_rgf(oop_fn; eval_expression, eval_module)
634642

635643
if !isscalar
@@ -639,6 +647,18 @@ function build_explicit_observed_function(sys, ts;
639647
wrap_code = mtkparams_wrapper .∘ array_wrapper .∘
640648
wrap_assignments(isscalar, obsexprs),
641649
expression = Val{true})[2]
650+
if !checkbounds
651+
iip_fn.args[end] = quote
652+
@inbounds begin
653+
$(iip_fn.args[end])
654+
end
655+
end
656+
end
657+
iip_fn.args[end] = quote
658+
$(Expr(:meta, :propagate_inbounds))
659+
$(iip_fn.args[end])
660+
end
661+
642662
if !expression
643663
iip_fn = eval_or_rgf(iip_fn; eval_expression, eval_module)
644664
end

0 commit comments

Comments
 (0)