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

Functions

static void test_1d ()
 
static void test_2d ()
 
static void test_3d ()
 
static void test_constants ()
 
static void test_boolean ()
 
static void test_functors ()
 
static void test_type_casting ()
 
static void test_select ()
 
template<typename Scalar >
void test_minmax_nan_propagation_templ ()
 
static void test_clip ()
 
static void test_minmax_nan_propagation ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_expr)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_expr  )
458  {
468 
469 // Nan propagation does currently not work like one would expect from std::max/std::min,
470 // so we disable it for now
471 #if !EIGEN_ARCH_ARM_OR_ARM64
473 #endif
474 }
static void test_constants()
Definition: cxx11_tensor_expr.cpp:169
static void test_clip()
Definition: cxx11_tensor_expr.cpp:434
static void test_3d()
Definition: cxx11_tensor_expr.cpp:116
static void test_boolean()
Definition: cxx11_tensor_expr.cpp:198
static void test_type_casting()
Definition: cxx11_tensor_expr.cpp:254
static void test_functors()
Definition: cxx11_tensor_expr.cpp:225
static void test_minmax_nan_propagation()
Definition: cxx11_tensor_expr.cpp:453
static void test_select()
Definition: cxx11_tensor_expr.cpp:280
static void test_2d()
Definition: cxx11_tensor_expr.cpp:76
static void test_1d()
Definition: cxx11_tensor_expr.cpp:19
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, test_1d(), test_2d(), test_3d(), test_boolean(), test_clip(), test_constants(), test_functors(), test_minmax_nan_propagation(), test_select(), and test_type_casting().

◆ test_1d()

static void test_1d ( )
static
19  {
22 
23  vec1(0) = 4.0;
24  vec2(0) = 0.0;
25  vec1(1) = 8.0;
26  vec2(1) = 1.0;
27  vec1(2) = 15.0;
28  vec2(2) = 2.0;
29  vec1(3) = 16.0;
30  vec2(3) = 3.0;
31  vec1(4) = 23.0;
32  vec2(4) = 4.0;
33  vec1(5) = 42.0;
34  vec2(5) = 5.0;
35 
36  float data3[6];
37  TensorMap<Tensor<float, 1>> vec3(data3, 6);
38  vec3 = vec1.sqrt();
39  float data4[6];
41  vec4 = vec2.square();
42  float data5[6];
44  vec5 = vec2.cube();
45 
46  VERIFY_IS_APPROX(vec3(0), sqrtf(4.0));
47  VERIFY_IS_APPROX(vec3(1), sqrtf(8.0));
48  VERIFY_IS_APPROX(vec3(2), sqrtf(15.0));
49  VERIFY_IS_APPROX(vec3(3), sqrtf(16.0));
50  VERIFY_IS_APPROX(vec3(4), sqrtf(23.0));
51  VERIFY_IS_APPROX(vec3(5), sqrtf(42.0));
52 
53  VERIFY_IS_APPROX(vec4(0), 0.0f);
54  VERIFY_IS_APPROX(vec4(1), 1.0f);
55  VERIFY_IS_APPROX(vec4(2), 2.0f * 2.0f);
56  VERIFY_IS_APPROX(vec4(3), 3.0f * 3.0f);
57  VERIFY_IS_APPROX(vec4(4), 4.0f * 4.0f);
58  VERIFY_IS_APPROX(vec4(5), 5.0f * 5.0f);
59 
60  VERIFY_IS_APPROX(vec5(0), 0.0f);
61  VERIFY_IS_APPROX(vec5(1), 1.0f);
62  VERIFY_IS_APPROX(vec5(2), 2.0f * 2.0f * 2.0f);
63  VERIFY_IS_APPROX(vec5(3), 3.0f * 3.0f * 3.0f);
64  VERIFY_IS_APPROX(vec5(4), 4.0f * 4.0f * 4.0f);
65  VERIFY_IS_APPROX(vec5(5), 5.0f * 5.0f * 5.0f);
66 
67  vec3 = vec1 + vec2;
68  VERIFY_IS_APPROX(vec3(0), 4.0f + 0.0f);
69  VERIFY_IS_APPROX(vec3(1), 8.0f + 1.0f);
70  VERIFY_IS_APPROX(vec3(2), 15.0f + 2.0f);
71  VERIFY_IS_APPROX(vec3(3), 16.0f + 3.0f);
72  VERIFY_IS_APPROX(vec3(4), 23.0f + 4.0f);
73  VERIFY_IS_APPROX(vec3(5), 42.0f + 5.0f);
74 }
RowVectorXd vec1(3)
A tensor expression mapping an existing array of data.
Definition: TensorMap.h:33
The tensor class.
Definition: Tensor.h:68
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13

