Skip to content

Commit ec878f7

Browse files
committed
add seen set
1 parent b2b7e28 commit ec878f7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pytensor/graph/basic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,13 +1088,18 @@ def truncated_graph_inputs(
10881088
return truncated_inputs
10891089

10901090
blockers: Set[Variable] = set(ancestors_to_include)
1091+
# variables that go here are under check already, do not repeat the loop for them
1092+
seen: Set[Variable] = set()
10911093
# enforce O(1) check for node in ancestors to include
10921094
ancestors_to_include = blockers.copy()
10931095

10941096
while candidates:
10951097
# on any new candidate
10961098
node = candidates.pop()
1097-
1099+
if node in seen:
1100+
continue
1101+
else:
1102+
seen.add(node)
10981103
# There was a repeated reference to this node, we have already investigated it
10991104
if node in truncated_inputs:
11001105
continue

0 commit comments

Comments
 (0)