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

compiler: Patch premature lowering of EvalDerivative #1979

Merged
merged 3 commits into from Aug 2, 2022

Conversation

FabioLuporini
Copy link
Contributor

fixes #1978

@codecov
Copy link

codecov bot commented Jul 29, 2022

Codecov Report

Merging #1979 (374a158) into master (45504b6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           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           
Impacted Files Coverage Δ
devito/finite_differences/differentiable.py 95.19% <100.00%> (-0.37%) ⬇️
tests/test_derivatives.py 100.00% <100.00%> (ø)
tests/test_dse.py 99.79% <100.00%> (+<0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us.

Copy link
Contributor

@mloubout mloubout left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

-a ?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

-a ?

Copy link
Contributor Author

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:
Copy link
Contributor

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:
Copy link
Contributor

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?

Copy link
Contributor Author

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

@FabioLuporini
Copy link
Contributor Author

pushed edits

@FabioLuporini
Copy link
Contributor Author

note latest pep8-related commit necessary due to https://github.com/devitocodes/devito/runs/7605926638?check_suite_focus=true

@FabioLuporini FabioLuporini merged commit 3d31436 into master Aug 2, 2022
@FabioLuporini FabioLuporini deleted the patch-evalderiv-lowering branch August 2, 2022 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Premature lowering of EvalDerivative
4 participants