cxx11_tensor_comparisons.cpp File Reference
#include "main.h"
#include <Eigen/CXX11/Tensor>

Typedefs

using Scalar = float
 
using TypedLTOp = internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LT, true >
 
using TypedLEOp = internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LE, true >
 
using TypedGTOp = internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GT, true >
 
using TypedGEOp = internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GE, true >
 
using TypedEQOp = internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_EQ, true >
 
using TypedNEOp = internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_NEQ, true >
 

Functions

static void test_orderings ()
 
static void test_equality ()
 
static void test_isnan ()
 
static void test_isinf ()
 
static void test_isfinite ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_comparisons)
 

Typedef Documentation

◆ Scalar

using Scalar = float

◆ TypedEQOp

using TypedEQOp = internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ, true>

◆ TypedGEOp

using TypedGEOp = internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE, true>

◆ TypedGTOp

using TypedGTOp = internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT, true>

◆ TypedLEOp

using TypedLEOp = internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE, true>

◆ TypedLTOp

using TypedLTOp = internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT, true>

◆ TypedNEOp

using TypedNEOp = internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ, true>

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_comparisons  )
186  {
192 }
static void test_equality()
Definition: cxx11_tensor_comparisons.cpp:70
static void test_isnan()
Definition: cxx11_tensor_comparisons.cpp:111
static void test_orderings()
Definition: cxx11_tensor_comparisons.cpp:26
static void test_isfinite()
Definition: cxx11_tensor_comparisons.cpp:159
static void test_isinf()
Definition: cxx11_tensor_comparisons.cpp:135
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, test_equality(), test_isfinite(), test_isinf(), test_isnan(), and test_orderings().

◆ test_equality()

