-
Notifications
You must be signed in to change notification settings - Fork 13
Support methods like __array_function__ on expressions
#315
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
Conversation
Adds support for methods like `__array_function__` which actually need to be added on the class as actual methods, not through overloading `__getattr__`. Custom methods can be registered by third party libraries. This PR also redoes the logic for upcasting when using binary operations. Instead of upcasting both values, it will only ever upcast one, choosing whichever one would be cheaper to upcast. This leads to more predictable behavior.
2ccaad7 to
ea91781
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for methods that need to be defined directly on classes as actual methods (not through __getattr__ overloading), such as __array_function__, and redesigns the binary operation upcasting logic to upcast only one operand (choosing the cheaper conversion) instead of both.
- Introduces a new mechanism for registering methods directly on runtime types for third-party library compatibility
- Completely refactors binary operation logic to find the minimum cost conversion between operands
- Removes the previous
test_upcast_argstest and updates related snapshot files
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| python/egglog/runtime.py | Core implementation of new method registration system and binary operation logic |
| python/egglog/declarations.py | Adds type matching methods for binary operations and type variable handling |
| python/egglog/conversion.py | Updates conversion utilities and removes old min conversion logic |
| python/egglog/egraph.py | Updates ignored method list to use new numeric binary methods constant |
| python/egglog/init.py | Exports new define_expr_method function |
| python/tests/test_high_level.py | Removes obsolete upcast test |
| python/tests/snapshots/test_array_api/ | Updates snapshots to reflect new expression optimization |
| docs/reference/python-integration.md | Documents the new method registration feature |
Co-authored-by: Copilot <[email protected]>
__array_function__ on expressions
CodSpeed WallTime Performance ReportMerging #315 will not alter performanceComparing Summary
|
CodSpeed Instrumentation Performance ReportMerging #315 will not alter performanceComparing Summary
|
Adds support for methods like
__array_function__which actually need to be added on the class as actual methods, not through overloading__getattr__. Custom methods can be registered by third party libraries.This PR also redoes the logic for upcasting when using binary operations. Instead of upcasting both values, it will only ever upcast one, choosing whichever one would be cheaper to upcast. This leads to more predictable behavior.