From 1022282ab0c2b6c7712ddd0811b588827dd40b6d Mon Sep 17 00:00:00 2001 From: Benjamin Chung Date: Fri, 13 Sep 2024 09:10:20 -0700 Subject: [PATCH] Fix support for array forms in the NamedTuple version of MutatingFunctionalAffect --- src/systems/callbacks.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/systems/callbacks.jl b/src/systems/callbacks.jl index 34acb5b2ae..ad41807ab8 100644 --- a/src/systems/callbacks.jl +++ b/src/systems/callbacks.jl @@ -1062,7 +1062,7 @@ 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...,) @@ -1070,7 +1070,7 @@ function compile_user_affect(affect::MutatingFunctionalAffect, cb, sys, dvs, ps; 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))...,)) @@ -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))