From 42f36c5876d27e6947f7ea5d94cfa21d279c80d2 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 17 Jan 2025 22:12:38 +0530 Subject: [PATCH] fix: respect `checkbounds` in `build_explicit_observed_function` --- src/systems/diffeqs/odesystem.jl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/systems/diffeqs/odesystem.jl b/src/systems/diffeqs/odesystem.jl index 61f16fd926..d9e126baba 100644 --- a/src/systems/diffeqs/odesystem.jl +++ b/src/systems/diffeqs/odesystem.jl @@ -629,7 +629,15 @@ function build_explicit_observed_function(sys, ts; oop_fn = Func(args, [], pre(Let(obsexprs, return_value, - false))) |> array_wrapper[1] |> oop_mtkp_wrapper |> toexpr + false)), [Expr(:meta, :propagate_inbounds)]) |> array_wrapper[1] |> oop_mtkp_wrapper |> toexpr + + if !checkbounds + oop_fn.args[end] = quote + @inbounds begin + $(oop_fn.args[end]) + end + end + end oop_fn = expression ? oop_fn : eval_or_rgf(oop_fn; eval_expression, eval_module) if !isscalar @@ -639,6 +647,18 @@ function build_explicit_observed_function(sys, ts; wrap_code = mtkparams_wrapper .∘ array_wrapper .∘ wrap_assignments(isscalar, obsexprs), expression = Val{true})[2] + if !checkbounds + iip_fn.args[end] = quote + @inbounds begin + $(iip_fn.args[end]) + end + end + end + iip_fn.args[end] = quote + $(Expr(:meta, :propagate_inbounds)) + $(iip_fn.args[end]) + end + if !expression iip_fn = eval_or_rgf(iip_fn; eval_expression, eval_module) end