From f9422bbf7b3816a0195fdc56902e19e14492177c Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sat, 9 Apr 2016 19:31:49 -0500
Subject: [PATCH] Fix min reduction, add test for all reductions

---
 loopy/library/reduction.py |  1 -
 test/test_loopy.py         | 23 +++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/loopy/library/reduction.py b/loopy/library/reduction.py
index 3eb590b80..b39115a35 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 810106aef..e126a2ed1 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)
-- 
GitLab