@@ -1068,14 +1068,24 @@ Keyword arguments:
1068
1068
providing this keyword is not necessary and is only useful to avoid repeatedly calling
1069
1069
`vars(exprs)`
1070
1070
- `obs`: the list of observed equations.
1071
+ - `available_vars`: If `exprs` involves a variable `x[1]`, this function will look for
1072
+ observed equations whose LHS is `x[1]` OR `x`. Sometimes, the latter is not required
1073
+ since `x[1]` might already be present elsewhere in the generated code (e.g. an argument
1074
+ to the function) but other elements of `x` are part of the observed equations, thus
1075
+ requiring them to be obtained from the equation for `x`. Any variable present in
1076
+ `available_vars` will not be searched for in the observed equations.
1071
1077
"""
1072
1078
function observed_equations_used_by (sys:: AbstractSystem , exprs;
1073
- involved_vars = vars (exprs; op = Union{Shift, Differential}), obs = observed (sys))
1079
+ involved_vars = vars (exprs; op = Union{Shift, Differential}), obs = observed (sys), available_vars = [] )
1074
1080
obsvars = getproperty .(obs, :lhs )
1075
1081
graph = observed_dependency_graph (obs)
1082
+ if ! (available_vars isa Set)
1083
+ available_vars = Set (available_vars)
1084
+ end
1076
1085
1077
1086
obsidxs = BitSet ()
1078
1087
for sym in involved_vars
1088
+ sym in available_vars && continue
1079
1089
arrsym = iscall (sym) && operation (sym) === getindex ? arguments (sym)[1 ] : nothing
1080
1090
idx = findfirst (v -> isequal (v, sym) || isequal (v, arrsym), obsvars)
1081
1091
idx === nothing && continue
0 commit comments