diff --git a/loopy/library/reduction.py b/loopy/library/reduction.py index 3eb590b80e9273e70c3d71108ec130a16afee692..b39115a355069cadf698b466b55c2fc3c6b5a4e0 100644 --- a/loopy/library/reduction.py +++ b/loopy/library/reduction.py @@ -139,7 +139,6 @@ class MaxReductionOperation(ScalarReductionOperation): class MinReductionOperation(ScalarReductionOperation): - @property def neutral_element(self, dtype, inames): return get_le_neutral(dtype) diff --git a/test/test_loopy.py b/test/test_loopy.py index 810106aefb7088f9e0df7fcf967eabd89458f2c7..e126a2ed13834f10cc1b971dbbeae48720c4ea80 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -959,6 +959,29 @@ def test_double_sum(ctx_factory): assert b.get() == ref +@pytest.mark.parametrize(("op_name", "np_op"), [ + ("sum", np.sum), + ("product", np.prod), + ("min", np.min), + ("max", np.max), + ]) +def test_reduction_library(ctx_factory, op_name, np_op): + ctx = ctx_factory() + queue = cl.CommandQueue(ctx) + + knl = lp.make_kernel( + "{[i,j]: 0<=i<n and 0<=j<m }", + [ + "res[i] = reduce(%s, j, a[i,j])" % op_name, + ], + assumptions="n>=1") + + a = np.random.randn(20, 10) + evt, (res,) = knl(queue, a=a) + + assert np.allclose(res, np_op(a, axis=1)) + + def test_double_sum_made_unique(ctx_factory): ctx = ctx_factory() queue = cl.CommandQueue(ctx)