-
Notifications
You must be signed in to change notification settings - Fork 25
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
Do not simplify in overloaded operators, type mappers #152
base: main
Are you sure you want to change the base?
Conversation
c8e444f
to
4190844
Compare
4190844
to
e194173
Compare
0c76ffa
to
a787ba3
Compare
2c129f2
to
f41f938
Compare
|
||
class FlattenMapper(IdentityMapper[[]]): |
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.
@alexfikl This PR bumps the compat target to 3.10. The immediate reason was this inheritance, which is illegal in 3.9 and below. It can be hacked around, but it would have to be hacked around in a lot of places. 3.8 is EOL as of a few weeks ago, and I'm not sure I'm too enamored with supporting 3.9. Current numpy also has a 3.10 minimum. The net implication is that the whole stack will probably switch before too long. There's some ruff type annotation churn that results, but it's probably for the best to get that out of the way. How do you feel about that idea?
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.
That sounds good to me. I've also jumped directly to 3.10 with most of my random code due to numpy bumping it. What's the conda default python these days?
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.
Also, I'm not sure I've ever seen this before. What's IdentityMapper[[]]
supposed to mean?
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.
The corresponding type parameter on IdentityMapper
is a ParamSpec
for i.e. the extra arguments that get passed around by the mapper methods.
https://docs.python.org/3.13/library/typing.html#user-defined-generic-types says
The one exception to this is that a list of types can be used to substitute a ParamSpec
Based on the failures on 3.8 and 3.9, this must be a relatively recent thing.
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.
Took a swift look over this and it looks good to me. Downstreams seem very upset with it though :(
|
||
class FlattenMapper(IdentityMapper[[]]): |
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.
Also, I'm not sure I've ever seen this before. What's IdentityMapper[[]]
supposed to mean?
They sure are. I'm trying to figure out whether the damage can be controlled or whether we need to do this in a more piecemeal fashion. |
f77d984
to
0d03277
Compare
0d03277
to
de7caf5
Compare
de7caf5
to
e355f08
Compare
diff --git a/pymbolic/geometric_algebra/__init__.py b/pymbolic/geometric_algebra/__init__.py
index fbc7e30..4291b74 100644
--- a/pymbolic/geometric_algebra/__init__.py
+++ b/pymbolic/geometric_algebra/__init__.py
@@ -526,6 +526,7 @@ class MultiVector(Generic[CoeffT]):
"""
space: Space
+ mapper_method = "map_multivector"
# {{{ construction
diff --git a/pymbolic/mapper/coefficient.py b/pymbolic/mapper/coefficient.py
index 99516f0..b09b4f6 100644
--- a/pymbolic/mapper/coefficient.py
+++ b/pymbolic/mapper/coefficient.py
@@ -100,6 +100,9 @@ class CoefficientCollector(Mapper):
return {1: expr}
def map_constant(self, expr):
+ if expr == 0:
+ return {}
+
return {1: expr}
def map_algebraic_leaf(self, expr):
EDIT: Well, that was wrong, there are other errors too :( |
e355f08
to
802b5aa
Compare
b2b4fc0
to
f44d2d0
Compare
Co-authored-by: Alexandru Fikl <[email protected]>
Co-authored-by: Alexandru Fikl <[email protected]>
f44d2d0
to
e8088f5
Compare
Closes #11.
Closes #149.
What finally tipped the balance is that the overload-y operators are hard to precisely type, which made typing various downstream user packages unnecessarily hard.
cc @kaushikcfd