From 7ccb623746ea36013689dbdf61f6ce50948e6c29 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 19 Jul 2018 13:15:40 +0200 Subject: bug #1569: fix Tensor::mean() on AVX with respective unit test. --- unsupported/test/cxx11_tensor_reduction.cpp | 41 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 20 deletions(-) (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 4c8a95c34..ff8e18c07 100644 --- a/unsupported/test/cxx11_tensor_reduction.cpp +++ b/unsupported/test/cxx11_tensor_reduction.cpp @@ -53,20 +53,20 @@ static void test_trivial_reductions() { } } -template +template static void test_simple_reductions() { - Tensor tensor(2, 3, 5, 7); + Tensor tensor(2, 3, 5, 7); tensor.setRandom(); array reduction_axis2; reduction_axis2[0] = 1; reduction_axis2[1] = 3; - Tensor result = tensor.sum(reduction_axis2); + Tensor result = 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; + Scalar sum = Scalar(0.0f); for (int k = 0; k < 3; ++k) { for (int l = 0; l < 7; ++l) { sum += tensor(i, k, j, l); @@ -77,7 +77,7 @@ static void test_simple_reductions() { } { - Tensor sum1 = tensor.sum(); + Tensor sum1 = tensor.sum(); VERIFY_IS_EQUAL(sum1.rank(), 0); array reduction_axis4; @@ -85,7 +85,7 @@ static void test_simple_reductions() { reduction_axis4[1] = 1; reduction_axis4[2] = 2; reduction_axis4[3] = 3; - Tensor sum2 = tensor.sum(reduction_axis4); + Tensor sum2 = tensor.sum(reduction_axis4); VERIFY_IS_EQUAL(sum2.rank(), 0); VERIFY_IS_APPROX(sum1(), sum2()); @@ -98,7 +98,7 @@ static void test_simple_reductions() { VERIFY_IS_EQUAL(result.dimension(1), 7); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 7; ++j) { - float prod = 1.0f; + Scalar prod = Scalar(1.0f); for (int k = 0; k < 2; ++k) { for (int l = 0; l < 5; ++l) { prod *= tensor(k, i, l, j); @@ -109,7 +109,7 @@ static void test_simple_reductions() { } { - Tensor prod1 = tensor.prod(); + Tensor prod1 = tensor.prod(); VERIFY_IS_EQUAL(prod1.rank(), 0); array reduction_axis4; @@ -117,7 +117,7 @@ static void test_simple_reductions() { reduction_axis4[1] = 1; reduction_axis4[2] = 2; reduction_axis4[3] = 3; - Tensor prod2 = tensor.prod(reduction_axis4); + Tensor prod2 = tensor.prod(reduction_axis4); VERIFY_IS_EQUAL(prod2.rank(), 0); VERIFY_IS_APPROX(prod1(), prod2()); @@ -130,7 +130,7 @@ static void test_simple_reductions() { VERIFY_IS_EQUAL(result.dimension(1), 7); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 7; ++j) { - float max_val = std::numeric_limits::lowest(); + Scalar max_val = std::numeric_limits::lowest(); for (int k = 0; k < 2; ++k) { for (int l = 0; l < 5; ++l) { max_val = (std::max)(max_val, tensor(k, i, l, j)); @@ -141,7 +141,7 @@ static void test_simple_reductions() { } { - Tensor max1 = tensor.maximum(); + Tensor max1 = tensor.maximum(); VERIFY_IS_EQUAL(max1.rank(), 0); array reduction_axis4; @@ -149,7 +149,7 @@ static void test_simple_reductions() { reduction_axis4[1] = 1; reduction_axis4[2] = 2; reduction_axis4[3] = 3; - Tensor max2 = tensor.maximum(reduction_axis4); + Tensor max2 = tensor.maximum(reduction_axis4); VERIFY_IS_EQUAL(max2.rank(), 0); VERIFY_IS_APPROX(max1(), max2()); @@ -162,7 +162,7 @@ static void test_simple_reductions() { VERIFY_IS_EQUAL(result.dimension(1), 7); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 7; ++j) { - float min_val = (std::numeric_limits::max)(); + Scalar min_val = (std::numeric_limits::max)(); for (int k = 0; k < 2; ++k) { for (int l = 0; l < 3; ++l) { min_val = (std::min)(min_val, tensor(k, l, i, j)); @@ -173,7 +173,7 @@ static void test_simple_reductions() { } { - Tensor min1 = tensor.minimum(); + Tensor min1 = tensor.minimum(); VERIFY_IS_EQUAL(min1.rank(), 0); array reduction_axis4; @@ -181,7 +181,7 @@ static void test_simple_reductions() { reduction_axis4[1] = 1; reduction_axis4[2] = 2; reduction_axis4[3] = 3; - Tensor min2 = tensor.minimum(reduction_axis4); + Tensor min2 = tensor.minimum(reduction_axis4); VERIFY_IS_EQUAL(min2.rank(), 0); VERIFY_IS_APPROX(min1(), min2()); @@ -194,7 +194,7 @@ static void test_simple_reductions() { VERIFY_IS_EQUAL(result.dimension(1), 7); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 7; ++j) { - float sum = 0.0f; + Scalar sum = Scalar(0.0f); int count = 0; for (int k = 0; k < 2; ++k) { for (int l = 0; l < 3; ++l) { @@ -207,7 +207,7 @@ static void test_simple_reductions() { } { - Tensor mean1 = tensor.mean(); + Tensor mean1 = tensor.mean(); VERIFY_IS_EQUAL(mean1.rank(), 0); array reduction_axis4; @@ -215,7 +215,7 @@ static void test_simple_reductions() { reduction_axis4[1] = 1; reduction_axis4[2] = 2; reduction_axis4[3] = 3; - Tensor mean2 = tensor.mean(reduction_axis4); + Tensor mean2 = tensor.mean(reduction_axis4); VERIFY_IS_EQUAL(mean2.rank(), 0); VERIFY_IS_APPROX(mean1(), mean2()); @@ -487,8 +487,9 @@ static void test_reduce_middle_dims() { EIGEN_DECLARE_TEST(cxx11_tensor_reduction) { CALL_SUBTEST(test_trivial_reductions()); CALL_SUBTEST(test_trivial_reductions()); - CALL_SUBTEST(test_simple_reductions()); - CALL_SUBTEST(test_simple_reductions()); + CALL_SUBTEST(( test_simple_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()); -- cgit v1.2.3