References vec1(), and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ test_2d()

static void test_2d ( )
static
76  {
77  float data1[6];
78  TensorMap<Tensor<float, 2>> mat1(data1, 2, 3);
79  float data2[6];
80  TensorMap<Tensor<float, 2, RowMajor>> mat2(data2, 2, 3);
81 
82  mat1(0, 0) = 0.0;
83  mat1(0, 1) = 1.0;
84  mat1(0, 2) = 2.0;
85  mat1(1, 0) = 3.0;
86  mat1(1, 1) = 4.0;
87  mat1(1, 2) = 5.0;
88 
89  mat2(0, 0) = -0.0;
90  mat2(0, 1) = -1.0;
91  mat2(0, 2) = -2.0;
92  mat2(1, 0) = -3.0;
93  mat2(1, 1) = -4.0;
94  mat2(1, 2) = -5.0;
95 
96  Tensor<float, 2> mat3(2, 3);
97  Tensor<float, 2, RowMajor> mat4(2, 3);
98  mat3 = mat1.abs();
99  mat4 = mat2.abs();
100 
101  VERIFY_IS_APPROX(mat3(0, 0), 0.0f);
102  VERIFY_IS_APPROX(mat3(0, 1), 1.0f);
103  VERIFY_IS_APPROX(mat3(0, 2), 2.0f);
104  VERIFY_IS_APPROX(mat3(1, 0), 3.0f);
105  VERIFY_IS_APPROX(mat3(1, 1), 4.0f);
106  VERIFY_IS_APPROX(mat3(1, 2), 5.0f);
107 
108  VERIFY_IS_APPROX(mat4(0, 0), 0.0f);
109  VERIFY_IS_APPROX(mat4(0, 1), 1.0f);
110  VERIFY_IS_APPROX(mat4(0, 2), 2.0f);
111  VERIFY_IS_APPROX(mat4(1, 0), 3.0f);
112  VERIFY_IS_APPROX(mat4(1, 1), 4.0f);
113  VERIFY_IS_APPROX(mat4(1, 2), 5.0f);
114 }
MatrixXd mat1(size, size)

References mat1(), and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ test_3d()

