cxx11_tensor_comparisons.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "main.h"
11 
12 #include <Eigen/CXX11/Tensor>
13 
14 using Eigen::Tensor;
15 using Eigen::RowMajor;
16 
17 static void test_orderings()
18 {
19  Tensor<float, 3> mat1(2,3,7);
20  Tensor<float, 3> mat2(2,3,7);
21  Tensor<bool, 3> lt(2,3,7);
22  Tensor<bool, 3> le(2,3,7);
23  Tensor<bool, 3> gt(2,3,7);
24  Tensor<bool, 3> ge(2,3,7);
25 
26  mat1.setRandom();
27  mat2.setRandom();
28 
29  lt = mat1 < mat2;
30  le = mat1 <= mat2;
31  gt = mat1 > mat2;
32  ge = mat1 >= mat2;
33 
34  for (int i = 0; i < 2; ++i) {
35  for (int j = 0; j < 3; ++j) {
36  for (int k = 0; k < 7; ++k) {
37  VERIFY_IS_EQUAL(lt(i,j,k), mat1(i,j,k) < mat2(i,j,k));
38  VERIFY_IS_EQUAL(le(i,j,k), mat1(i,j,k) <= mat2(i,j,k));
39  VERIFY_IS_EQUAL(gt(i,j,k), mat1(i,j,k) > mat2(i,j,k));
40  VERIFY_IS_EQUAL(ge(i,j,k), mat1(i,j,k) >= mat2(i,j,k));
41  }
42  }
43  }
44 }
45 
46 
47 static void test_equality()
48 {
49  Tensor<float, 3> mat1(2,3,7);
50  Tensor<float, 3> mat2(2,3,7);
51 
52  mat1.setRandom();
53  mat2.setRandom();
54  for (int i = 0; i < 2; ++i) {
55  for (int j = 0; j < 3; ++j) {
56  for (int k = 0; k < 7; ++k) {
57  if (internal::random<bool>()) {
58  mat2(i,j,k) = mat1(i,j,k);
59  }
60  }
61  }
62  }
63 
64  Tensor<bool, 3> eq(2,3,7);
65  Tensor<bool, 3> ne(2,3,7);
66  eq = (mat1 == mat2);
67  ne = (mat1 != mat2);
68 
69  for (int i = 0; i < 2; ++i) {
70  for (int j = 0; j < 3; ++j) {
71  for (int k = 0; k < 7; ++k) {
72  VERIFY_IS_EQUAL(eq(i,j,k), mat1(i,j,k) == mat2(i,j,k));
73  VERIFY_IS_EQUAL(ne(i,j,k), mat1(i,j,k) != mat2(i,j,k));
74  }
75  }
76  }
77 }
78 
79 
81 {
82  CALL_SUBTEST(test_orderings());
83  CALL_SUBTEST(test_equality());
84 }
static void test_equality()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition: TensorBase.h:848
static void test_orderings()
void test_cxx11_tensor_comparisons()
The tensor class.
Definition: Tensor.h:63


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:08