From 21a2a33aa6d505da57c30c8e8326b40201106aae Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 13 Dec 2024 18:21:18 +0530 Subject: [PATCH] feat: allow passing pre-computed `vars` to `observed_equations_used_by` --- src/utils.jl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index dd7113cbe6..e9ddad3a07 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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