Skip to content

Commit 97c3e61

Browse files
Copilotgramalingam
andcommitted
Rename main_root_node property to root in MatchContext
Co-authored-by: gramalingam <10075881+gramalingam@users.noreply.github.com>
1 parent e8560f7 commit 97c3e61

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

docs/tutorial/rewriter/conditional_rewrite.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The MatchContext provides the following read-only properties:
6161

6262
- `model`: The entire ONNX model being matched
6363
- `graph_or_function`: The specific graph or function being matched
64-
- `main_root_node`: The primary root node of the matching subgraph
64+
- `root`: The root node of the matching subgraph
6565
- `output_values`: The output values of the matching subgraph
6666
- `nodes`: All nodes that are part of the matching subgraph
6767

@@ -74,7 +74,7 @@ def advanced_condition_check(context, x, y, **_):
7474
"""Example condition function using MatchContext."""
7575

7676
# Access the main node of the pattern match
77-
main_node = context.main_root_node
77+
main_node = context.root
7878

7979
# Check that the main_node does not have an attribute called "alpha"
8080
if "alpha" in main_node.attributes:

onnxscript/rewriter/_basics.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,28 +344,28 @@ class MatchContext:
344344
"""A read-only context containing information about a pattern match.
345345
346346
This class captures information about the context describing a match to a given pattern,
347-
providing access to the model, graph/function, main root node, output values, and all
347+
providing access to the model, graph/function, root node, output values, and all
348348
nodes of the matching subgraph.
349349
"""
350350

351351
def __init__(
352352
self,
353353
model: ir.Model,
354354
graph_or_function: ir.Graph | ir.Function,
355-
main_root_node: ir.Node,
355+
root: ir.Node,
356356
match_result: MatchResult,
357357
) -> None:
358358
"""Initialize the pattern match context.
359359
360360
Args:
361361
model: The model being matched.
362362
graph_or_function: The graph or function being matched.
363-
main_root_node: The main root node of the matching subgraph.
363+
root: The root node of the matching subgraph.
364364
match_result: The match result containing matched nodes and outputs.
365365
"""
366366
self._model = model
367367
self._graph_or_function = graph_or_function
368-
self._main_root_node = main_root_node
368+
self._root = root
369369
self._match_result = match_result
370370

371371
@property
@@ -379,9 +379,9 @@ def graph_or_function(self) -> ir.Graph | ir.Function:
379379
return self._graph_or_function
380380

381381
@property
382-
def main_root_node(self) -> ir.Node:
383-
"""The main root node of the matching subgraph."""
384-
return self._main_root_node
382+
def root(self) -> ir.Node:
383+
"""The root node of the matching subgraph."""
384+
return self._root
385385

386386
@property
387387
def output_values(self) -> Sequence[ir.Value]:

onnxscript/rewriter/match_context_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def condition_using_context(context, x, y):
3131
# Use context to check properties of the match
3232
self.assertIs(context.model, model)
3333
self.assertIs(context.graph_or_function, model.graph)
34-
self.assertIs(context.main_root_node, model.graph[2])
34+
self.assertIs(context.root, model.graph[2])
3535

3636
# Verify that we can inspect the matched nodes
3737
self.assertEqual(len(context.nodes), 2)

0 commit comments

Comments
 (0)