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

Macros

#define EIGEN_TESTMAP_MAX_SIZE   256
 

Functions

template<typename VectorType >
void map_class_vector (const VectorType &m)
 
template<typename MatrixType >
void map_class_matrix (const MatrixType &m)
 
template<typename VectorType >
void map_static_methods (const VectorType &m)
 
template<typename PlainObjectType >
void check_const_correctness (const PlainObjectType &)
 
 EIGEN_DECLARE_TEST (mapped_matrix)
 

Macro Definition Documentation

◆ EIGEN_TESTMAP_MAX_SIZE

#define EIGEN_TESTMAP_MAX_SIZE   256

Function Documentation

◆ check_const_correctness()

template<typename PlainObjectType >
void check_const_correctness ( const PlainObjectType &  )
163  {
164  // there's a lot that we can't test here while still having this test compile!
165  // the only possible approach would be to run a script trying to compile stuff and checking that it fails.
166  // CMake can help with that.
167 
168  // verify that map-to-const don't have LvalueBit
169  typedef std::add_const_t<PlainObjectType> ConstPlainObjectType;
170  VERIFY(!(internal::traits<Map<ConstPlainObjectType> >::Flags & LvalueBit));
174 }
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
const unsigned int LvalueBit
Definition: Constants.h:148
#define VERIFY(a)
Definition: main.h:362
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56

References Eigen::LvalueBit, and VERIFY.

Referenced by EIGEN_DECLARE_TEST().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( mapped_matrix  )
176  {
177  for (int i = 0; i < g_repeat; i++) {
180  CALL_SUBTEST_2(map_class_vector(Vector4d()));
181  CALL_SUBTEST_2(map_class_vector(VectorXd(13)));
183  CALL_SUBTEST_3(map_class_vector(RowVector4f()));
184  CALL_SUBTEST_4(map_class_vector(VectorXcf(8)));
185  CALL_SUBTEST_5(map_class_vector(VectorXi(12)));
187 
189  CALL_SUBTEST_2(map_class_matrix(Matrix4d()));
191  CALL_SUBTEST_4(map_class_matrix(MatrixXcf(internal::random<int>(1, 10), internal::random<int>(1, 10))));
192  CALL_SUBTEST_5(map_class_matrix(MatrixXi(internal::random<int>(1, 10), internal::random<int>(1, 10))));
193 
195  CALL_SUBTEST_7(map_static_methods(Vector3f()));
196  CALL_SUBTEST_8(map_static_methods(RowVector3d()));
197  CALL_SUBTEST_9(map_static_methods(VectorXcd(8)));
198  CALL_SUBTEST_10(map_static_methods(VectorXf(12)));
199  }
200 }
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 map_static_methods(const VectorType &m)
Definition: mapped_matrix.cpp:136
void map_class_vector(const VectorType &m)
Definition: mapped_matrix.cpp:15
void check_const_correctness(const PlainObjectType &)
Definition: mapped_matrix.cpp:163
void map_class_matrix(const MatrixType &m)
Definition: mapped_matrix.cpp:50
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_11(FUNC)
Definition: split_test_helper.h:64
#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
#define CALL_SUBTEST_10(FUNC)
Definition: split_test_helper.h:58

References CALL_SUBTEST_1, CALL_SUBTEST_10, CALL_SUBTEST_11, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, check_const_correctness(), Eigen::g_repeat, i, map_class_matrix(), map_class_vector(), and map_static_methods().

◆ map_class_matrix()

