Skip to content

Commit

Permalink
Merge pull request #3339 from AayushSabharwal/as/observed-inbounds
Browse files Browse the repository at this point in the history
fix: respect `checkbounds` in `build_explicit_observed_function`
  • Loading branch information
ChrisRackauckas authored Jan 18, 2025
2 parents f497ae0 + 42f36c5 commit 009d8b8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/systems/diffeqs/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 009d8b8

Please sign in to comment.