From 1de99ef069269dd5580ba60eec2e0d98a91b9861 Mon Sep 17 00:00:00 2001
From: Your Name <stephan.seitz@fau.de>
Date: Wed, 28 Aug 2019 11:13:56 +0200
Subject: [PATCH] Add printing support for
 re,im,ImaginaryUnit,_typed_number(**complex**) to CustomSympyPrinter

---
 pystencils/backends/cbackend.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py
index 239f060e..4e7c5cf2 100644
--- a/pystencils/backends/cbackend.py
+++ b/pystencils/backends/cbackend.py
@@ -380,6 +380,10 @@ class CustomSympyPrinter(CCodePrinter):
             return res + '.0f' if '.' not in res else res + 'f'
         elif dtype.numpy_dtype == np.float64:
             return res + '.0' if '.' not in res else res
+        elif dtype.numpy_dtype == np.complex64:
+            return f"{_typed_number(number.real, np.float32)} + {_typed_number(number.real, np.float32).replace('f', 'if')}"
+        elif dtype.numpy_dtype == np.complex128:
+            return f"{_typed_number(number.real, np.float64)} + {_typed_number(number.real, np.float64)}i"
         else:
             return res
 
@@ -431,6 +435,15 @@ class CustomSympyPrinter(CCodePrinter):
     _print_Max = C89CodePrinter._print_Max
     _print_Min = C89CodePrinter._print_Min
 
+    def _print_re(self, expr):
+        return f"std::real({self._print(expr.args[0])})"
+
+    def _print_im(self, expr):
+        return f"std::imag({self._print(expr.args[0])})"
+
+    def _print_ImaginaryUnit(self, expr):
+        return "1if"
+        
 
 # noinspection PyPep8Naming
 class VectorizedCustomSympyPrinter(CustomSympyPrinter):
-- 
GitLab