Skip to content

Commit 955abff

Browse files
committed
Use sorted dependencies in ODEProblem
1 parent f3b6994 commit 955abff

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/systems/diffeqs/odesystem.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,14 @@ function build_explicit_observed_function(
250250

251251
obs = observed(sys)
252252
observed_idx = Dict(map(x->x.lhs, obs) .=> 1:length(obs))
253-
output = map(sym->obs[observed_idx[sym]].rhs, syms)
253+
output = similar(syms, Any)
254+
# FIXME: this is a rather rough estimate of dependencies.
255+
maxidx = 0
256+
for (i, s) in enumerate(syms)
257+
idx = observed_idx[s]
258+
idx > maxidx && (maxidx = idx)
259+
output[i] = obs[idx].rhs
260+
end
254261

255262
ex = Func(
256263
[
@@ -259,7 +266,10 @@ function build_explicit_observed_function(
259266
independent_variable(sys)
260267
],
261268
[],
262-
isscalar ? output[1] : MakeArray(output, output_type)
269+
Let(
270+
map(eq -> eq.lhseq.rhs, obs[1:maxidx]),
271+
isscalar ? output[1] : MakeArray(output, output_type)
272+
)
263273
) |> toexpr
264274

265275
expression ? ex : @RuntimeGeneratedFunction(ex)

0 commit comments

Comments
 (0)