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 
80 EIGEN_DECLARE_TEST(cxx11_tensor_comparisons)
81 {
84 }
Eigen::Tensor
The tensor class.
Definition: Tensor.h:63
mat1
MatrixXd mat1(size, size)
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
test_equality
static void test_equality()
Definition: cxx11_tensor_comparisons.cpp:47
Eigen::RowMajor
@ RowMajor
Definition: Constants.h:321
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
Eigen::TensorBase< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::setRandom
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition: TensorBase.h:996
main.h
test_orderings
static void test_orderings()
Definition: cxx11_tensor_comparisons.cpp:17
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_comparisons)
Definition: cxx11_tensor_comparisons.cpp:80
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition: main.h:399


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:08