Skip to content
Snippets Groups Projects
Commit e9ee769d authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Adaptations to reduction test

parent 9a8e6f9b
1 merge request!438Reduction Support
Pipeline #72114 failed with stages
in 4 minutes and 8 seconds
......@@ -6,39 +6,23 @@ import pystencils as ps
from pystencils import AddReducedAssignment
@pytest.mark.parametrize('dtype', ["float64", "float32"])
def test_log(dtype):
a = sp.Symbol("a")
@pytest.mark.parametrize('dtype', ["float64"])
def test_reduction(dtype):
x = ps.fields(f'x: {dtype}[1d]')
w = sp.Symbol("w")
# kernel with main assignments and no reduction
# kernel with reduction assignment
main_assignment = ps.AssignmentCollection({x.center(): a})
reduction_assignment = AddReducedAssignment(w, x.center())
ast_main = ps.create_kernel(main_assignment, default_dtype=dtype)
code_main = ps.get_code_str(ast_main)
kernel_main = ast_main.compile()
config = ps.CreateKernelConfig(cpu_openmp=True)
# ps.show_code(ast)
if dtype == "float64":
assert "float" not in code_main
array = np.zeros((10,), dtype=dtype)
kernel_main(x=array, a=100)
assert np.allclose(array, 4.60517019)
# kernel with single reduction assignment
omega = sp.Symbol("omega")
reduction_assignment = AddReducedAssignment(omega, x.center())
ast_reduction = ps.create_kernel(reduction_assignment, default_dtype=dtype)
code_reduction = ps.get_code_str(ast_reduction)
ast_reduction = ps.create_kernel([reduction_assignment], config, default_dtype=dtype)
#code_reduction = ps.get_code_str(ast_reduction)
kernel_reduction = ast_reduction.compile()
if dtype == "float64":
assert "float" not in code_reduction
ps.show_code(ast_reduction)
ps.show_code(ast_reduction)
\ No newline at end of file
array = np.ones((10,), dtype=dtype)
kernel_reduction(x=array, w=0)
# TODO: check if "w = #points"
\ 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