From 102f07f860a7ff2b5a6b1823b50cc4b2fd7368dd Mon Sep 17 00:00:00 2001 From: Nils Kohl <nils.kohl@fau.de> Date: Mon, 20 May 2019 10:04:44 +0200 Subject: [PATCH] Added NoEvaluationPiecewise. This is a sympy.Piecewise wrapper that sets evaluate=False to avoid expensive simplifications during the kernel generation. --- pystencils/backends/cbackend.py | 3 +++ pystencils/sympyextensions.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py index 92a6080c7..18fd1d344 100644 --- a/pystencils/backends/cbackend.py +++ b/pystencils/backends/cbackend.py @@ -263,6 +263,9 @@ class CustomSympyPrinter(CCodePrinter): result = super(CustomSympyPrinter, self)._print_Piecewise(expr) return result.replace("\n", "") + def _print_NoEvaluationPiecewise(self, expr): + return self._print_Piecewise(expr) + def _print_Function(self, expr): infix_functions = { bitwise_xor: '^', diff --git a/pystencils/sympyextensions.py b/pystencils/sympyextensions.py index 86614a212..db5a6792e 100644 --- a/pystencils/sympyextensions.py +++ b/pystencils/sympyextensions.py @@ -580,3 +580,10 @@ def sort_assignments_topologically(assignments: Sequence[Assignment]) -> List[As class SymbolCreator: def __getattribute__(self, name): return sp.Symbol(name) + + +class NoEvaluationPiecewise(sp.Piecewise): + def __new__(cls, *args, **kwargs): + kwargs['evaluate'] = False + obj = super(NoEvaluationPiecewise, cls).__new__(cls, *args, **kwargs) + return obj -- GitLab