MatchResult¶
- class onnxscript.rewriter.pattern.MatchResult[source]¶
The state object used by the pattern-matching algorithm.
A match can either succeed or fail. If it succeeds, it returns a list of nodes that matched the pattern and a set of bindings for the variables in the pattern.
Example:
def pattern(x, shape1, shape2): t1 = op.Reshape(x, shape1) t2 = op.Reshape(t1, shape2) return t2
The above pattern matches a sequence of two Reshape ops. The matched_nodes will contain the two Reshape ops, and the bindings will contain the values that are bound to the variables x, shape1, and shape2.
- abandon_current_match() PartialMatchResult [source]¶
Abandons the current alternative due to failure.
- merge_current_match() None [source]¶
Merges a successful sub-match for an alternative with the parent one.
- fail(reason: str = '', failure_source: Node | Value | list[Node | Value] | None = None) MatchResult [source]¶
- bind_node(pattern_node: _pattern_ir.NodePattern, node: ir.Node)[source]¶
Binds a pattern node to a matched node.
- property value_bindings: dict[_pattern_ir.ValuePattern, ir.Value]¶
Returns the bindings for the value variables.
- property node_bindings: dict[_pattern_ir.NodePattern, ir.Node]¶
Returns the bindings for the node variables.
- property outputs: MutableSequence[Value]¶
Returns the list of output values that matched the pattern.
- property failure_nodes_and_values: list[Node | Value]¶
Returns the nodes and values that caused the failure.