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

Macros

#define TEST_TENSOR_EQUAL(e1, e2)
 
#define TEST_OP(op)   TEST_TENSOR_EQUAL(t op 0, t op t.constant(0))
 

Functions

static void test_comparison_sugar ()
 
static void test_scalar_sugar_add_mul ()
 
static void test_scalar_sugar_sub_div ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_sugar)
 

Macro Definition Documentation

◆ TEST_OP

#define TEST_OP (   op)    TEST_TENSOR_EQUAL(t op 0, t op t.constant(0))

◆ TEST_TENSOR_EQUAL

#define TEST_TENSOR_EQUAL (   e1,
  e2 
)
Value:
b = ((e1) == (e2)).all(); \
VERIFY(b())
Scalar * b
Definition: benchVecAdd.cpp:17
static constexpr Eigen::internal::all_t all
Definition: IndexedViewHelper.h:86

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_sugar  )
74  {
78 }
static void test_scalar_sugar_sub_div()
Definition: cxx11_tensor_sugar.cpp:55
static void test_scalar_sugar_add_mul()
Definition: cxx11_tensor_sugar.cpp:35
static void test_comparison_sugar()
Definition: cxx11_tensor_sugar.cpp:8
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, test_comparison_sugar(), test_scalar_sugar_add_mul(), and test_scalar_sugar_sub_div().

◆ test_comparison_sugar()

static void test_comparison_sugar ( )
static
8  {
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 }
The tensor class.
Definition: Tensor.h:68
#define TEST_OP(op)
t
Definition: plotPSD.py:36

References b, plotPSD::t, and TEST_OP.

Referenced by EIGEN_DECLARE_TEST().

◆ test_scalar_sugar_add_mul()

static void test_scalar_sugar_add_mul ( )
static
35  {
36  Tensor<float, 3> A(6, 7, 5);
37  Tensor<float, 3> B(6, 7, 5);
38  A.setRandom();
39  B.setRandom();
40 
41  const float alpha = 0.43f;
42  const float beta = 0.21f;
43  const float gamma = 0.14f;
44 
45  Tensor<float, 3> R = A.constant(gamma) + A * A.constant(alpha) + B * B.constant(beta);
46  Tensor<float, 3> S = A * alpha + B * beta + gamma;
47  Tensor<float, 3> T = gamma + alpha * A + beta * B;
48 
49  for (int i = 0; i < 6 * 7 * 5; ++i) {
50  VERIFY_IS_APPROX(R(i), S(i));
51  VERIFY_IS_APPROX(R(i), T(i));
52  }
53 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
@ R
Definition: StatisticsVector.h:21
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:48
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Derived & setRandom(Index size)
Definition: Random.h:147
Definition: matrices.h:74
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
RealScalar alpha
Definition: level1_cplx_impl.h:151
Scalar beta
Definition: level2_cplx_impl.h:36
Mdouble gamma(Mdouble gamma_in)
This is the gamma function returns the true value for the half integer value.
Definition: ExtendedMath.cc:116
@ S
Definition: quadtree.h:62

References alpha, beta, mathsFunc::gamma(), i, R, oomph::QuadTreeNames::S, Eigen::PlainObjectBase< Derived >::setRandom(), and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ test_scalar_sugar_sub_div()

static void test_scalar_sugar_sub_div ( )
static
55  {
56  Tensor<float, 3> A(6, 7, 5);
57  Tensor<float, 3> B(6, 7, 5);
58  A.setRandom();
59  B.setRandom();
60 
61  const float alpha = 0.43f;
62  const float beta = 0.21f;
63  const float gamma = 0.14f;
64  const float delta = 0.32f;
65 
66  Tensor<float, 3> R = A.constant(gamma) - A / A.constant(alpha) - B.constant(beta) / B - A.constant(delta);
67  Tensor<float, 3> S = gamma - A / alpha - beta / B - delta;
68 
69  for (int i = 0; i < 6 * 7 * 5; ++i) {
70  VERIFY_IS_APPROX(R(i), S(i));
71  }
72 }
int delta
Definition: MultiOpt.py:96

References alpha, beta, MultiOpt::delta, mathsFunc::gamma(), i, R, oomph::QuadTreeNames::S, Eigen::PlainObjectBase< Derived >::setRandom(), and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().