From e180d077a519805638506e6265aff9ceaf62bcfe Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Mon, 14 Nov 2016 08:05:03 +0100 Subject: [PATCH] Python3.3 compatibility fixes --- field.py | 10 +++++++--- typedsymbol.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/field.py b/field.py index 7fa21a000..4c58d322d 100644 --- a/field.py +++ b/field.py @@ -264,7 +264,7 @@ class Field: def _hashable_content(self): superClassContents = list(super(Field.Access, self)._hashable_content()) - t = tuple([*superClassContents, hash(self._field), self._index] + self._offsets) + t = tuple(superClassContents + [hash(self._field), self._index] + self._offsets) return t @@ -275,10 +275,14 @@ def extractCommonSubexpressions(equations): Usually called before list of equations is passed to :func:`createKernel` """ replacements, newEq = sp.cse(equations) - replacementEqs = [sp.Eq(*r) for r in replacements] + # Workaround for older sympy versions: here subexpressions (temporary = True) are extracted + # which leads to problems in Piecewise functions which have to a default case indicated by True + symbolsEqualToTrue = {r[0]: True for r in replacements if r[1] is sp.true} + + replacementEqs = [sp.Eq(*r) for r in replacements if r[1] is not sp.true] equations = replacementEqs + newEq topologicallySortedPairs = sp.cse_main.reps_toposort([[e.lhs, e.rhs] for e in equations]) - equations = [sp.Eq(*a) for a in topologicallySortedPairs] + equations = [sp.Eq(a[0], a[1].subs(symbolsEqualToTrue)) for a in topologicallySortedPairs] return equations diff --git a/typedsymbol.py b/typedsymbol.py index 675c39093..816194a91 100644 --- a/typedsymbol.py +++ b/typedsymbol.py @@ -22,5 +22,5 @@ class TypedSymbol(sp.Symbol): def _hashable_content(self): superClassContents = list(super(TypedSymbol, self)._hashable_content()) - t = tuple([*superClassContents, hash(self._dtype)]) + t = tuple(superClassContents + [hash(self._dtype)]) return t -- GitLab