Skip to content

Commit 0e7179f

Browse files
committed
Use sorted dependencies in ODAEProblem
1 parent 955abff commit 0e7179f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/structural_transformation/codegen.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,14 @@ function build_observed_function(
272272
required_algvars = Set(intersect(algvars, syms_set))
273273
obs = observed(sys)
274274
observed_idx = Dict(map(x->x.lhs, obs) .=> 1:length(obs))
275-
for sym in syms
276-
idx = get(observed_idx, sym, nothing)
275+
# FIXME: this is a rather rough estimate of dependencies.
276+
maxidx = 0
277+
for (i, s) in enumerate(syms)
278+
idx = get(observed_idx, s, nothing)
277279
idx === nothing && continue
280+
idx > maxidx && (maxidx = idx)
281+
end
282+
for idx in 1:maxidx
278283
vs = vars(obs[idx].rhs)
279284
union!(required_algvars, intersect(algvars, vs))
280285
end
@@ -308,7 +313,10 @@ function build_observed_function(
308313
],
309314
[],
310315
Let(
311-
collect(Iterators.flatten(solves)),
316+
[
317+
collect(Iterators.flatten(solves))
318+
map(eq -> eq.lhseq.rhs, obs[1:maxidx])
319+
],
312320
isscalar ? output[1] : MakeArray(output, output_type)
313321
)
314322
) |> Code.toexpr

0 commit comments

Comments
 (0)