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
compiler: Patch premature lowering of EvalDerivative #1979
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1979 +/- ##
=======================================
Coverage 87.90% 87.90%
=======================================
Files 214 214
Lines 36213 36232 +19
Branches 5461 5465 +4
=======================================
+ Hits 31832 31849 +17
- Misses 3866 3868 +2
Partials 515 515
Help us with your feedback. Take ten seconds to tell us how you rate us. |
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.
Some comments but nice catch and yest these 1.0
where a pain
@@ -423,14 +423,30 @@ def __new__(cls, *args, **kwargs): | |||
# a*1 -> a | |||
args = [i for i in args if i != 1] | |||
|
|||
# a*-1 -> a |
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.
-a ?
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.
good catch. will put a*-1
(see below)
# a*-1*-1 -> a | ||
# a*-1*-1*-1 -> a*-1 |
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.
-a ?
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 arguments are a
and -1
(unless a
it's an integer) that's why it's not factored out
# will preserve the integrity of `EvalDerivative`s, if any. | ||
try: | ||
a, b = args | ||
if not a.is_zero and a.is_Rational: |
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.
a.is_zero
is un-necessary would have been cought line 420 already.
a, b = args | ||
if not a.is_zero and a.is_Rational: | ||
r, b = b.as_coeff_Mul() | ||
if r is sympy.S.One and type(b) is Add: |
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.
Can this be generalized to like r is sympy.Number
or r.is_Symbol
and merge it with a
?
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.
for the record, I lifted it from sympy
https://github.com/sympy/sympy/blob/master/sympy/core/mul.py#L285
tho admittedly a slightly older version than the one I have installed locally
I will try to improve it
pushed edits |
note latest pep8-related commit necessary due to https://github.com/devitocodes/devito/runs/7605926638?check_suite_focus=true |
fixes #1978