static void test_equality ( )
static
70  {
71  Tensor<Scalar, 3> mat1(2, 3, 7);
72  Tensor<Scalar, 3> mat2(2, 3, 7);
73 
74  mat1.setRandom();
75  mat2.setRandom();
76  for (int i = 0; i < 2; ++i) {
77  for (int j = 0; j < 3; ++j) {
78  for (int k = 0; k < 7; ++k) {
79  if (internal::random<bool>()) {
80  mat2(i, j, k) = mat1(i, j, k);
81  }
82  }
83  }
84  }
85 
86  Tensor<bool, 3> eq(2, 3, 7);
87  Tensor<bool, 3> ne(2, 3, 7);
88 
89  Tensor<Scalar, 3> typed_eq(2, 3, 7);
90  Tensor<Scalar, 3> typed_ne(2, 3, 7);
91 
92  eq = (mat1 == mat2);
93  ne = (mat1 != mat2);
94 
95  typed_eq = mat1.binaryExpr(mat2, TypedEQOp());
96  typed_ne = mat1.binaryExpr(mat2, TypedNEOp());
97 
98  for (int i = 0; i < 2; ++i) {
99  for (int j = 0; j < 3; ++j) {
100  for (int k = 0; k < 7; ++k) {
101  VERIFY_IS_EQUAL(eq(i, j, k), mat1(i, j, k) == mat2(i, j, k));
102  VERIFY_IS_EQUAL(ne(i, j, k), mat1(i, j, k) != mat2(i, j, k));
103 
104  VERIFY_IS_EQUAL(eq(i, j, k), (bool)typed_eq(i, j, k));
105  VERIFY_IS_EQUAL(ne(i, j, k), (bool)typed_ne(i, j, k));
106  }
107  }
108  }
109 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
MatrixXd mat1(size, size)
The tensor class.
Definition: Tensor.h:68
internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_NEQ, true > TypedNEOp
Definition: cxx11_tensor_comparisons.cpp:24
internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_EQ, true > TypedEQOp
Definition: cxx11_tensor_comparisons.cpp:23
char char char int int * k
Definition: level2_impl.h:374
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References i, j, k, mat1(), Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_isfinite()

static void test_isfinite ( )
static
159  {
160  Tensor<Scalar, 3> mat(2, 3, 7);
161 
162  mat.setRandom();
163  for (int i = 0; i < 2; ++i) {
164  for (int j = 0; j < 3; ++j) {
165  for (int k = 0; k < 7; ++k) {
166  if (internal::random<bool>()) {
167  mat(i, j, k) = std::numeric_limits<Scalar>::infinity();
168  }
169  if (internal::random<bool>()) {
170  mat(i, j, k) = std::numeric_limits<Scalar>::quiet_NaN();
171  }
172  }
173  }
174  }
175  Tensor<bool, 3> inf(2, 3, 7);
176  inf = (mat.isfinite)();
177  for (int i = 0; i < 2; ++i) {
178  for (int j = 0; j < 3; ++j) {
179  for (int k = 0; k < 7; ++k) {
180  VERIFY_IS_EQUAL(inf(i, j, k), (std::isfinite)(mat(i, j, k)));
181  }
182  }
183  }
184 }
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
#define isfinite(X)
Definition: main.h:111
const Mdouble inf
Definition: GeneralDefine.h:23

References i, constants::inf, isfinite, j, k, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_isinf()

static void test_isinf ( )
static
135  {
136  Tensor<Scalar, 3> mat(2, 3, 7);
137 
138  mat.setRandom();
139  for (int i = 0; i < 2; ++i) {
140  for (int j = 0; j < 3; ++j) {
141  for (int k = 0; k < 7; ++k) {
142  if (internal::random<bool>()) {
143  mat(i, j, k) = std::numeric_limits<Scalar>::infinity();
144  }
145  }
146  }
147  }
148  Tensor<bool, 3> inf(2, 3, 7);
149  inf = (mat.isinf)();
150  for (int i = 0; i < 2; ++i) {
151  for (int j = 0; j < 3; ++j) {
152  for (int k = 0; k < 7; ++k) {
153  VERIFY_IS_EQUAL(inf(i, j, k), (std::isinf)(mat(i, j, k)));
154  }
155  }
156  }
157 }
#define isinf(X)
Definition: main.h:110

References i, constants::inf, isinf, j, k, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_isnan()

static void test_isnan ( )
static
111  {
112  Tensor<Scalar, 3> mat(2, 3, 7);
113 
114  mat.setRandom();
115  for (int i = 0; i < 2; ++i) {
116  for (int j = 0; j < 3; ++j) {
117  for (int k = 0; k < 7; ++k) {
118  if (internal::random<bool>()) {
119  mat(i, j, k) = std::numeric_limits<Scalar>::quiet_NaN();
120  }
121  }
122  }
123  }
124  Tensor<bool, 3> nan(2, 3, 7);
125  nan = (mat.isnan)();
126  for (int i = 0; i < 2; ++i) {
127  for (int j = 0; j < 3; ++j) {
128  for (int k = 0; k < 7; ++k) {
129  VERIFY_IS_EQUAL(nan(i, j, k), (std::isnan)(mat(i, j, k)));
130  }
131  }
132  }
133 }
#define isnan(X)
Definition: main.h:109

References i, isnan, j, k, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_orderings()

static void test_orderings ( )
static
26  {
27  Tensor<Scalar, 3> mat1(2, 3, 7);
28  Tensor<Scalar, 3> mat2(2, 3, 7);
29 
30  mat1.setRandom();
31  mat2.setRandom();
32 
33  Tensor<bool, 3> lt(2, 3, 7);
34  Tensor<bool, 3> le(2, 3, 7);
35  Tensor<bool, 3> gt(2, 3, 7);
36  Tensor<bool, 3> ge(2, 3, 7);
37 
38  Tensor<Scalar, 3> typed_lt(2, 3, 7);
39  Tensor<Scalar, 3> typed_le(2, 3, 7);
40  Tensor<Scalar, 3> typed_gt(2, 3, 7);
41  Tensor<Scalar, 3> typed_ge(2, 3, 7);
42 
43  lt = mat1 < mat2;
44  le = mat1 <= mat2;
45  gt = mat1 > mat2;
46  ge = mat1 >= mat2;
47 
48  typed_lt = mat1.binaryExpr(mat2, TypedLTOp());
49  typed_le = mat1.binaryExpr(mat2, TypedLEOp());
50  typed_gt = mat1.binaryExpr(mat2, TypedGTOp());
51  typed_ge = mat1.binaryExpr(mat2, TypedGEOp());
52 
53  for (int i = 0; i < 2; ++i) {
54  for (int j = 0; j < 3; ++j) {
55  for (int k = 0; k < 7; ++k) {
56  VERIFY_IS_EQUAL(lt(i, j, k), mat1(i, j, k) < mat2(i, j, k));
57  VERIFY_IS_EQUAL(le(i, j, k), mat1(i, j, k) <= mat2(i, j, k));
58  VERIFY_IS_EQUAL(gt(i, j, k), mat1(i, j, k) > mat2(i, j, k));
59  VERIFY_IS_EQUAL(ge(i, j, k), mat1(i, j, k) >= mat2(i, j, k));
60 
61  VERIFY_IS_EQUAL(lt(i, j, k), (bool)typed_lt(i, j, k));
62  VERIFY_IS_EQUAL(le(i, j, k), (bool)typed_le(i, j, k));
63  VERIFY_IS_EQUAL(gt(i, j, k), (bool)typed_gt(i, j, k));
64  VERIFY_IS_EQUAL(ge(i, j, k), (bool)typed_ge(i, j, k));
65  }
66  }
67  }
68 }
internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LE, true > TypedLEOp
Definition: cxx11_tensor_comparisons.cpp:20
internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LT, true > TypedLTOp
Definition: cxx11_tensor_comparisons.cpp:19
internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GT, true > TypedGTOp
Definition: cxx11_tensor_comparisons.cpp:21
internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GE, true > TypedGEOp
Definition: cxx11_tensor_comparisons.cpp:22

References i, j, k, mat1(), Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().