Commit 9f76ea1d authored by Martin Bauer's avatar Martin Bauer
Browse files

Merge branch 'infinity' into 'master'

Fix printing of sp.Infinity/sp.NegativeInfinity

See merge request pycodegen/pystencils!71
parents 96a28eb8 dd28d031
......@@ -350,7 +350,7 @@ class CustomSympyPrinter(CCodePrinter):
return "&(%s)" % self._print(expr.args[0])
elif isinstance(expr, cast_func):
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 "((%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