Skip to content
Snippets Groups Projects
Commit e867d1f6 authored by Markus Holzer's avatar Markus Holzer
Browse files

Added test cases for stencil

parent 6aa28a4b
Branches
Tags
No related merge requests found
......@@ -34,6 +34,8 @@ def is_valid(stencil, max_neighborhood=None):
True
>>> is_valid([(2, 0), (1, 0)], max_neighborhood=1)
False
>>> is_valid([(2, 0), (1, 0)], max_neighborhood=2)
True
"""
expected_dim = len(stencil[0])
for d in stencil:
......@@ -67,8 +69,11 @@ def have_same_entries(s1, s2):
Examples:
>>> stencil1 = [(1, 0), (-1, 0), (0, 1), (0, -1)]
>>> stencil2 = [(-1, 0), (0, -1), (1, 0), (0, 1)]
>>> stencil3 = [(-1, 0), (0, -1), (1, 0)]
>>> have_same_entries(stencil1, stencil2)
True
>>> have_same_entries(stencil1, stencil3)
False
"""
if len(s1) != len(s2):
return False
......
......@@ -4,6 +4,7 @@ import sympy as sp
import pytest
import pystencils as ps
from pystencils import x_staggered_vector, TypedSymbol
class TestStaggeredDiffusion:
......@@ -96,3 +97,12 @@ def test_staggered_loop_cutting():
assignments = [ps.Assignment(j.staggered_access("SW"), 1)]
ast = ps.create_staggered_kernel(assignments, target=dh.default_target)
assert not ast.atoms(ps.astnodes.Conditional)
def test_staggered_vector():
dim = 2
v = x_staggered_vector(dim)
ctr0 = TypedSymbol('ctr_0', 'int', nonnegative=True)
ctr1 = TypedSymbol('ctr_1', 'int', nonnegative=True)
expected_result = sp.Matrix(tuple((ctr0 + 0.5, ctr1 + 0.5)))
assert v == expected_result
\ No newline at end of file
import pystencils as ps
import sympy as sp
from pystencils.stencil import coefficient_list, plot_expression
def test_coefficient_list():
f = ps.fields("f: double[1D]")
expr = 2 * f[1] + 3 * f[-1]
coff = coefficient_list(expr)
assert coff == [3, 0, 2]
plot_expression(expr, matrix_form=True)
f = ps.fields("f: double[3D]")
expr = 2 * f[1, 0, 0] + 3 * f[0, -1, 0]
coff = coefficient_list(expr)
assert coff == [[[0, 3, 0], [0, 0, 2], [0, 0, 0]]]
expr = 2 * f[1, 0, 0] + 3 * f[0, -1, 0] + 4 * f[0, 0, 1]
coff = coefficient_list(expr, matrix_form=True)
assert coff[0] == sp.zeros(3, 3)
# in 3D plot only works if there are entries on every of the three 2D planes. In the above examples z-1 was empty
expr = 2 * f[1, 0, 0] + 1 * f[0, -1, 0] + 1 * f[0, 0, 1] + f[0, 0, -1]
plot_expression(expr)
def test_plot_expression():
f = ps.fields("f: double[2D]")
plot_expression(2 * f[1, 0] + 3 * f[0, -1], matrix_form=True)
\ No newline at end of file
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