Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass match object to conditional function. #2088

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rezaasjd
Copy link

@rezaasjd rezaasjd commented Mar 4, 2025

Match object can be used to single out a replacement to a pattern that was matched if the user intends to.
This would be helpful since node.name is not passed to replacer functions and as a result user cannot have logic based on the node names that were part of the match.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR updates the conditional function invocation in the pattern rewriter so that the full match object is passed instead of a placeholder context.

  • Removed the unused assignment of a dummy context.
  • Updated the _condition_function call to receive the match object for improved flexibility in node-based logic.

Reviewed Changes

File Description
onnxscript/rewriter/pattern.py Updated _condition_function call to pass the match object and removed redundant context assignment.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

onnxscript/rewriter/pattern.py:1373

  • Ensure that _condition_function is updated to accept a MatchResult object instead of a context parameter and that its documentation reflects this new interface.
if not self._condition_function(match, **match.bindings):

onnxscript/rewriter/pattern.py:1368

  • Remove the obsolete 'context = None' assignment since it is no longer used after passing the match object.
context = None  # TODO(rama)
Copy link

codecov bot commented Mar 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.21%. Comparing base (6edcfd5) to head (1772780).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2088      +/-   ##
==========================================
- Coverage   72.21%   72.21%   -0.01%     
==========================================
  Files         217      217              
  Lines       29023    29022       -1     
  Branches     3442     3442              
==========================================
- Hits        20960    20959       -1     
  Misses       6935     6935              
  Partials     1128     1128              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

1 participant