-
Notifications
You must be signed in to change notification settings - Fork 16
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
Equality comparison mapper #166
Conversation
343b4d0
to
859b387
Compare
74e42b4
to
bd1c612
Compare
This is ready. The time taken by the |
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.
Thanks for working on this! A few questions below, but generally this looks good.
pytato/transform.py
Outdated
raise NotImplementedError | ||
|
||
def map_placeholder(self, expr1: Placeholder, expr2: Any) -> bool: | ||
return (isinstance(expr2, Placeholder) |
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.
isinstance
isn't precise enough, since the object might compare equal to its subclass. I think the types need to match. (Yes, that was a bug in the original __eq__
.)
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.
Went with expr1.__class__ is expr2.__class__
7847d63
to
4ee85e3
Compare
4ee85e3
to
2b47d9a
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.
Thanks! A few more superficial bits, then this is good to go.
pytato/equality.py
Outdated
|
||
def handle_unsupported_array(self, expr1: Array, | ||
expr2: Any) -> bool: | ||
raise NotImplementedError |
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.
I think it'd be good to have an intelligible messages here.
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.
Added the type name. Thanks!
pytato/equality.py
Outdated
raise NotImplementedError | ||
|
||
def map_foreign(self, expr1: Any, expr2: Any) -> bool: | ||
raise NotImplementedError |
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.
I think it'd be good to have an intelligible messages here.
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.
Added the type name. Thanks!
pytato/equality.py
Outdated
from pytato.loopy import LoopyCall | ||
|
||
__doc__ = """ | ||
.. currentmodule:: pytato.equality |
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.
.. currentmodule:: pytato.equality |
(not needed)
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.
Done.
if TYPE_CHECKING: | ||
from pytato.loopy import LoopyCall | ||
|
||
__doc__ = """ |
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.
Should this be hooked into the external docs somewhere?
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.
Done.
pytato/equality.py
Outdated
# }}} | ||
|
||
|
||
def is_structurally_equivalent(expr1: ArrayOrNames, expr2: Any) -> bool: |
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.
- Not loving the name.
equivalent
suggests something more restrictive than equal. - Why not just call
EqualityComparisonMapper()(expr1, expr2)
in__eq__
?
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.
Ok, got rid of it.
pytato/equality.py
Outdated
|
||
# {{{ EqualityComparisonMapper | ||
|
||
class EqualityComparisonMapper: |
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.
class EqualityComparisonMapper: | |
class EqualityComparer: |
?
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.
Sure.
pytato/equality.py
Outdated
.. note:: | ||
|
||
Complexity: :math:`O(N)`, where :math:`N` is the number of nodes in | ||
*expr1*. |
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.
This could get moved to the EqualityComparer
docstring.
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.
Done.
# {{{ EqualityComparisonMapper | ||
|
||
class EqualityComparisonMapper: | ||
def __init__(self) -> None: |
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.
Add a docstring justifying why this object exists (to host caches for equality comparison, and that comparison might be exponential without it).
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.
Done.
Co-authored-by: Andreas Kloeckner <inform@tiker.net>
2b47d9a
to
1d31563
Compare
Thanks! |
Closes #163