integer_types.cpp File Reference
#include "main.h"

Macros

#define VERIFY_IS_APPROX(a, b)   VERIFY((a) == (b));
 
#define VERIFY_IS_NOT_APPROX(a, b)   VERIFY((a) != (b));
 

Functions

template<typename MatrixType >
void signed_integer_type_tests (const MatrixType &m)
 
template<typename MatrixType >
void integer_type_tests (const MatrixType &m)
 
template<int >
void integer_types_extra ()
 
 EIGEN_DECLARE_TEST (integer_types)
 

Macro Definition Documentation

◆ VERIFY_IS_APPROX

#define VERIFY_IS_APPROX (   a,
  b 
)    VERIFY((a) == (b));

◆ VERIFY_IS_NOT_APPROX

#define VERIFY_IS_NOT_APPROX (   a,
  b 
)    VERIFY((a) != (b));

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( integer_types  )
137  {
138  for (int i = 0; i < g_repeat; i++) {
141 
144 
147 
150 
153 
155 
158 
160  }
161  CALL_SUBTEST_9(integer_types_extra<0>());
162 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
void integer_type_tests(const MatrixType &m)
Definition: integer_types.cpp:46
void signed_integer_type_tests(const MatrixType &m)
Definition: integer_types.cpp:18
static int g_repeat
Definition: main.h:191
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, Eigen::g_repeat, i, integer_type_tests(), and signed_integer_type_tests().

◆ integer_type_tests()

template<typename MatrixType >
void integer_type_tests ( const MatrixType m)
46  {
47  typedef typename MatrixType::Scalar Scalar;
48 
50  enum { is_signed = (Scalar(-1) > Scalar(0)) ? 0 : 1 };
51  VERIFY(int(NumTraits<Scalar>::IsSigned) == is_signed);
52 
54 
55  Index rows = m.rows();
56  Index cols = m.cols();
57 
58  // this test relies a lot on Random.h, and there's not much more that we can do
59  // to test it, hence I consider that we will have tested Random.h
60  MatrixType m1(rows, cols), m2 = MatrixType::Random(rows, cols), m3(rows, cols), mzero = MatrixType::Zero(rows, cols);
61 
63  SquareMatrixType identity = SquareMatrixType::Identity(rows, rows), square = SquareMatrixType::Random(rows, rows);
64  VectorType v1(rows), v2 = VectorType::Random(rows), vzero = VectorType::Zero(rows);
65 
66  do {
67  m1 = MatrixType::Random(rows, cols);
68  } while (m1 == mzero || m1 == m2);
69 
70  do {
71  v1 = VectorType::Random(rows);
72  } while (v1 == vzero || v1 == v2);
73 
76  VERIFY_IS_APPROX(vzero, v1 - v1);
79  VERIFY_IS_APPROX(mzero, m1 - m1);
80 
81  VERIFY_IS_APPROX(m3 = m1, m1);
82  MatrixType m4;
83  VERIFY_IS_APPROX(m4 = m1, m1);
84 
85  m3.real() = m1.real();
86  VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), static_cast<const MatrixType&>(m1).real());
87  VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), m1.real());
88 
89  // check == / != operators
90  VERIFY(m1 == m1);
91  VERIFY(m1 != m2);
92  VERIFY(!(m1 == m2));
93  VERIFY(!(m1 != m1));
94  m1 = m2;
95  VERIFY(m1 == m2);
96  VERIFY(!(m1 != m2));
97 
98  // check linear structure
99 
100  Scalar s1;
101  do {
102  s1 = internal::random<Scalar>();
103  } while (s1 == 0);
104 
105  VERIFY_IS_EQUAL(m1 + m1, 2 * m1);
106  VERIFY_IS_EQUAL(m1 + m2 - m1, m2);
107  VERIFY_IS_EQUAL(m1 * s1, s1 * m1);
108  VERIFY_IS_EQUAL((m1 + m2) * s1, s1 * m1 + s1 * m2);
109  m3 = m2;
110  m3 += m1;
111  VERIFY_IS_EQUAL(m3, m1 + m2);
112  m3 = m2;
113  m3 -= m1;
114  VERIFY_IS_EQUAL(m3, m2 - m1);
115  m3 = m2;
116  m3 *= s1;
117  VERIFY_IS_EQUAL(m3, s1 * m2);
118 
119  // check matrix product.
120 
121  VERIFY_IS_APPROX(identity * m1, m1);
122  VERIFY_IS_APPROX(square * (m1 + m2), square * m1 + square * m2);
123  VERIFY_IS_APPROX((m1 + m2).transpose() * square, m1.transpose() * square + m2.transpose() * square);
124  VERIFY_IS_APPROX((m1 * m2.transpose()) * m1, m1 * (m2.transpose() * m1));
125 }
Matrix3d m1
Definition: IOFormat.cpp:2
MatrixType m2(n_dims)
Map< RowVectorXf > v2(M2.data(), M2.size())
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
float real
Definition: datatypes.h:10
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
#define VERIFY_IS_NOT_APPROX(a, b)
Definition: integer_types.cpp:15
int * m
Definition: level2_cplx_impl.h:294
#define VERIFY(a)
Definition: main.h:362
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
squared absolute sa ArrayBase::abs2 DOXCOMMA MatrixBase::cwiseAbs2 square(power 2)
void transpose()
Definition: skew_symmetric_matrix3.cpp:135
double Zero
Definition: pseudosolid_node_update_elements.cc:35
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Definition: fft_test_shared.h:66

References cols, m, m1, m2(), rows, Eigen::square(), anonymous_namespace{skew_symmetric_matrix3.cpp}::transpose(), v1(), v2(), VERIFY, VERIFY_IS_APPROX, VERIFY_IS_EQUAL, VERIFY_IS_NOT_APPROX, and oomph::PseudoSolidHelper::Zero.

Referenced by EIGEN_DECLARE_TEST().

◆ integer_types_extra()

template<int >
void integer_types_extra ( )
128  {
131  if (sizeof(long) > sizeof(int)) {
134  }
135 }
squared absolute value
Definition: GlobalFunctions.h:87

References Eigen::value, VERIFY, and VERIFY_IS_EQUAL.

◆ signed_integer_type_tests()

template<typename MatrixType >
void signed_integer_type_tests ( const MatrixType m)
18  {
19  typedef typename MatrixType::Scalar Scalar;
20 
21  enum { is_signed = (Scalar(-1) > Scalar(0)) ? 0 : 1 };
22  VERIFY(is_signed == 1);
23 
24  Index rows = m.rows();
25  Index cols = m.cols();
26 
27  MatrixType m1(rows, cols), m2 = MatrixType::Random(rows, cols), mzero = MatrixType::Zero(rows, cols);
28 
29  do {
30  m1 = MatrixType::Random(rows, cols);
31  } while (m1 == mzero || m1 == m2);
32 
33  // check linear structure
34 
35  Scalar s1;
36  do {
37  s1 = internal::random<Scalar>();
38  } while (s1 == 0);
39 
40  VERIFY_IS_EQUAL(-(-m1), m1);
41  VERIFY_IS_EQUAL(-m2 + m1 + m2, m1);
42  VERIFY_IS_EQUAL((-m1 + m2) * s1, -s1 * m1 + s1 * m2);
43 }

References cols, m, m1, m2(), rows, VERIFY, VERIFY_IS_EQUAL, and oomph::PseudoSolidHelper::Zero.

Referenced by EIGEN_DECLARE_TEST().