Commit dd28d031 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Fix printing of sp.Infinity/sp.NegativeInfinity

For sympy, oo s a number. So pystencils prints a type infinity a double
parent 96a28eb8
...@@ -350,7 +350,7 @@ class CustomSympyPrinter(CCodePrinter): ...@@ -350,7 +350,7 @@ class CustomSympyPrinter(CCodePrinter):
return "&(%s)" % self._print(expr.args[0]) return "&(%s)" % self._print(expr.args[0])
elif isinstance(expr, cast_func): elif isinstance(expr, cast_func):
arg, data_type = expr.args arg, data_type = expr.args
if isinstance(arg, sp.Number): if isinstance(arg, sp.Number) and arg.is_finite:
return self._typed_number(arg, data_type) return self._typed_number(arg, data_type)
else: else:
return "((%s)(%s))" % (data_type, self._print(arg)) return "((%s)(%s))" % (data_type, self._print(arg))
import pytest
import pystencils
from sympy import oo
@pytest.mark.parametrize('type', ('float32', 'float64', 'int64'))
@pytest.mark.parametrize('negative', (False, 'Negative'))
@pytest.mark.parametrize('target', ('cpu', 'gpu'))
def test_print_infinity(type, negative, target):
x = pystencils.fields(f'x: {type}[1d]')
if negative:
assignment = pystencils.Assignment(, -oo)
assignment = pystencils.Assignment(, oo)
ast = pystencils.create_kernel(assignment, data_type=type, target=target)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment