mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
vectorize comparisons and select by enabling typed comparisons
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
2e9b945baf
commit
826627f653
@@ -14,14 +14,16 @@
|
||||
using Eigen::Tensor;
|
||||
using Eigen::RowMajor;
|
||||
|
||||
using Scalar = float;
|
||||
|
||||
static void test_orderings()
|
||||
{
|
||||
Tensor<float, 3> mat1(2,3,7);
|
||||
Tensor<float, 3> mat2(2,3,7);
|
||||
Tensor<bool, 3> lt(2,3,7);
|
||||
Tensor<bool, 3> le(2,3,7);
|
||||
Tensor<bool, 3> gt(2,3,7);
|
||||
Tensor<bool, 3> ge(2,3,7);
|
||||
Tensor<Scalar, 3> mat1(2,3,7);
|
||||
Tensor<Scalar, 3> mat2(2,3,7);
|
||||
Tensor<Scalar, 3> lt(2,3,7);
|
||||
Tensor<Scalar, 3> le(2,3,7);
|
||||
Tensor<Scalar, 3> gt(2,3,7);
|
||||
Tensor<Scalar, 3> ge(2,3,7);
|
||||
|
||||
mat1.setRandom();
|
||||
mat2.setRandom();
|
||||
@@ -46,8 +48,8 @@ static void test_orderings()
|
||||
|
||||
static void test_equality()
|
||||
{
|
||||
Tensor<float, 3> mat1(2,3,7);
|
||||
Tensor<float, 3> mat2(2,3,7);
|
||||
Tensor<Scalar, 3> mat1(2,3,7);
|
||||
Tensor<Scalar, 3> mat2(2,3,7);
|
||||
|
||||
mat1.setRandom();
|
||||
mat2.setRandom();
|
||||
@@ -61,8 +63,8 @@ static void test_equality()
|
||||
}
|
||||
}
|
||||
|
||||
Tensor<bool, 3> eq(2,3,7);
|
||||
Tensor<bool, 3> ne(2,3,7);
|
||||
Tensor<Scalar, 3> eq(2,3,7);
|
||||
Tensor<Scalar, 3> ne(2,3,7);
|
||||
eq = (mat1 == mat2);
|
||||
ne = (mat1 != mat2);
|
||||
|
||||
|
||||
@@ -200,14 +200,14 @@ static void test_boolean()
|
||||
std::iota(vec.data(), vec.data() + kSize, 0);
|
||||
|
||||
// Test ||.
|
||||
Tensor<bool, 1> bool1 = vec < vec.constant(1) || vec > vec.constant(4);
|
||||
Tensor<bool, 1> bool1 = (vec < vec.constant(1) || vec > vec.constant(4)).cast<bool>();
|
||||
for (int i = 0; i < kSize; ++i) {
|
||||
bool expected = i < 1 || i > 4;
|
||||
VERIFY_IS_EQUAL(bool1[i], expected);
|
||||
}
|
||||
|
||||
// Test &&, including cast of operand vec.
|
||||
Tensor<bool, 1> bool2 = vec.cast<bool>() && vec < vec.constant(4);
|
||||
Tensor<bool, 1> bool2 = vec.cast<bool>() && (vec < vec.constant(4)).cast<bool>();
|
||||
for (int i = 0; i < kSize; ++i) {
|
||||
bool expected = bool(i) && i < 4;
|
||||
VERIFY_IS_EQUAL(bool2[i], expected);
|
||||
@@ -218,7 +218,7 @@ static void test_boolean()
|
||||
// CoeffReturnType is set to match Op return type of bool for Unary and Binary
|
||||
// Ops.
|
||||
Tensor<bool, 1> bool3 = vec.cast<bool>() && bool2;
|
||||
bool3 = vec < vec.constant(4) && bool2;
|
||||
bool3 = (vec < vec.constant(4)).cast<bool>() && bool2;
|
||||
}
|
||||
|
||||
static void test_functors()
|
||||
|
||||
Reference in New Issue
Block a user