From 7b0607443c98bb46d2bc8bb683ebfcb57bea02b1 Mon Sep 17 00:00:00 2001
From: markus <markus.holzer@fau.de>
Date: Wed, 17 Jun 2020 17:12:31 +0200
Subject: [PATCH] Fix identification of interger type in abs functions

---
 pystencils/backends/cbackend.py |  2 +-
 pystencils_tests/test_abs.py    | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 pystencils_tests/test_abs.py

diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py
index 46d9e3a77..3552aeea4 100644
--- a/pystencils/backends/cbackend.py
+++ b/pystencils/backends/cbackend.py
@@ -362,7 +362,7 @@ class CustomSympyPrinter(CCodePrinter):
         return result.replace("\n", "")
 
     def _print_Abs(self, expr):
-        if expr.is_integer:
+        if expr.args[0].is_integer:
             return 'abs({0})'.format(self._print(expr.args[0]))
         else:
             return 'fabs({0})'.format(self._print(expr.args[0]))
diff --git a/pystencils_tests/test_abs.py b/pystencils_tests/test_abs.py
new file mode 100644
index 000000000..53917bcc6
--- /dev/null
+++ b/pystencils_tests/test_abs.py
@@ -0,0 +1,19 @@
+import sympy
+
+import pystencils
+from pystencils.data_types import cast_func, create_type
+
+
+def test_abs():
+    x, y, z = pystencils.fields('x, y, z:  float64[2d]')
+
+    default_int_type = create_type('int64')
+
+    assignments = pystencils.AssignmentCollection({
+        x[0, 0]: sympy.Abs(cast_func(y[0, 0], default_int_type))
+    })
+
+    ast = pystencils.create_kernel(assignments, target="gpu")
+    code = pystencils.get_code_str(ast)
+    print(code)
+    assert 'fabs(' not in code
-- 
GitLab