static void test_3d ( )
static
116  {
117  Tensor<float, 3> mat1(2, 3, 7);
118  Tensor<float, 3, RowMajor> mat2(2, 3, 7);
119 
120  float val = 1.0f;
121  for (int i = 0; i < 2; ++i) {
122  for (int j = 0; j < 3; ++j) {
123  for (int k = 0; k < 7; ++k) {
124  mat1(i, j, k) = val;
125  mat2(i, j, k) = val;
126  val += 1.0f;
127  }
128  }
129  }
130 
131  Tensor<float, 3> mat3(2, 3, 7);
132  mat3 = mat1 + mat1;
133  Tensor<float, 3, RowMajor> mat4(2, 3, 7);
134  mat4 = mat2 * 3.14f;
135  Tensor<float, 3> mat5(2, 3, 7);
136  mat5 = (mat1 + mat1.constant(1)).inverse().log();
137  Tensor<float, 3, RowMajor> mat6(2, 3, 7);
138  mat6 = mat2.pow(0.5f) * 3.14f;
139  Tensor<float, 3> mat7(2, 3, 7);
140  mat7 = mat1.cwiseMax(mat5 * 2.0f).exp();
141  Tensor<float, 3, RowMajor> mat8(2, 3, 7);
142  mat8 = (-mat2).exp() * 3.14f;
143  Tensor<float, 3, RowMajor> mat9(2, 3, 7);
144  mat9 = mat2 + 3.14f;
145  Tensor<float, 3, RowMajor> mat10(2, 3, 7);
146  mat10 = mat2 - 3.14f;
147  Tensor<float, 3, RowMajor> mat11(2, 3, 7);
148  mat11 = mat2 / 3.14f;
149 
150  val = 1.0f;
151  for (int i = 0; i < 2; ++i) {
152  for (int j = 0; j < 3; ++j) {
153  for (int k = 0; k < 7; ++k) {
154  VERIFY_IS_APPROX(mat3(i, j, k), val + val);
155  VERIFY_IS_APPROX(mat4(i, j, k), val * 3.14f);
156  VERIFY_IS_APPROX(mat5(i, j, k), logf(1.0f / (val + 1)));
157  VERIFY_IS_APPROX(mat6(i, j, k), sqrtf(val) * 3.14f);
158  VERIFY_IS_APPROX(mat7(i, j, k), expf((std::max)(val, mat5(i, j, k) * 2.0f)));
159  VERIFY_IS_APPROX(mat8(i, j, k), expf(-val) * 3.14f);
160  VERIFY_IS_APPROX(mat9(i, j, k), val + 3.14f);
161  VERIFY_IS_APPROX(mat10(i, j, k), val - 3.14f);
162  VERIFY_IS_APPROX(mat11(i, j, k), val / 3.14f);
163  val += 1.0f;
164  }
165  }
166  }
167 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define max(a, b)
Definition: datatypes.h:23
void inverse(const MatrixType &m)
Definition: inverse.cpp:64
char char char int int * k
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16 &a)
Definition: BFloat16.h:615
val
Definition: calibrate.py:119
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::bfloat16_impl::exp(), i, inverse(), j, k, mat1(), max, calibrate::val, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ test_boolean()

static void test_boolean ( )
static
198  {
199  const int kSize = 31;
200  Tensor<int, 1> vec(kSize);
201  std::iota(vec.data(), vec.data() + kSize, 0);
202 
203  // Test ||.
204  Tensor<bool, 1> bool1 = (vec < vec.constant(1) || vec > vec.constant(4)).cast<bool>();
205  for (int i = 0; i < kSize; ++i) {
206  bool expected = i < 1 || i > 4;
207  VERIFY_IS_EQUAL(bool1[i], expected);
208  }
209 
210  // Test &&, including cast of operand vec.
211  Tensor<bool, 1> bool2 = vec.cast<bool>() && (vec < vec.constant(4)).cast<bool>();
212  for (int i = 0; i < kSize; ++i) {
213  bool expected = bool(i) && i < 4;
214  VERIFY_IS_EQUAL(bool2[i], expected);
215  }
216 
217  // Compilation tests:
218  // Test Tensor<bool> against results of cast or comparison; verifies that
219  // CoeffReturnType is set to match Op return type of bool for Unary and Binary
220  // Ops.
221  Tensor<bool, 1> bool3 = vec.cast<bool>() && bool2;
222  bool3 = (vec < vec.constant(4)).cast<bool>() && bool2;
223 }
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), i, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_clip()

static void test_clip ( )
static
434  {
435  Tensor<float, 1> vec(6);
436  vec(0) = 4.0;
437  vec(1) = 8.0;
438  vec(2) = 15.0;
439  vec(3) = 16.0;
440  vec(4) = 23.0;
441  vec(5) = 42.0;
442 
443  float kMin = 20;
444  float kMax = 30;
445 
446  Tensor<float, 1> vec_clipped(6);
447  vec_clipped = vec.clip(kMin, kMax);
448  for (int i = 0; i < 6; ++i) {
449  VERIFY_IS_EQUAL(vec_clipped(i), numext::mini(numext::maxi(vec(i), kMin), kMax));
450  }
451 }
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: MathFunctions.h:926
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
Definition: MathFunctions.h:920

