Skip to content

Commit 21a2a33

Browse files
feat: allow passing pre-computed vars to observed_equations_used_by
1 parent 31f7a54 commit 21a2a33

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/utils.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,19 +1033,24 @@ end
10331033
$(TYPEDSIGNATURES)
10341034
10351035
Return the indexes of observed equations of `sys` used by expression `exprs`.
1036+
1037+
Keyword arguments:
1038+
- `involved_vars`: A collection of the variables involved in `exprs`. This is the set of
1039+
variables which will be explored to find dependencies on observed equations. Typically,
1040+
providing this keyword is not necessary and is only useful to avoid repeatedly calling
1041+
`vars(exprs)`
10361042
"""
1037-
function observed_equations_used_by(sys::AbstractSystem, exprs)
1043+
function observed_equations_used_by(sys::AbstractSystem, exprs; involved_vars = vars(exprs))
10381044
obs = observed(sys)
10391045

10401046
obsvars = getproperty.(obs, :lhs)
10411047
graph = observed_dependency_graph(obs)
10421048

1043-
syms = vars(exprs)
1044-
10451049
obsidxs = BitSet()
1046-
for sym in syms
1050+
for sym in involved_vars
10471051
idx = findfirst(isequal(sym), obsvars)
10481052
idx === nothing && continue
1053+
idx in obsidxs && continue
10491054
parents = dfs_parents(graph, idx)
10501055
for i in eachindex(parents)
10511056
parents[i] == 0 && continue

0 commit comments

Comments
 (0)