From c6b0de2c21c921e1c1cca4978d4e9d6e18559a15 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Fri, 22 Jul 2016 17:18:20 -0700 Subject: Improved partial reductions in more cases --- unsupported/test/cxx11_tensor_reduction.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'unsupported/test/cxx11_tensor_reduction.cpp') diff --git a/unsupported/test/cxx11_tensor_reduction.cpp b/unsupported/test/cxx11_tensor_reduction.cpp index ca483257b..1490ec3da 100644 --- a/unsupported/test/cxx11_tensor_reduction.cpp +++ b/unsupported/test/cxx11_tensor_reduction.cpp @@ -239,6 +239,33 @@ static void test_simple_reductions() { } } + +template +static void test_reductions_in_expr() { + Tensor tensor(2, 3, 5, 7); + tensor.setRandom(); + array reduction_axis2; + reduction_axis2[0] = 1; + reduction_axis2[1] = 3; + + Tensor result(2, 5); + result = result.constant(1.0f) - tensor.sum(reduction_axis2); + VERIFY_IS_EQUAL(result.dimension(0), 2); + VERIFY_IS_EQUAL(result.dimension(1), 5); + for (int i = 0; i < 2; ++i) { + for (int j = 0; j < 5; ++j) { + float sum = 0.0f; + for (int k = 0; k < 3; ++k) { + for (int l = 0; l < 7; ++l) { + sum += tensor(i, k, j, l); + } + } + VERIFY_IS_APPROX(result(i, j), 1.0f - sum); + } + } +} + + template static void test_full_reductions() { Tensor tensor(2, 3); @@ -462,6 +489,8 @@ void test_cxx11_tensor_reduction() { CALL_SUBTEST(test_trivial_reductions()); CALL_SUBTEST(test_simple_reductions()); CALL_SUBTEST(test_simple_reductions()); + CALL_SUBTEST(test_reductions_in_expr()); + CALL_SUBTEST(test_reductions_in_expr()); CALL_SUBTEST(test_full_reductions()); CALL_SUBTEST(test_full_reductions()); CALL_SUBTEST(test_user_defined_reductions()); -- cgit v1.2.3