Skip to content

Commit

Permalink
feat: allow passing pre-computed vars to observed_equations_used_by
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Dec 17, 2024
1 parent 31f7a54 commit 21a2a33
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1033,19 +1033,24 @@ end
$(TYPEDSIGNATURES)
Return the indexes of observed equations of `sys` used by expression `exprs`.
Keyword arguments:
- `involved_vars`: A collection of the variables involved in `exprs`. This is the set of
variables which will be explored to find dependencies on observed equations. Typically,
providing this keyword is not necessary and is only useful to avoid repeatedly calling
`vars(exprs)`
"""
function observed_equations_used_by(sys::AbstractSystem, exprs)
function observed_equations_used_by(sys::AbstractSystem, exprs; involved_vars = vars(exprs))
obs = observed(sys)

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

syms = vars(exprs)

obsidxs = BitSet()
for sym in syms
for sym in involved_vars
idx = findfirst(isequal(sym), obsvars)
idx === nothing && continue
idx in obsidxs && continue
parents = dfs_parents(graph, idx)
for i in eachindex(parents)
parents[i] == 0 && continue
Expand Down

0 comments on commit 21a2a33

Please sign in to comment.