Skip to content

Commit bb15228

Browse files
feat: add available_vars to observed_equations_used_by
1 parent 3a54d9e commit bb15228

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/utils.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,14 +1068,24 @@ Keyword arguments:
10681068
providing this keyword is not necessary and is only useful to avoid repeatedly calling
10691069
`vars(exprs)`
10701070
- `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.
10711077
"""
10721078
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 = [])
10741080
obsvars = getproperty.(obs, :lhs)
10751081
graph = observed_dependency_graph(obs)
1082+
if !(available_vars isa Set)
1083+
available_vars = Set(available_vars)
1084+
end
10761085

10771086
obsidxs = BitSet()
10781087
for sym in involved_vars
1088+
sym in available_vars && continue
10791089
arrsym = iscall(sym) && operation(sym) === getindex ? arguments(sym)[1] : nothing
10801090
idx = findfirst(v -> isequal(v, sym) || isequal(v, arrsym), obsvars)
10811091
idx === nothing && continue

0 commit comments

Comments
 (0)