@@ -74,6 +74,7 @@ struct ODESystem <: AbstractODESystem
7474 structure: structural information of the system
7575 """
7676 structure:: Any
77+ reduced_states:: Vector
7778end
7879
7980function ODESystem (
@@ -101,7 +102,7 @@ function ODESystem(
101102 if length (unique (sysnames)) != length (sysnames)
102103 throw (ArgumentError (" System names must be unique." ))
103104 end
104- ODESystem (deqs, iv′, dvs′, ps′, observed, tgrad, jac, Wfact, Wfact_t, name, systems, default_u0, default_p, nothing )
105+ ODESystem (deqs, iv′, dvs′, ps′, observed, tgrad, jac, Wfact, Wfact_t, name, systems, default_u0, default_p, nothing , [] )
105106end
106107
107108var_from_nested_derivative (x, i= 0 ) = (missing , missing )
@@ -235,7 +236,7 @@ ODESystem(eq::Equation, args...; kwargs...) = ODESystem([eq], args...; kwargs...
235236$(SIGNATURES)
236237
237238Build the observed function assuming the observed equations are all explicit,
238- i.e. there are no cycles or dependencies .
239+ i.e. there are no cycles.
239240"""
240241function build_explicit_observed_function (
241242 sys, syms;
@@ -249,7 +250,14 @@ function build_explicit_observed_function(
249250
250251 obs = observed (sys)
251252 observed_idx = Dict (map (x-> x. lhs, obs) .=> 1 : length (obs))
252- 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
253261
254262 ex = Func (
255263 [
@@ -258,7 +266,10 @@ function build_explicit_observed_function(
258266 independent_variable (sys)
259267 ],
260268 [],
261- isscalar ? output[1 ] : MakeArray (output, output_type)
269+ Let (
270+ map (eq -> eq. lhs← eq. rhs, obs[1 : maxidx]),
271+ isscalar ? output[1 ] : MakeArray (output, output_type)
272+ )
262273 ) |> toexpr
263274
264275 expression ? ex : @RuntimeGeneratedFunction (ex)
0 commit comments