mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
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<bool>::__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<bool>` (`-Wimplicit-conversion-floating-point-to-bool`).
- Added `scalar_square_op<bool>` and `scalar_cube_op<bool>`
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.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
a3b300f1af
commit
22f67b5958
@@ -222,7 +222,7 @@ static void test_eval_tensor_unary_expr_block() {
|
||||
input.setRandom();
|
||||
|
||||
VerifyBlockEvaluator<T, NumDims, Layout>(
|
||||
input.square(), [&dims]() { return RandomBlock<Layout>(dims, 1, 10); });
|
||||
input.abs(), [&dims]() { return RandomBlock<Layout>(dims, 1, 10); });
|
||||
}
|
||||
|
||||
template <typename T, int NumDims, int Layout>
|
||||
@@ -274,7 +274,7 @@ static void test_eval_tensor_broadcast() {
|
||||
// Check that desc.destination() memory is not shared between two broadcast
|
||||
// materializations.
|
||||
VerifyBlockEvaluator<T, NumDims, Layout>(
|
||||
input.broadcast(bcast) * input.square().broadcast(bcast),
|
||||
input.broadcast(bcast) * input.abs().broadcast(bcast),
|
||||
[&bcasted_dims]() { return SkewedInnerBlock<Layout>(bcasted_dims); });
|
||||
}
|
||||
|
||||
@@ -391,27 +391,46 @@ static void test_eval_tensor_chipping() {
|
||||
|
||||
// Block expression assignment.
|
||||
VerifyBlockEvaluator<T, NumDims - 1, Layout>(
|
||||
input.square().chip(chip_offset, chip_dim),
|
||||
input.abs().chip(chip_offset, chip_dim),
|
||||
[&chipped_dims]() { return FixedSizeBlock(chipped_dims); });
|
||||
|
||||
VerifyBlockEvaluator<T, NumDims - 1, Layout>(
|
||||
input.square().chip(chip_offset, chip_dim),
|
||||
input.abs().chip(chip_offset, chip_dim),
|
||||
[&chipped_dims]() { return RandomBlock<Layout>(chipped_dims, 1, 10); });
|
||||
}
|
||||
|
||||
|
||||
template<typename T, int NumDims>
|
||||
struct SimpleTensorGenerator {
|
||||
T operator()(const array<Index, NumDims>& coords) const {
|
||||
T result = static_cast<T>(0);
|
||||
for (int i = 0; i < NumDims; ++i) {
|
||||
result += static_cast<T>((i + 1) * coords[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// Boolean specialization to avoid -Wint-in-bool-context warnings on GCC.
|
||||
template<int NumDims>
|
||||
struct SimpleTensorGenerator<bool, NumDims> {
|
||||
bool operator()(const array<Index, NumDims>& coords) const {
|
||||
bool result = false;
|
||||
for (int i = 0; i < NumDims; ++i) {
|
||||
result ^= coords[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename T, int NumDims, int Layout>
|
||||
static void test_eval_tensor_generator() {
|
||||
DSizes<Index, NumDims> dims = RandomDims<NumDims>(10, 20);
|
||||
Tensor<T, NumDims, Layout> input(dims);
|
||||
input.setRandom();
|
||||
|
||||
auto generator = [](const array<Index, NumDims>& coords) -> T {
|
||||
T result = static_cast<T>(0);
|
||||
for (int i = 0; i < NumDims; ++i) {
|
||||
result += static_cast<T>((i + 1) * coords[i]);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
auto generator = SimpleTensorGenerator<T, NumDims>();
|
||||
|
||||
VerifyBlockEvaluator<T, NumDims, Layout>(
|
||||
input.generate(generator), [&dims]() { return FixedSizeBlock(dims); });
|
||||
|
||||
Reference in New Issue
Block a user