template<typename MatrixType >
void map_class_matrix ( const MatrixType m)
50  {
51  typedef typename MatrixType::Scalar Scalar;
52 
53  Index rows = m.rows(), cols = m.cols(), size = rows * cols;
54  Scalar s1 = internal::random<Scalar>();
55 
56  // array1 and array2 -> aligned heap allocation
57  Scalar* array1 = internal::aligned_new<Scalar>(size);
58  for (int i = 0; i < size; i++) array1[i] = Scalar(1);
59  Scalar* array2 = internal::aligned_new<Scalar>(size);
60  for (int i = 0; i < size; i++) array2[i] = Scalar(1);
61  // array3unaligned -> unaligned pointer to heap
62  Scalar* array3 = new Scalar[size + 1];
63  Index sizep1 = size + 1; // <- without this temporary MSVC 2103 generates bad code
64  for (Index i = 0; i < sizep1; i++) array3[i] = Scalar(1);
65  // In case of no alignment, avoid division by zero.
66  constexpr int alignment = (std::max<int>)(EIGEN_MAX_ALIGN_BYTES, 1);
67  Scalar* array3unaligned = (std::uintptr_t(array3) % alignment) == 0 ? array3 + 1 : array3;
68  Scalar array4[256];
69  if (size <= 256)
70  for (int i = 0; i < size; i++) array4[i] = Scalar(1);
71 
72  Map<MatrixType> map1(array1, rows, cols);
73  Map<MatrixType, AlignedMax> map2(array2, rows, cols);
74  Map<MatrixType> map3(array3unaligned, rows, cols);
75  Map<MatrixType> map4(array4, rows, cols);
76 
77  VERIFY_IS_EQUAL(map1, MatrixType::Ones(rows, cols));
78  map1.setConstant(s1);
79  VERIFY_IS_EQUAL(map1, MatrixType::Constant(rows, cols, s1));
80  map1.setZero();
82 
83  VERIFY_IS_EQUAL(map2, MatrixType::Ones(rows, cols));
84  map2.setConstant(s1);
85  VERIFY_IS_EQUAL(map2, MatrixType::Constant(rows, cols, s1));
86  map2.setZero();
88 
89  VERIFY_IS_EQUAL(map3, MatrixType::Ones(rows, cols));
90  map3.setConstant(s1);
91  VERIFY_IS_EQUAL(map3, MatrixType::Constant(rows, cols, s1));
92  map3.setZero();
94 
95  map1 = MatrixType::Random(rows, cols);
96  map2 = map1;
97  map3 = map1;
98  MatrixType ma1 = map1;
99  MatrixType ma2 = map2;
100  MatrixType ma3 = map3;
101  VERIFY_IS_EQUAL(map1, map2);
102  VERIFY_IS_EQUAL(map1, map3);
103  VERIFY_IS_EQUAL(ma1, ma2);
104  VERIFY_IS_EQUAL(ma1, ma3);
105  VERIFY_IS_EQUAL(ma1, map3);
106 
107  VERIFY_IS_APPROX(s1 * map1, s1 * map2);
108  VERIFY_IS_APPROX(s1 * ma1, s1 * ma2);
109  VERIFY_IS_EQUAL(s1 * ma1, s1 * ma3);
110  VERIFY_IS_APPROX(s1 * map1, s1 * map3);
111 
112  map2 *= s1;
113  map3 *= s1;
114  VERIFY_IS_APPROX(s1 * map1, map2);
115  VERIFY_IS_APPROX(s1 * map1, map3);
116 
117  if (size <= 256) {
118  VERIFY_IS_EQUAL(map4, MatrixType::Ones(rows, cols));
119  map4 = map1;
120  MatrixType ma4 = map4;
121  VERIFY_IS_EQUAL(map1, map4);
122  VERIFY_IS_EQUAL(ma1, map4);
123  VERIFY_IS_EQUAL(ma1, ma4);
124  VERIFY_IS_APPROX(s1 * map1, s1 * map4);
125 
126  map4 *= s1;
127  VERIFY_IS_APPROX(s1 * map1, map4);
128  }
129 
132  delete[] array3;
133 }
#define EIGEN_MAX_ALIGN_BYTES
Definition: ConfigureVectorization.h:163
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
int * m
Definition: level2_cplx_impl.h:294
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
EIGEN_DEVICE_FUNC void aligned_delete(T *ptr, std::size_t size)
Definition: Memory.h:430
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
double Zero
Definition: pseudosolid_node_update_elements.cc:35

