dense_storage.cpp File Reference
#include "main.h"
#include "AnnoyingScalar.h"
#include "MovableScalar.h"
#include "SafeScalar.h"
#include <Eigen/Core>

Macros

#define EIGEN_TESTING_PLAINOBJECT_CTOR
 

Typedefs

using DenseStorageD3x3 = Eigen::DenseStorage< double, 9, 3, 3, 0 >
 

Functions

template<typename T , int Size, int Rows, int Cols>
void dense_storage_copy (int rows, int cols)
 
template<typename T , int Size, int Rows, int Cols>
void dense_storage_assignment (int rows, int cols)
 
template<typename T , int Size, int Rows, int Cols>
void dense_storage_swap (int rowsa, int colsa, int rowsb, int colsb)
 
template<typename T , int Size, std::size_t Alignment>
void dense_storage_alignment ()
 
template<typename T >
void dense_storage_tests ()
 
template<typename PlainType >
void plaintype_tests ()
 
 EIGEN_DECLARE_TEST (dense_storage)
 

Macro Definition Documentation

◆ EIGEN_TESTING_PLAINOBJECT_CTOR

#define EIGEN_TESTING_PLAINOBJECT_CTOR

Typedef Documentation

◆ DenseStorageD3x3

Function Documentation

◆ dense_storage_alignment()

template<typename T , int Size, std::size_t Alignment>
void dense_storage_alignment ( )
106  {
107  struct alignas(Alignment) Empty1 {};
109 
110  struct EIGEN_ALIGN_TO_BOUNDARY(Alignment) Empty2 {};
112 
113  struct Nested1 {
114  EIGEN_ALIGN_TO_BOUNDARY(Alignment) T data[Size];
115  };
117 
118  VERIFY_IS_EQUAL((std::alignment_of<internal::plain_array<T, Size, AutoAlign, Alignment>>::value), Alignment);
119 
120  const std::size_t default_alignment = internal::compute_default_alignment<T, Size>::value;
121  if (default_alignment > 0) {
122  VERIFY_IS_EQUAL((std::alignment_of<DenseStorage<T, Size, 1, 1, AutoAlign>>::value), default_alignment);
123  VERIFY_IS_EQUAL((std::alignment_of<Matrix<T, Size, 1, AutoAlign>>::value), default_alignment);
124  struct Nested2 {
126  };
128  }
129 }
#define EIGEN_ALIGN_TO_BOUNDARY(n)
Definition: ConfigureVectorization.h:37
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
int data[]
Definition: Map_placement_new.cpp:1
Definition: DenseStorage.h:541
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
squared absolute value
Definition: GlobalFunctions.h:87

References data, EIGEN_ALIGN_TO_BOUNDARY, Eigen::value, and VERIFY_IS_EQUAL.

◆ dense_storage_assignment()

