Skip to content
Snippets Groups Projects
Commit a333aa55 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

integer division and remainder folding tests

parent af52d21f
No related branches found
No related tags found
1 merge request!393Ternary Expressions, Improved Integer Divisions, and Iteration Space Fix
Pipeline #67190 passed
......@@ -11,7 +11,8 @@ from pystencils.backend.ast.expressions import (
PsEq,
PsGt,
PsTernary,
PsRem
PsRem,
PsIntDiv
)
from pystencils.types.quick import Int, Fp, Bool
......@@ -28,8 +29,10 @@ f1 = PsExpression.make(PsConstant(1.0, Fp(32)))
i0 = PsExpression.make(PsConstant(0, Int(32)))
i1 = PsExpression.make(PsConstant(1, Int(32)))
im1 = PsExpression.make(PsConstant(-1, Int(32)))
i3 = PsExpression.make(PsConstant(3, Int(32)))
i4 = PsExpression.make(PsConstant(4, Int(32)))
im3 = PsExpression.make(PsConstant(-3, Int(32)))
i12 = PsExpression.make(PsConstant(12, Int(32)))
......@@ -105,6 +108,46 @@ def test_divisions():
result = elim(expr)
assert result.structurally_equal(i0)
expr = typify(PsIntDiv(i12, i3))
result = elim(expr)
assert result.structurally_equal(i4)
expr = typify(i12 / i3)
result = elim(expr)
assert result.structurally_equal(i4)
expr = typify(PsIntDiv(i4, i3))
result = elim(expr)
assert result.structurally_equal(i1)
expr = typify(PsIntDiv(-i4, i3))
result = elim(expr)
assert result.structurally_equal(im1)
expr = typify(PsIntDiv(i4, -i3))
result = elim(expr)
assert result.structurally_equal(im1)
expr = typify(PsIntDiv(-i4, -i3))
result = elim(expr)
assert result.structurally_equal(i1)
expr = typify(PsRem(i4, i3))
result = elim(expr)
assert result.structurally_equal(i1)
expr = typify(PsRem(-i4, i3))
result = elim(expr)
assert result.structurally_equal(im1)
expr = typify(PsRem(i4, -i3))
result = elim(expr)
assert result.structurally_equal(i1)
expr = typify(PsRem(-i4, -i3))
result = elim(expr)
assert result.structurally_equal(im1)
def test_boolean_folding():
ctx = KernelCreationContext()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment