From 774606b1c0c0f3550110133c89a2c5106887b746 Mon Sep 17 00:00:00 2001 From: Fabio Luporini Date: Mon, 26 Feb 2024 13:55:45 +0000 Subject: [PATCH] compiler: Hotfix unevaluation.Pow(1, ...) --- devito/symbolics/unevaluation.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/devito/symbolics/unevaluation.py b/devito/symbolics/unevaluation.py index 44a3273e54..38b0621d13 100644 --- a/devito/symbolics/unevaluation.py +++ b/devito/symbolics/unevaluation.py @@ -18,4 +18,13 @@ class Mul(sympy.Mul, UnevaluableMixin): class Pow(sympy.Pow, UnevaluableMixin): - __new__ = UnevaluableMixin.__new__ + + def __new__(cls, base, exp, evaluate=None, **kwargs): + if base == 1: + # Otherwise we might get trapped within vicious recursion inside + # SymPy each time it tries to perform a simplification via + # `as_numer_denom`, since the `denom` turns into a Pow itself + # such as `1**c` + return sympy.S.One + else: + return cls.__base__.__new__(cls, base, exp, evaluate=False, **kwargs)