Skip to content

Commit

Permalink
Don't return order edges in in/out_edges instead
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Jan 10, 2024
1 parent e12fab8 commit f8d8173
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions guppy/hugr/hugr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
FunctionType,
GuppyType,
Inst,
NoneType,
SumType,
TupleType,
row_to_type,
Expand Down Expand Up @@ -155,21 +154,15 @@ def in_port(self, offset: PortOffset | None) -> InPortV:
"""Returns the input port at the given offset."""
assert offset is not None
assert offset < self.num_in_ports
if offset < 0:
# Order edge
return InPortV(self, len(self.in_port_types), NoneType())
else:
return InPortV(self, offset, self.in_port_types[offset])
assert offset != -1, "Cannot get the port of an order edge"
return InPortV(self, offset, self.in_port_types[offset])

def out_port(self, offset: PortOffset | None) -> OutPortV:
"""Returns the output port at the given offset."""
assert offset is not None
assert offset < self.num_out_ports
if offset < 0:
# Order edge
return OutPortV(self, len(self.out_port_types), NoneType())
else:
return OutPortV(self, offset, self.out_port_types[offset])
assert offset != -1, "Cannot get the port of an order edge"
return OutPortV(self, offset, self.out_port_types[offset])

@property
def in_ports(self) -> Iterator[InPortV]:
Expand Down Expand Up @@ -622,13 +615,17 @@ def order_edges(self) -> Iterator[OrderEdge]:
def in_edges(self, port: InPort) -> Iterator[Edge]:
"""Returns an iterator over all edges connected to a given in-port."""
for e in self._graph.in_edges(port.node.idx, keys=True):
if e[2] == ORDER_EDGE_KEY:
continue
src, tgt = self._to_edge(*e)
if tgt.offset == port.offset:
yield src, tgt

def out_edges(self, port: OutPort) -> Iterator[Edge]:
"""Returns an iterator over all edges originating from a given out-port."""
for e in self._graph.out_edges(port.node.idx, keys=True):
if e[2] == ORDER_EDGE_KEY:
continue
src, tgt = self._to_edge(*e)
if src.offset == port.offset:
yield src, tgt
Expand Down

0 comments on commit f8d8173

Please sign in to comment.