Skip to content

Commit

Permalink
opt ancestors
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasdiener authored and inducer committed Nov 28, 2024
1 parent 706e873 commit 9726d9b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions loopy/schedule/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ def ancestors(self, node: NodeT) -> tuple[NodeT, ...]:
"""
Returns a :class:`tuple` of nodes that are ancestors of *node*.
"""
if self.is_root(node):
parent = self.parent(node)
if parent is None:
# => root
return ()

parent = self._child_to_parent[node]
assert parent is not None

return (parent, *self.ancestors(parent))

def parent(self, node: NodeT) -> NodeT | None:
Expand Down

0 comments on commit 9726d9b

Please sign in to comment.