Function¶
- class onnx_ir.Function(domain: str, name: str, overload: str = '', *, graph: Graph, attributes: Sequence[Attr])¶
IR functions.
Like a graph, a function can have nodes that are not topologically sorted. It is the responsibility of the user to maintain a topological order of the nodes.
Note that there is not a
node
attribute in the Function. The Function can be seen as a Sequence of nodes and should be used as such. For example, to obtain all nodes as a list, calllist(function)
.- name¶
The function name.
- domain¶
The domain this function is defined in.
- overload¶
The overload name when the function is overloaded.
- inputs¶
The input values of the function.
- attributes¶
The attributes this function defines.
- outputs¶
The output values of the function.
- opset_imports¶
Opsets imported by the function.
- doc_string¶
Documentation string.
- meta¶
Metadata store for graph transform passes.
- metadata_props¶
Metadata that will be serialized to the ONNX file.
- property attributes: OrderedDict[str, Attr]¶
- count(value) integer -- return number of occurrences of value ¶
- display(*, page: bool = False) None ¶
Pretty print the object.
- Parameters:
page – Whether to page the output.
- extend(nodes: Iterable[Node], /) None [source]¶
Extend the function with the given nodes in O(#new_nodes) time.
- index(value[, start[, stop]]) integer -- return first index of value. ¶
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- property inputs: MutableSequence[Value]¶
- insert_after(node: Node, new_nodes: Iterable[Node] | Node, /) None [source]¶
Insert new nodes after the given node in O(#new_nodes) time.
- insert_before(node: Node, new_nodes: Iterable[Node] | Node, /) None [source]¶
Insert new nodes before the given node in O(#new_nodes) time.
- property meta: MetadataStore¶
The metadata store for intermediate analysis.
Write to the
metadata_props
if you would like the metadata to be serialized to the ONNX proto.
- property outputs: MutableSequence[Value]¶
- remove(nodes: Node | Iterable[Node], /, safe: bool = False) None [source]¶
Remove nodes from the graph in O(#num of nodes) time.
If any errors are raise, to ensure the graph is not left in an inconsistent state, the graph is not modified.
- Parameters:
nodes – The node to remove.
safe –
If True, performs the following actions before removal:
1. It checks to make sure there are no users of the node that are not to be removed before removing it. 2. It checks the node does not contribute to any graph outputs. 3. It removes references to all inputs so it is no longer a user of other nodes.
- Raises:
ValueError – If any node to remove does not belong to this graph.
ValueError – (When
safe=True
) If the node does not belong to this graph or if there are users of the node.ValueError – (When
safe=True
) If the node is still being used by other nodes not to be removed.