Skip to content

Commit 33f31ca

Browse files
authored
Add support for backtracking in pattern matcher (#2273)
Extends the recently introduced "Or" patterns fully (without any restrictions). The general case is handled via backtracking. The Or pattern constructor function will automatically determine whether the optimized (deterministic) matching implementation can be used or if the backtracking-based implementation should be used.
1 parent 3bd6a79 commit 33f31ca

File tree

3 files changed

+310
-129
lines changed

3 files changed

+310
-129
lines changed

onnxscript/rewriter/generic_pattern.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def _to_match_result(pmr: PatternMatchResult) -> orp.MatchResult:
8383
TODO: This is a temporary hack until MatchResult and PatternMatchResult are unified.
8484
"""
8585
result = orp.MatchResult()
86-
result.nodes.extend(pmr.model_nodes)
86+
for node in pmr.model_nodes:
87+
result.add_node(node)
88+
8789
for var, val in pmr.matched_pattern_to_model_value.items():
8890
if var.name is not None:
8991
result.bind(var.name, val)

0 commit comments

Comments
 (0)