Skip to content

Commit

Permalink
compiler: Speedup ordering of IndexDerivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Sep 18, 2023
1 parent 173ca9f commit 76e5adf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions devito/finite_differences/differentiable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sympy
from sympy.core.add import _addsort
from sympy.core.mul import _keep_coeff, _mulsort
from sympy.core.core import ordering_of_classes
from sympy.core.decorators import call_highest_priority
from sympy.core.evalf import evalf_table

Expand Down Expand Up @@ -668,6 +669,16 @@ def __new__(cls, expr, mapper, **kwargs):
def _hashable_content(self):
return super()._hashable_content() + (self.mapper,)

def compare(self, other):
if self is other:
return 0
n1 = self.__class__
n2 = other.__class__
if n1.__name__ == n2.__name__:
return self.base.compare(other.base)
else:
return super().compare(other)

@cached_property
def base(self):
return self.expr.func(*[a for a in self.expr.args if a is not self.weights])
Expand Down Expand Up @@ -700,6 +711,10 @@ def _evaluate(self, **kwargs):
return expr


ordering_of_classes.insert(ordering_of_classes.index('Derivative') + 1,
'IndexDerivative')


class EvalDerivative(DifferentiableOp, sympy.Add):

is_commutative = True
Expand Down

0 comments on commit 76e5adf

Please sign in to comment.