Skip to content

Commit

Permalink
Fix support for array forms in the NamedTuple version of MutatingFunc…
Browse files Browse the repository at this point in the history
…tionalAffect
  • Loading branch information
BenChung committed Sep 24, 2024
1 parent 3e1637d commit 1022282
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1062,15 +1062,15 @@ function compile_user_affect(affect::MutatingFunctionalAffect, cb, sys, dvs, ps;
zeros(sz)
end
obs_fun = build_explicit_observed_function(
sys, reduce(vcat, Symbolics.scalarize.(obs_exprs); init = []);
sys, Symbolics.scalarize.(obs_exprs);
array_type = :tuple)
obs_sym_tuple = (obs_syms...,)

# okay so now to generate the stuff to assign it back into the system
mod_pairs = mod_exprs .=> mod_syms
mod_names = (mod_syms..., )
mod_og_val_fun = build_explicit_observed_function(
sys, reduce(vcat, Symbolics.scalarize.(first.(mod_pairs)); init = []);
sys, Symbolics.scalarize.(first.(mod_pairs));
array_type = :tuple)

upd_funs = NamedTuple{mod_names}((setu.((sys,), first.(mod_pairs))...,))
Expand All @@ -1084,7 +1084,8 @@ function compile_user_affect(affect::MutatingFunctionalAffect, cb, sys, dvs, ps;
let user_affect = func(affect), ctx = context(affect)
function (integ)
# update the to-be-mutated values; this ensures that if you do a no-op then nothing happens
upd_component_array = NamedTuple{mod_names}(mod_og_val_fun(integ.u, integ.p..., integ.t))
modvals = mod_og_val_fun(integ.u, integ.p..., integ.t)
upd_component_array = NamedTuple{mod_names}(modvals)

# update the observed values
obs_component_array = NamedTuple{obs_sym_tuple}(obs_fun(integ.u, integ.p..., integ.t))
Expand Down

0 comments on commit 1022282

Please sign in to comment.