Skip to content

Commit f48c20c

Browse files
committed
Create the convenience methods i() and o() on Node
1 parent 77fc946 commit f48c20c

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/onnx_ir/_core.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,40 @@ def inputs(self, _: Any) -> None:
15521552
"Directly mutating the input sequence is unsupported. Please use Node.replace_input_with() instead."
15531553
)
15541554

1555+
@property
1556+
def outputs(self) -> Sequence[Value]:
1557+
"""The output values of the node.
1558+
1559+
The outputs are immutable. To change the outputs, create a new node and
1560+
replace the inputs of the using nodes of this node's outputs by calling
1561+
:meth:`replace_input_with` on the using nodes of this node's outputs.
1562+
"""
1563+
return self._outputs
1564+
1565+
@outputs.setter
1566+
def outputs(self, _: Sequence[Value]) -> None:
1567+
raise AttributeError("outputs is immutable. Please create a new node instead.")
1568+
1569+
def i(self, index: int = 0) -> Value | None:
1570+
"""Get the input value at the given index.
1571+
1572+
This is a convenience method that is equivalent to `self.inputs[index]`.
1573+
1574+
Raises:
1575+
IndexError: If the index is out of range.
1576+
"""
1577+
return self.inputs[index]
1578+
1579+
def o(self, index: int = 0) -> Value:
1580+
"""Get the output value at the given index.
1581+
1582+
This is a convenience method that is equivalent to `self.outputs[index]`.
1583+
1584+
Raises:
1585+
IndexError: If the index is out of range.
1586+
"""
1587+
return self.outputs[index]
1588+
15551589
def predecessors(self) -> Sequence[Node]:
15561590
"""Return the predecessor nodes of the node, deduplicated, in a deterministic order."""
15571591
# Use the ordered nature of a dictionary to deduplicate the nodes
@@ -1622,20 +1656,6 @@ def append(self, /, nodes: Node | Iterable[Node]) -> None:
16221656
raise ValueError("The node to append to does not belong to any graph.")
16231657
self._graph.insert_after(self, nodes)
16241658

1625-
@property
1626-
def outputs(self) -> Sequence[Value]:
1627-
"""The output values of the node.
1628-
1629-
The outputs are immutable. To change the outputs, create a new node and
1630-
replace the inputs of the using nodes of this node's outputs by calling
1631-
:meth:`replace_input_with` on the using nodes of this node's outputs.
1632-
"""
1633-
return self._outputs
1634-
1635-
@outputs.setter
1636-
def outputs(self, _: Sequence[Value]) -> None:
1637-
raise AttributeError("outputs is immutable. Please create a new node instead.")
1638-
16391659
@property
16401660
def attributes(self) -> OrderedDict[str, Attr]:
16411661
"""The attributes of the node."""

0 commit comments

Comments
 (0)