Skip to content
Snippets Groups Projects

[Fix] Printing of subtraction

Merged Markus Holzer requested to merge holzer/pystencils:FixSubtraction into master
Viewing commit 2a95e87e
Next
Show latest version
1 file
+ 52
0
Preferences
Compare changes
import pytest
import sympy as sp
import pystencils
from sympy import oo
from pystencils.backends.cbackend import CBackend
class UnsupportedNode(pystencils.astnodes.Node):
def __init__(self):
super().__init__()
@pytest.mark.parametrize('type', ('float32', 'float64', 'int64'))
@@ -12,9 +19,9 @@ def test_print_infinity(type, negative, target):
x = pystencils.fields(f'x: {type}[1d]')
if negative:
assignment = pystencils.Assignment(x.center, -oo)
assignment = pystencils.Assignment(x.center, -sp.oo)
else:
assignment = pystencils.Assignment(x.center, oo)
assignment = pystencils.Assignment(x.center, sp.oo)
ast = pystencils.create_kernel(assignment, data_type=type, target=target)
if target == pystencils.Target.GPU:
@@ -23,3 +30,23 @@ def test_print_infinity(type, negative, target):
ast.compile()
print(ast.compile().code)
def test_print_unsupported_node():
with pytest.raises(NotImplementedError, match='CBackend does not support node of type UnsupportedNode'):
CBackend()(UnsupportedNode())
def test_print_subtraction():
a, b = sp.symbols("a b")
x = pystencils.fields(f'x: double[3d]')
y = pystencils.fields(f'y: double[3d]')
config = pystencils.CreateKernelConfig(target=pystencils.Target.CPU)
update = pystencils.Assignment(x.center, y.center - b)
ast = pystencils.create_kernel(update, config=config)
code = pystencils.get_code_str(ast)
assert "-1.0" not in code