Skip to content

Commit 0244545

Browse files
author
dd
committed
n*m -> n*log(m)
1 parent b7d59b4 commit 0244545

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/systems/callbacks.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function get_discrete_events(sys::AbstractSystem)
1010
end
1111

1212
struct FunctionalAffect
13-
f::Function
13+
f::Any
1414
sts::Vector
1515
sts_syms::Vector{Symbol}
1616
pars::Vector
@@ -316,11 +316,11 @@ function compile_affect(eqs::Vector{Equation}, sys, dvs, ps; outputidxs = nothin
316316
alleq = all(isequal(isparameter(first(update_vars))),
317317
Iterators.map(isparameter, update_vars))
318318
if !isparameter(first(lhss)) && alleq
319-
stateind(sym) = findfirst(isequal(sym), dvs)
320-
update_inds = stateind.(update_vars)
319+
stateind = Dict(map(a -> reverse(a), enumerate(dvs)))
320+
update_inds = map(sym -> stateind[sym], update_vars)
321321
elseif isparameter(first(lhss)) && alleq
322-
psind(sym) = findfirst(isequal(sym), ps)
323-
update_inds = psind.(update_vars)
322+
psind = Dict(map(a -> reverse(a), enumerate(ps)))
323+
update_inds = map(sym -> psind[sym], update_vars)
324324
outvar = :p
325325
else
326326
error("Error, building an affect function for a callback that wants to modify both parameters and states. This is not currently allowed in one individual callback.")
@@ -411,10 +411,11 @@ function generate_rootfinding_callback(cbs, sys::AbstractODESystem, dvs = states
411411
end
412412

413413
function compile_user_affect(affect::FunctionalAffect, sys, dvs, ps; kwargs...)
414-
ind(sym, v) = findfirst(isequal(sym), v)
415-
inds(syms, v) = map(sym -> ind(sym, v), syms)
416-
v_inds = inds(states(affect), dvs)
417-
p_inds = inds(parameters(affect), ps)
414+
dvs_ind = Dict(map(a -> reverse(a), enumerate(dvs)))
415+
v_inds = map(sym -> dvs_ind[sym], states(affect))
416+
417+
ps_ind = Dict(map(a -> reverse(a), enumerate(ps)))
418+
p_inds = map(sym -> ps_ind[sym], parameters(affect))
418419

419420
# HACK: filter out eliminated symbols. Not clear this is the right thing to do
420421
# (MTK should keep these symbols)

0 commit comments

Comments
 (0)