References Eigen::internal::aligned_delete(), cols, EIGEN_MAX_ALIGN_BYTES, i, m, rows, size, VERIFY_IS_APPROX, VERIFY_IS_EQUAL, and oomph::PseudoSolidHelper::Zero.

Referenced by EIGEN_DECLARE_TEST().

◆ map_class_vector()

template<typename VectorType >
void map_class_vector ( const VectorType m)
15  {
16  typedef typename VectorType::Scalar Scalar;
17 
18  Index size = m.size();
19 
20  Scalar* array1 = internal::aligned_new<Scalar>(size);
21  Scalar* array2 = internal::aligned_new<Scalar>(size);
22  Scalar* array3 = new Scalar[size + 1];
23  // In case of no alignment, avoid division by zero.
24  constexpr int alignment = (std::max<int>)(EIGEN_MAX_ALIGN_BYTES, 1);
25  Scalar* array3unaligned = (std::uintptr_t(array3) % alignment) == 0 ? array3 + 1 : array3;
27 
28  Map<VectorType, AlignedMax>(array1, size) = VectorType::Random(size);
30  Map<VectorType>(array3unaligned, size) = Map<VectorType>(array1, size);
34  VectorType ma3 = Map<VectorType>(array3unaligned, size);
35  VectorType ma4 = Map<VectorType>(array4, size);
36  VERIFY_IS_EQUAL(ma1, ma2);
37  VERIFY_IS_EQUAL(ma1, ma3);
38  VERIFY_IS_EQUAL(ma1, ma4);
39 #ifdef EIGEN_VECTORIZE
40  if (internal::packet_traits<Scalar>::Vectorizable && size >= AlignedMax)
42 #endif
43 
46  delete[] array3;
47 }
@ AlignedMax
Definition: Constants.h:254
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:329
#define EIGEN_TESTMAP_MAX_SIZE
Definition: mapped_matrix.cpp:12
Definition: fft_test_shared.h:66

References Eigen::internal::aligned_delete(), Eigen::AlignedMax, EIGEN_MAX_ALIGN_BYTES, EIGEN_TESTMAP_MAX_SIZE, m, size, VERIFY_IS_EQUAL, and VERIFY_RAISES_ASSERT.

Referenced by EIGEN_DECLARE_TEST().

◆ map_static_methods()

template<typename VectorType >
void map_static_methods ( const VectorType m)
136  {
137  typedef typename VectorType::Scalar Scalar;
138 
139  Index size = m.size();
140 
141  Scalar* array1 = internal::aligned_new<Scalar>(size);
142  Scalar* array2 = internal::aligned_new<Scalar>(size);
143  Scalar* array3 = new Scalar[size + 1];
144  // In case of no alignment, avoid division by zero.
145  constexpr int alignment = (std::max<int>)(EIGEN_MAX_ALIGN_BYTES, 1);
146  Scalar* array3unaligned = (std::uintptr_t(array3) % alignment) == 0 ? array3 + 1 : array3;
147 
148  VectorType::MapAligned(array1, size) = VectorType::Random(size);
149  VectorType::Map(array2, size) = VectorType::Map(array1, size);
150  VectorType::Map(array3unaligned, size) = VectorType::Map(array1, size);
151  VectorType ma1 = VectorType::Map(array1, size);
152  VectorType ma2 = VectorType::MapAligned(array2, size);
153  VectorType ma3 = VectorType::Map(array3unaligned, size);
154  VERIFY_IS_EQUAL(ma1, ma2);
155  VERIFY_IS_EQUAL(ma1, ma3);
156 
159  delete[] array3;
160 }

References Eigen::internal::aligned_delete(), EIGEN_MAX_ALIGN_BYTES, m, size, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().