Skip to content

Commit a21171c

Browse files
committed
sympy: Prevent infinite recursion when checking equality
1 parent a1b9b61 commit a21171c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

devito/finite_differences/differentiable.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,16 @@ def __neg__(self):
263263
return Mul(sympy.S.NegativeOne, self)
264264

265265
def __eq__(self, other):
266-
ret = super().__eq__(other)
266+
from devito.finite_differences import Derivative
267+
# Prevent recustion if other is also of derivative type
268+
if type(self) is type(other) is Derivative:
269+
# `sympy.Derivative.__eq__(self, other)` also recurses
270+
ret = self.expr == other.expr
271+
ret &= self.dimensions == other.dimensions
272+
ret &= self.derivative_count == other.derivative_count
273+
ret &= self.deriv_order == other.deriv_order
274+
else:
275+
ret = super().__eq__(other)
267276
if ret is NotImplemented or not ret:
268277
# Non comparable or not equal as sympy objects
269278
return False

0 commit comments

Comments
 (0)