From 05d3ca9bc3e1ceeb4aebb6bf514bfb4ad3a7f192 Mon Sep 17 00:00:00 2001 From: arghdos Date: Fri, 9 Dec 2016 13:06:33 -0500 Subject: [PATCH] add integer reduction tests --- test/test_loopy.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/test_loopy.py b/test/test_loopy.py index 9eaece6a8..2438829f4 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -1933,6 +1933,37 @@ def test_unscheduled_insn_detection(): lp.generate_code(knl) +def test_integer_reduction(): + n = 200 + var_int = np.random.randint(1000, size=n, dtype=np.int32) + var_lp = lp.TemporaryVariable('var', initializer=var_int, + scope=scopes.PRIVATE, + read_only=True, + dtype=np.int32, + shape=lp.auto) + + reductions = [('max', lambda x: x == np.max(var_int)), + ('min', lambda x: x == np.min(var_int)), + ('sum', lambda x: x == np.sum(var_int)), + ('product', lambda x: x == np.prod(var_int)), + ('argmax', lambda x: (x[0] == np.max(var_int) and + x[1] == np.argmax(var_int))), + ('argmin', lambda x: (x[0] == np.min(var_int) and + x[1] == np.argmin(var_int)))] + + for reduction, function in reductions: + kstr = (("out" if not 'arg' in reduction + else "out[0], out[1]") + ' = {}(k, var[k])'.format(reduction)) + knl = lp.make_kernel('{[k]: 0<=k 1: exec(sys.argv[1]) -- GitLab