Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWeber42 committed Jun 19, 2024
1 parent 42a8f38 commit fe23f49
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions dace/sdfg/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import networkx as nx
from dace.dtypes import deduplicate
import dace.serialize
from typing import Any, Callable, Generic, Iterable, List, Sequence, TypeVar, Union
from typing import Any, Callable, Generic, Iterable, List, Optional, Sequence, TypeVar, Union


class NodeNotFoundError(Exception):
Expand Down Expand Up @@ -364,19 +364,19 @@ def sink_nodes(self) -> List[NodeT]:
"""Returns nodes with no outgoing edges."""
return [n for n in self.nodes() if self.out_degree(n) == 0]

def bfs_nodes(self, source: NodeT = None) -> Sequence[NodeT]:
"""Returns nodes in topological order iff the graph contains exactly
one node with no incoming edges."""
def bfs_nodes(self, source: Optional[NodeT] = None) -> Iterable[NodeT]:
"""Returns an iterable over nodes traversed in breadth-first search
order starting from ``source``."""
if source is not None:
sources = [source]
else:
sources = self.source_nodes()
if len(sources) == 0:
sources = [self.nodes()[0]]
#raise RuntimeError("No source nodes found")
if len(sources) > 1:
sources = [self.nodes()[0]]
#raise RuntimeError("Multiple source nodes found")
if len(sources) != 1:
source = next(iter(self.nodes()), None)
if source is None:
return [] # graph has no nodes
sources = [source]

seen = OrderedDict() # No OrderedSet in Python
queue = deque(sources)
while len(queue) > 0:
Expand Down

0 comments on commit fe23f49

Please sign in to comment.