template<typename T , int Size, int Rows, int Cols>
void dense_storage_assignment ( int  rows,
int  cols 
)
69  {
70  typedef DenseStorage<T, Size, Rows, Cols, 0> DenseStorageType;
71 
72  const int size = rows * cols;
73  DenseStorageType reference(size, rows, cols);
74  T* raw_reference = reference.data();
75  for (int i = 0; i < size; ++i) raw_reference[i] = internal::random<T>();
76 
77  DenseStorageType copied_reference;
78  copied_reference = reference;
79  const T* raw_copied_reference = copied_reference.data();
80  for (int i = 0; i < size; ++i) VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
81 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17

References cols, i, rows, size, and VERIFY_IS_EQUAL.

◆ dense_storage_copy()

template<typename T , int Size, int Rows, int Cols>
void dense_storage_copy ( int  rows,
int  cols 
)
55  {
56  typedef DenseStorage<T, Size, Rows, Cols, 0> DenseStorageType;
57 
58  const int size = rows * cols;
59  DenseStorageType reference(size, rows, cols);
60  T* raw_reference = reference.data();
61  for (int i = 0; i < size; ++i) raw_reference[i] = internal::random<T>();
62 
63  DenseStorageType copied_reference(reference);
64  const T* raw_copied_reference = copied_reference.data();
65  for (int i = 0; i < size; ++i) VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
66 }

References cols, i, rows, size, and VERIFY_IS_EQUAL.

◆ dense_storage_swap()

template<typename T , int Size, int Rows, int Cols>
void dense_storage_swap ( int  rowsa,
int  colsa,
int  rowsb,
int  colsb 
)
84  {
85  typedef DenseStorage<T, Size, Rows, Cols, 0> DenseStorageType;
86 
87  const int sizea = rowsa * colsa;
88  ArrayX<T> referencea(sizea);
89  referencea.setRandom();
90  DenseStorageType a(sizea, rowsa, colsa);
91  for (int i = 0; i < sizea; ++i) a.data()[i] = referencea(i);
92 
93  const int sizeb = rowsb * colsb;
94  ArrayX<T> referenceb(sizeb);
95  referenceb.setRandom();
96  DenseStorageType b(sizeb, rowsb, colsb);
97  for (int i = 0; i < sizeb; ++i) b.data()[i] = referenceb(i);
98 
99  a.swap(b);
100 
101  for (int i = 0; i < sizea; i++) VERIFY_IS_EQUAL(b.data()[i], referencea(i));
102  for (int i = 0; i < sizeb; i++) VERIFY_IS_EQUAL(a.data()[i], referenceb(i));
103 }
Scalar * b
Definition: benchVecAdd.cpp:17
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, b, i, and VERIFY_IS_EQUAL.

◆ dense_storage_tests()

template<typename T >
void dense_storage_tests ( )
132  {
133  // Dynamic Storage.
134  dense_storage_copy<T, Dynamic, Dynamic, Dynamic>(4, 3);
135  dense_storage_copy<T, Dynamic, Dynamic, 3>(4, 3);
136  dense_storage_copy<T, Dynamic, 4, Dynamic>(4, 3);
137  // Fixed Storage.
138  dense_storage_copy<T, 12, 4, 3>(4, 3);
139  dense_storage_copy<T, 12, Dynamic, Dynamic>(4, 3);
140  dense_storage_copy<T, 12, 4, Dynamic>(4, 3);
141  dense_storage_copy<T, 12, Dynamic, 3>(4, 3);
142  // Fixed Storage with Uninitialized Elements.
143  dense_storage_copy<T, 18, Dynamic, Dynamic>(4, 3);
144  dense_storage_copy<T, 18, 4, Dynamic>(4, 3);
145  dense_storage_copy<T, 18, Dynamic, 3>(4, 3);
146 
147  // Dynamic Storage.
148  dense_storage_assignment<T, Dynamic, Dynamic, Dynamic>(4, 3);
149  dense_storage_assignment<T, Dynamic, Dynamic, 3>(4, 3);
150  dense_storage_assignment<T, Dynamic, 4, Dynamic>(4, 3);
151  // Fixed Storage.
152  dense_storage_assignment<T, 12, 4, 3>(4, 3);
153  dense_storage_assignment<T, 12, Dynamic, Dynamic>(4, 3);
154  dense_storage_assignment<T, 12, 4, Dynamic>(4, 3);
155  dense_storage_assignment<T, 12, Dynamic, 3>(4, 3);
156  // Fixed Storage with Uninitialized Elements.
157  dense_storage_assignment<T, 18, Dynamic, Dynamic>(4, 3);
158  dense_storage_assignment<T, 18, 4, Dynamic>(4, 3);
159  dense_storage_assignment<T, 18, Dynamic, 3>(4, 3);
160 
161  // Dynamic Storage.
162  dense_storage_swap<T, Dynamic, Dynamic, Dynamic>(4, 3, 4, 3);
163  dense_storage_swap<T, Dynamic, Dynamic, Dynamic>(4, 3, 2, 1);
164  dense_storage_swap<T, Dynamic, Dynamic, Dynamic>(2, 1, 4, 3);
165  dense_storage_swap<T, Dynamic, Dynamic, 3>(4, 3, 4, 3);
166  dense_storage_swap<T, Dynamic, Dynamic, 3>(4, 3, 2, 3);
167  dense_storage_swap<T, Dynamic, Dynamic, 3>(2, 3, 4, 3);
168  dense_storage_swap<T, Dynamic, 4, Dynamic>(4, 3, 4, 3);
169  dense_storage_swap<T, Dynamic, 4, Dynamic>(4, 3, 4, 1);
170  dense_storage_swap<T, Dynamic, 4, Dynamic>(4, 1, 4, 3);
171  // Fixed Storage.
172  dense_storage_swap<T, 12, 4, 3>(4, 3, 4, 3);
173  dense_storage_swap<T, 12, Dynamic, Dynamic>(4, 3, 4, 3);
174  dense_storage_swap<T, 12, Dynamic, Dynamic>(4, 3, 2, 1);
175  dense_storage_swap<T, 12, Dynamic, Dynamic>(2, 1, 4, 3);
176  dense_storage_swap<T, 12, 4, Dynamic>(4, 3, 4, 3);
177  dense_storage_swap<T, 12, 4, Dynamic>(4, 3, 4, 1);
178  dense_storage_swap<T, 12, 4, Dynamic>(4, 1, 4, 3);
179  dense_storage_swap<T, 12, Dynamic, 3>(4, 3, 4, 3);
180  dense_storage_swap<T, 12, Dynamic, 3>(4, 3, 2, 3);
181  dense_storage_swap<T, 12, Dynamic, 3>(2, 3, 4, 3);
182  // Fixed Storage with Uninitialized Elements.
183  dense_storage_swap<T, 18, Dynamic, Dynamic>(4, 3, 4, 3);
184  dense_storage_swap<T, 18, Dynamic, Dynamic>(4, 3, 2, 1);
185  dense_storage_swap<T, 18, Dynamic, Dynamic>(2, 1, 4, 3);
186  dense_storage_swap<T, 18, 4, Dynamic>(4, 3, 4, 3);
187  dense_storage_swap<T, 18, 4, Dynamic>(4, 3, 4, 1);
188  dense_storage_swap<T, 18, 4, Dynamic>(4, 1, 4, 3);
189  dense_storage_swap<T, 18, Dynamic, 3>(4, 3, 4, 3);
190  dense_storage_swap<T, 18, Dynamic, 3>(4, 3, 2, 3);
191  dense_storage_swap<T, 18, Dynamic, 3>(2, 3, 4, 3);
192 
193  dense_storage_alignment<T, 16, 8>();
194  dense_storage_alignment<T, 16, 16>();
195  dense_storage_alignment<T, 16, 32>();
196  dense_storage_alignment<T, 16, 64>();
197 }

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( dense_storage  )
253  {
254  dense_storage_tests<int>();
255  dense_storage_tests<float>();
256  dense_storage_tests<SafeScalar<float>>();
257  dense_storage_tests<MovableScalar<float>>();
258  dense_storage_tests<AnnoyingScalar>();
259  for (int i = 0; i < g_repeat; i++) {
260  plaintype_tests<Matrix<float, 0, 0, ColMajor>>();
261  plaintype_tests<Matrix<float, Dynamic, Dynamic, ColMajor, 0, 0>>();
262 
263  plaintype_tests<Matrix<float, 16, 16, ColMajor>>();
264  plaintype_tests<Matrix<float, 16, Dynamic, ColMajor>>();
265  plaintype_tests<Matrix<float, Dynamic, Dynamic, ColMajor>>();
266  plaintype_tests<Matrix<float, Dynamic, Dynamic, ColMajor, 16, 16>>();
267 
268  plaintype_tests<Matrix<SafeScalar<float>, 16, 16, ColMajor>>();
269  plaintype_tests<Matrix<SafeScalar<float>, 16, Dynamic, ColMajor>>();
270  plaintype_tests<Matrix<SafeScalar<float>, Dynamic, Dynamic, ColMajor>>();
271  plaintype_tests<Matrix<SafeScalar<float>, Dynamic, Dynamic, ColMajor, 16, 16>>();
272 
273  plaintype_tests<Matrix<MovableScalar<float>, 16, 16, ColMajor>>();
274  plaintype_tests<Matrix<MovableScalar<float>, 16, Dynamic, ColMajor>>();
275  plaintype_tests<Matrix<MovableScalar<float>, Dynamic, Dynamic, ColMajor>>();
276  plaintype_tests<Matrix<MovableScalar<float>, Dynamic, Dynamic, ColMajor, 16, 16>>();
277 
278  plaintype_tests<Matrix<AnnoyingScalar, 16, 16, ColMajor>>();
279  plaintype_tests<Matrix<AnnoyingScalar, 16, Dynamic, ColMajor>>();
280  plaintype_tests<Matrix<AnnoyingScalar, Dynamic, Dynamic, ColMajor>>();
281  plaintype_tests<Matrix<AnnoyingScalar, Dynamic, Dynamic, ColMajor, 16, 16>>();
282  }
283 }
@ ColMajor
Definition: Constants.h:318
static int g_repeat
Definition: main.h:191
const int Dynamic
Definition: Constants.h:25

References Eigen::ColMajor, Eigen::Dynamic, Eigen::g_repeat, and i.

◆ plaintype_tests()

template<typename PlainType >
void plaintype_tests ( )
200  {
201  constexpr int RowsAtCompileTime = PlainType::RowsAtCompileTime;
202  constexpr int ColsAtCompileTime = PlainType::ColsAtCompileTime;
203  constexpr int MaxRowsAtCompileTime = PlainType::MaxRowsAtCompileTime;
204  constexpr int MaxColsAtCompileTime = PlainType::MaxColsAtCompileTime;
205  const Index expectedDefaultRows = RowsAtCompileTime == Dynamic ? 0 : RowsAtCompileTime;
206  const Index expectedDefaultCols = ColsAtCompileTime == Dynamic ? 0 : ColsAtCompileTime;
207  const Index minRows = RowsAtCompileTime == Dynamic ? 0 : RowsAtCompileTime;
208  const Index minCols = ColsAtCompileTime == Dynamic ? 0 : ColsAtCompileTime;
209  const Index maxRows = MaxRowsAtCompileTime == Dynamic ? 100 : MaxRowsAtCompileTime;
210  const Index maxCols = MaxColsAtCompileTime == Dynamic ? 100 : MaxColsAtCompileTime;
211  const Index rows = internal::random<Index>(minRows, maxRows);
212  const Index cols = internal::random<Index>(minCols, maxCols);
213  // default construction
214  PlainType m0;
215  VERIFY_IS_EQUAL(m0.rows(), expectedDefaultRows);
216  VERIFY_IS_EQUAL(m0.cols(), expectedDefaultCols);
217  m0.resize(rows, cols);
218  m0.setRandom();
219  // copy construction
220  PlainType m1(m0);
221  VERIFY_IS_EQUAL(m1.rows(), m0.rows());
222  VERIFY_IS_EQUAL(m1.cols(), m0.cols());
224  // move construction
225  PlainType m2(std::move(m1));
226  VERIFY_IS_EQUAL(m2.rows(), m0.rows());
227  VERIFY_IS_EQUAL(m2.cols(), m0.cols());
229  // check that object is usable after move construction
230  m1.resize(minRows, minCols);
231  m1.setRandom();
232  // copy assignment
233  m1 = m0;
234  VERIFY_IS_EQUAL(m1.rows(), m0.rows());
235  VERIFY_IS_EQUAL(m1.cols(), m0.cols());
237  // move assignment
238  m2.resize(minRows, minCols);
239  m2.setRandom();
240  m2 = std::move(m1);
241  VERIFY_IS_EQUAL(m2.rows(), m0.rows());
242  VERIFY_IS_EQUAL(m2.cols(), m0.cols());
244  // check that object is usable after move assignment
245  m1.resize(minRows, minCols);
246  m1.setRandom();
247  m1 = m2;
248  VERIFY_IS_EQUAL(m1.rows(), m0.rows());
249  VERIFY_IS_EQUAL(m1.cols(), m0.cols());
251 }
Matrix3d m1
Definition: IOFormat.cpp:2
MatrixType m2(n_dims)
#define VERIFY_IS_CWISE_EQUAL(a, b)
Definition: main.h:375
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83

References cols, Eigen::Dynamic, m1, m2(), rows, VERIFY_IS_CWISE_EQUAL, and VERIFY_IS_EQUAL.