References i, Eigen::numext::maxi(), Eigen::numext::mini(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_constants()

static void test_constants ( )
static
169  {
170  Tensor<float, 3> mat1(2, 3, 7);
171  Tensor<float, 3> mat2(2, 3, 7);
172  Tensor<float, 3> mat3(2, 3, 7);
173 
174  float val = 1.0f;
175  for (int i = 0; i < 2; ++i) {
176  for (int j = 0; j < 3; ++j) {
177  for (int k = 0; k < 7; ++k) {
178  mat1(i, j, k) = val;
179  val += 1.0f;
180  }
181  }
182  }
183  mat2 = mat1.constant(3.14f);
184  mat3 = mat1.cwiseMax(7.3f).exp();
185 
186  val = 1.0f;
187  for (int i = 0; i < 2; ++i) {
188  for (int j = 0; j < 3; ++j) {
189  for (int k = 0; k < 7; ++k) {
190  VERIFY_IS_APPROX(mat2(i, j, k), 3.14f);
191  VERIFY_IS_APPROX(mat3(i, j, k), expf((std::max)(val, 7.3f)));
192  val += 1.0f;
193  }
194  }
195  }
196 }

References i, j, k, mat1(), max, calibrate::val, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ test_functors()

static void test_functors ( )
static
225  {
226  Tensor<float, 3> mat1(2, 3, 7);
227  Tensor<float, 3> mat2(2, 3, 7);
228  Tensor<float, 3> mat3(2, 3, 7);
229 
230  float val = 1.0f;
231  for (int i = 0; i < 2; ++i) {
232  for (int j = 0; j < 3; ++j) {
233  for (int k = 0; k < 7; ++k) {
234  mat1(i, j, k) = val;
235  val += 1.0f;
236  }
237  }
238  }
239  mat2 = mat1.inverse().unaryExpr(&asinf);
240  mat3 = mat1.unaryExpr(&tanhf);
241 
242  val = 1.0f;
243  for (int i = 0; i < 2; ++i) {
244  for (int j = 0; j < 3; ++j) {
245  for (int k = 0; k < 7; ++k) {
246  VERIFY_IS_APPROX(mat2(i, j, k), asinf(1.0f / mat1(i, j, k)));
247  VERIFY_IS_APPROX(mat3(i, j, k), tanhf(mat1(i, j, k)));
248  val += 1.0f;
249  }
250  }
251  }
252 }

References i, j, k, mat1(), calibrate::val, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ test_minmax_nan_propagation()

static void test_minmax_nan_propagation ( )
static
453  {
454  test_minmax_nan_propagation_templ<float>();
455  test_minmax_nan_propagation_templ<double>();
456 }

Referenced by EIGEN_DECLARE_TEST().

◆ test_minmax_nan_propagation_templ()

template<typename Scalar >
void test_minmax_nan_propagation_templ ( )
316  {
317  for (int size = 1; size < 17; ++size) {
318  const Scalar kNaN = std::numeric_limits<Scalar>::quiet_NaN();
319  const Scalar kInf = std::numeric_limits<Scalar>::infinity();
320  const Scalar kZero(0);
321  Tensor<Scalar, 1> vec_full_nan(size);
322  Tensor<Scalar, 1> vec_one_nan(size);
323  Tensor<Scalar, 1> vec_zero(size);
324  vec_full_nan.setConstant(kNaN);
325  vec_zero.setZero();
326  vec_one_nan.setZero();
327  vec_one_nan(size / 2) = kNaN;
328 
329  auto verify_all_nan = [&](const Tensor<Scalar, 1>& v) {
330  for (int i = 0; i < size; ++i) {
331  VERIFY((numext::isnan)(v(i)));
332  }
333  };
334 
335  auto verify_all_zero = [&](const Tensor<Scalar, 1>& v) {
336  for (int i = 0; i < size; ++i) {
337  VERIFY_IS_EQUAL(v(i), Scalar(0));
338  }
339  };
340 
341  // Test NaN propagating max.
342  // max(nan, nan) = nan
343  // max(nan, 0) = nan
344  // max(0, nan) = nan
345  // max(0, 0) = 0
346  verify_all_nan(vec_full_nan.template cwiseMax<PropagateNaN>(kNaN));
347  verify_all_nan(vec_full_nan.template cwiseMax<PropagateNaN>(vec_full_nan));
348  verify_all_nan(vec_full_nan.template cwiseMax<PropagateNaN>(kZero));
349  verify_all_nan(vec_full_nan.template cwiseMax<PropagateNaN>(vec_zero));
350  verify_all_nan(vec_zero.template cwiseMax<PropagateNaN>(kNaN));
351  verify_all_nan(vec_zero.template cwiseMax<PropagateNaN>(vec_full_nan));
352  verify_all_zero(vec_zero.template cwiseMax<PropagateNaN>(kZero));
353  verify_all_zero(vec_zero.template cwiseMax<PropagateNaN>(vec_zero));
354 
355  // Test number propagating max.
356  // max(nan, nan) = nan
357  // max(nan, 0) = 0
358  // max(0, nan) = 0
359  // max(0, 0) = 0
360  verify_all_nan(vec_full_nan.template cwiseMax<PropagateNumbers>(kNaN));
361  verify_all_nan(vec_full_nan.template cwiseMax<PropagateNumbers>(vec_full_nan));
362  verify_all_zero(vec_full_nan.template cwiseMax<PropagateNumbers>(kZero));
363  verify_all_zero(vec_full_nan.template cwiseMax<PropagateNumbers>(vec_zero));
364  verify_all_zero(vec_zero.template cwiseMax<PropagateNumbers>(kNaN));
365  verify_all_zero(vec_zero.template cwiseMax<PropagateNumbers>(vec_full_nan));
366  verify_all_zero(vec_zero.template cwiseMax<PropagateNumbers>(kZero));
367  verify_all_zero(vec_zero.template cwiseMax<PropagateNumbers>(vec_zero));
368 
369  // Test NaN propagating min.
370  // min(nan, nan) = nan
371  // min(nan, 0) = nan
372  // min(0, nan) = nan
373  // min(0, 0) = 0
374  verify_all_nan(vec_full_nan.template cwiseMin<PropagateNaN>(kNaN));
375  verify_all_nan(vec_full_nan.template cwiseMin<PropagateNaN>(vec_full_nan));
376  verify_all_nan(vec_full_nan.template cwiseMin<PropagateNaN>(kZero));
377  verify_all_nan(vec_full_nan.template cwiseMin<PropagateNaN>(vec_zero));
378  verify_all_nan(vec_zero.template cwiseMin<PropagateNaN>(kNaN));
379  verify_all_nan(vec_zero.template cwiseMin<PropagateNaN>(vec_full_nan));
380  verify_all_zero(vec_zero.template cwiseMin<PropagateNaN>(kZero));
381  verify_all_zero(vec_zero.template cwiseMin<PropagateNaN>(vec_zero));
382 
383  // Test number propagating min.
384  // min(nan, nan) = nan
385  // min(nan, 0) = 0
386  // min(0, nan) = 0
387  // min(0, 0) = 0
388  verify_all_nan(vec_full_nan.template cwiseMin<PropagateNumbers>(kNaN));
389  verify_all_nan(vec_full_nan.template cwiseMin<PropagateNumbers>(vec_full_nan));
390  verify_all_zero(vec_full_nan.template cwiseMin<PropagateNumbers>(kZero));
391  verify_all_zero(vec_full_nan.template cwiseMin<PropagateNumbers>(vec_zero));
392  verify_all_zero(vec_zero.template cwiseMin<PropagateNumbers>(kNaN));
393  verify_all_zero(vec_zero.template cwiseMin<PropagateNumbers>(vec_full_nan));
394  verify_all_zero(vec_zero.template cwiseMin<PropagateNumbers>(kZero));
395  verify_all_zero(vec_zero.template cwiseMin<PropagateNumbers>(vec_zero));
396 
397  // Test min and max reduction
399  val = vec_zero.minimum();
400  VERIFY_IS_EQUAL(val(), kZero);
401  val = vec_zero.template minimum<PropagateNaN>();
402  VERIFY_IS_EQUAL(val(), kZero);
403  val = vec_zero.template minimum<PropagateNumbers>();
404  VERIFY_IS_EQUAL(val(), kZero);
405  val = vec_zero.maximum();
406  VERIFY_IS_EQUAL(val(), kZero);
407  val = vec_zero.template maximum<PropagateNaN>();
408  VERIFY_IS_EQUAL(val(), kZero);
409  val = vec_zero.template maximum<PropagateNumbers>();
410  VERIFY_IS_EQUAL(val(), kZero);
411 
412  // Test NaN propagation for tensor of all NaNs.
413  val = vec_full_nan.template minimum<PropagateNaN>();
414  VERIFY((numext::isnan)(val()));
415  val = vec_full_nan.template minimum<PropagateNumbers>();
416  VERIFY_IS_EQUAL(val(), kInf);
417  val = vec_full_nan.template maximum<PropagateNaN>();
418  VERIFY((numext::isnan)(val()));
419  val = vec_full_nan.template maximum<PropagateNumbers>();
420  VERIFY_IS_EQUAL(val(), -kInf);
421 
422  // Test NaN propagation for tensor with a single NaN.
423  val = vec_one_nan.template minimum<PropagateNaN>();
424  VERIFY((numext::isnan)(val()));
425  val = vec_one_nan.template minimum<PropagateNumbers>();
426  VERIFY_IS_EQUAL(val(), (size == 1 ? kInf : kZero));
427  val = vec_one_nan.template maximum<PropagateNaN>();
428  VERIFY((numext::isnan)(val()));
429  val = vec_one_nan.template maximum<PropagateNumbers>();
430  VERIFY_IS_EQUAL(val(), (size == 1 ? -kInf : kZero));
431  }
432 }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
#define VERIFY(a)
Definition: main.h:362
#define isnan(X)
Definition: main.h:109

References i, isnan, Eigen::TensorBase< Derived, AccessLevel >::setConstant(), Eigen::TensorBase< Derived, AccessLevel >::setZero(), size, v, calibrate::val, VERIFY, and VERIFY_IS_EQUAL.

◆ test_select()

static void test_select ( )
static
280  {
281  using TypedGTOp = internal::scalar_cmp_op<float, float, internal::cmp_GT, true>;
282 
283  Tensor<float, 3> selector(2, 3, 7);
284  Tensor<float, 3> mat1(2, 3, 7);
285  Tensor<float, 3> mat2(2, 3, 7);
286  Tensor<float, 3> result(2, 3, 7);
287 
288  selector.setRandom();
289  mat1.setRandom();
290  mat2.setRandom();
291 
292  // test select with a boolean condition
293  result = (selector > selector.constant(0.5f)).select(mat1, mat2);
294 
295  for (int i = 0; i < 2; ++i) {
296  for (int j = 0; j < 3; ++j) {
297  for (int k = 0; k < 7; ++k) {
298  VERIFY_IS_APPROX(result(i, j, k), (selector(i, j, k) > 0.5f) ? mat1(i, j, k) : mat2(i, j, k));
299  }
300  }
301  }
302 
303  // test select with a typed condition
304  result = selector.binaryExpr(selector.constant(0.5f), TypedGTOp()).select(mat1, mat2);
305 
306  for (int i = 0; i < 2; ++i) {
307  for (int j = 0; j < 3; ++j) {
308  for (int k = 0; k < 7; ++k) {
309  VERIFY_IS_APPROX(result(i, j, k), (selector(i, j, k) > 0.5f) ? mat1(i, j, k) : mat2(i, j, k));
310  }
311  }
312  }
313 }
internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GT, true > TypedGTOp
Definition: cxx11_tensor_comparisons.cpp:21

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

Referenced by EIGEN_DECLARE_TEST().

◆ test_type_casting()

static void test_type_casting ( )
static
254  {
255  Tensor<bool, 3> mat1(2, 3, 7);
256  Tensor<float, 3> mat2(2, 3, 7);
257  Tensor<double, 3> mat3(2, 3, 7);
258  mat1.setRandom();
259  mat2.setRandom();
260 
261  mat3 = mat1.cast<double>();
262  for (int i = 0; i < 2; ++i) {
263  for (int j = 0; j < 3; ++j) {
264  for (int k = 0; k < 7; ++k) {
265  VERIFY_IS_APPROX(mat3(i, j, k), mat1(i, j, k) ? 1.0 : 0.0);
266  }
267  }
268  }
269 
270  mat3 = mat2.cast<double>();
271  for (int i = 0; i < 2; ++i) {
272  for (int j = 0; j < 3; ++j) {
273  for (int k = 0; k < 7; ++k) {
274  VERIFY_IS_APPROX(mat3(i, j, k), static_cast<double>(mat2(i, j, k)));
275  }
276  }
277  }
278 }

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

Referenced by EIGEN_DECLARE_TEST().