cxx11_tensor_sugar.cpp
Go to the documentation of this file.
1 #include "main.h"
2 
3 #include <Eigen/CXX11/Tensor>
4 
5 using Eigen::Tensor;
6 using Eigen::RowMajor;
7 
8 static void test_comparison_sugar() {
9  // we already trust comparisons between tensors, we're simply checking that
10  // the sugared versions are doing the same thing
11  Tensor<int, 3> t(6, 7, 5);
12 
13  t.setRandom();
14  // make sure we have at least one value == 0
15  t(0,0,0) = 0;
16 
18 
19 #define TEST_TENSOR_EQUAL(e1, e2) \
20  b = ((e1) == (e2)).all(); \
21  VERIFY(b())
22 
23 #define TEST_OP(op) TEST_TENSOR_EQUAL(t op 0, t op t.constant(0))
24 
25  TEST_OP(==);
26  TEST_OP(!=);
27  TEST_OP(<=);
28  TEST_OP(>=);
29  TEST_OP(<);
30  TEST_OP(>);
31 #undef TEST_OP
32 #undef TEST_TENSOR_EQUAL
33 }
34 
35 
37  Tensor<float, 3> A(6, 7, 5);
38  Tensor<float, 3> B(6, 7, 5);
39  A.setRandom();
40  B.setRandom();
41 
42  const float alpha = 0.43f;
43  const float beta = 0.21f;
44  const float gamma = 0.14f;
45 
46  Tensor<float, 3> R = A.constant(gamma) + A * A.constant(alpha) + B * B.constant(beta);
47  Tensor<float, 3> S = A * alpha + B * beta + gamma;
48  Tensor<float, 3> T = gamma + alpha * A + beta * B;
49 
50  for (int i = 0; i < 6*7*5; ++i) {
51  VERIFY_IS_APPROX(R(i), S(i));
52  VERIFY_IS_APPROX(R(i), T(i));
53  }
54 }
55 
57  Tensor<float, 3> A(6, 7, 5);
58  Tensor<float, 3> B(6, 7, 5);
59  A.setRandom();
60  B.setRandom();
61 
62  const float alpha = 0.43f;
63  const float beta = 0.21f;
64  const float gamma = 0.14f;
65  const float delta = 0.32f;
66 
67  Tensor<float, 3> R = A.constant(gamma) - A / A.constant(alpha)
68  - B.constant(beta) / B - A.constant(delta);
69  Tensor<float, 3> S = gamma - A / alpha - beta / B - delta;
70 
71  for (int i = 0; i < 6*7*5; ++i) {
72  VERIFY_IS_APPROX(R(i), S(i));
73  }
74 }
75 
77 {
81 }
void test_cxx11_tensor_sugar()
Scalar * b
Definition: benchVecAdd.cpp:17
Rot2 R(Rot2::fromAngle(0.1))
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition: TensorBase.h:850
static void test_scalar_sugar_add_mul()
Matrix< SCALARA, Dynamic, Dynamic > A
Definition: bench_gemm.cpp:35
Matrix< SCALARB, Dynamic, Dynamic > B
Definition: bench_gemm.cpp:36
#define VERIFY_IS_APPROX(a, b)
static void test_comparison_sugar()
static void test_scalar_sugar_sub_div()
const mpreal gamma(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition: mpreal.h:2262
Key S(std::uint64_t j)
Eigen::Triplet< double > T
RealScalar alpha
#define CALL_SUBTEST(FUNC)
Definition: main.h:342
#define TEST_OP(op)
The tensor class.
Definition: Tensor.h:63
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:56