From 22f67b59585805fedf86759f7013b2b670f83386 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Thu, 19 Nov 2020 10:22:42 -0800 Subject: Fix boolean float conversion and product warnings. This fixes some gcc warnings such as: ``` Eigen/src/Core/GenericPacketMath.h:655:63: warning: implicit conversion turns floating-point number into bool: 'typename __gnu_cxx::__enable_if<__is_integer::__value, double>::__type' (aka 'double') to 'bool' [-Wimplicit-conversion-floating-point-to-bool] Packet psqrt(const Packet& a) { EIGEN_USING_STD(sqrt); return sqrt(a); } ``` Details: - Added `scalar_sqrt_op` (`-Wimplicit-conversion-floating-point-to-bool`). - Added `scalar_square_op` and `scalar_cube_op` specializations (`-Wint-in-bool-context`) - Deprecated above specialized ops for bool. - Modified `cxx11_tensor_block_eval` to specialize generator for booleans (`-Wint-in-bool-context`) and to use `abs` instead of `square` to avoid deprecated bool ops. --- unsupported/test/cxx11_tensor_block_eval.cpp | 41 ++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'unsupported') diff --git a/unsupported/test/cxx11_tensor_block_eval.cpp b/unsupported/test/cxx11_tensor_block_eval.cpp index a7a49fa1f..b2e26ebb7 100644 --- a/unsupported/test/cxx11_tensor_block_eval.cpp +++ b/unsupported/test/cxx11_tensor_block_eval.cpp @@ -222,7 +222,7 @@ static void test_eval_tensor_unary_expr_block() { input.setRandom(); VerifyBlockEvaluator( - input.square(), [&dims]() { return RandomBlock(dims, 1, 10); }); + input.abs(), [&dims]() { return RandomBlock(dims, 1, 10); }); } template @@ -274,7 +274,7 @@ static void test_eval_tensor_broadcast() { // Check that desc.destination() memory is not shared between two broadcast // materializations. VerifyBlockEvaluator( - input.broadcast(bcast) * input.square().broadcast(bcast), + input.broadcast(bcast) * input.abs().broadcast(bcast), [&bcasted_dims]() { return SkewedInnerBlock(bcasted_dims); }); } @@ -391,27 +391,46 @@ static void test_eval_tensor_chipping() { // Block expression assignment. VerifyBlockEvaluator( - input.square().chip(chip_offset, chip_dim), + input.abs().chip(chip_offset, chip_dim), [&chipped_dims]() { return FixedSizeBlock(chipped_dims); }); VerifyBlockEvaluator( - input.square().chip(chip_offset, chip_dim), + input.abs().chip(chip_offset, chip_dim), [&chipped_dims]() { return RandomBlock(chipped_dims, 1, 10); }); } -template -static void test_eval_tensor_generator() { - DSizes dims = RandomDims(10, 20); - Tensor input(dims); - input.setRandom(); - auto generator = [](const array& coords) -> T { +template +struct SimpleTensorGenerator { + T operator()(const array& coords) const { T result = static_cast(0); for (int i = 0; i < NumDims; ++i) { result += static_cast((i + 1) * coords[i]); } return result; - }; + } +}; + +// Boolean specialization to avoid -Wint-in-bool-context warnings on GCC. +template +struct SimpleTensorGenerator { + bool operator()(const array& coords) const { + bool result = false; + for (int i = 0; i < NumDims; ++i) { + result ^= coords[i]; + } + return result; + } +}; + + +template +static void test_eval_tensor_generator() { + DSizes dims = RandomDims(10, 20); + Tensor input(dims); + input.setRandom(); + + auto generator = SimpleTensorGenerator(); VerifyBlockEvaluator( input.generate(generator), [&dims]() { return FixedSizeBlock(dims); }); -- cgit v1.2.3