stdvector_overload.cpp File Reference
#include "main.h"
#include <Eigen/StdVector>
#include <Eigen/Geometry>

Functions

template<typename MatrixType >
void check_stdvector_matrix (const MatrixType &m)
 
template<typename TransformType >
void check_stdvector_transform (const TransformType &)
 
template<typename QuaternionType >
void check_stdvector_quaternion (const QuaternionType &)
 
 EIGEN_DECLARE_TEST (stdvector_overload)
 

Function Documentation

◆ check_stdvector_matrix()

template<typename MatrixType >
void check_stdvector_matrix ( const MatrixType m)
29  {
30  Index rows = m.rows();
31  Index cols = m.cols();
32  MatrixType x = MatrixType::Random(rows, cols), y = MatrixType::Random(rows, cols);
33  std::vector<MatrixType> v(10, MatrixType::Zero(rows, cols)), w(20, y);
34  v[5] = x;
35  w[6] = v[5];
36  VERIFY_IS_APPROX(w[6], v[5]);
37  v = w;
38  for (int i = 0; i < 20; i++) {
39  VERIFY_IS_APPROX(w[i], v[i]);
40  }
41 
42  v.resize(21);
43  v[20] = x;
44  VERIFY_IS_APPROX(v[20], x);
45  v.resize(22, y);
46  VERIFY_IS_APPROX(v[21], y);
47  v.push_back(x);
48  VERIFY_IS_APPROX(v[22], x);
49  VERIFY((std::uintptr_t) & (v[22]) == (std::uintptr_t) & (v[21]) + sizeof(MatrixType));
50 
51  // do a lot of push_back such that the vector gets internally resized
52  // (with memory reallocation)
53  MatrixType* ref = &w[0];
54  for (int i = 0; i < 30 || ((ref == &w[0]) && i < 300); ++i) v.push_back(w[i % w.size()]);
55  for (unsigned int i = 23; i < v.size(); ++i) {
56  VERIFY(v[i] == w[(i - 23) % w.size()]);
57  }
58 }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
RowVector3d w
Definition: Matrix_resize_int.cpp:3
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
Scalar * y
Definition: level1_cplx_impl.h:128
int * m
Definition: level2_cplx_impl.h:294
#define VERIFY(a)
Definition: main.h:362
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
list x
Definition: plotDoE.py:28

References cols, i, m, rows, v, VERIFY, VERIFY_IS_APPROX, w, plotDoE::x, y, and oomph::PseudoSolidHelper::Zero.

Referenced by EIGEN_DECLARE_TEST().

◆ check_stdvector_quaternion()

template<typename QuaternionType >
void check_stdvector_quaternion ( const QuaternionType &  )
92  {
93  typedef typename QuaternionType::Coefficients Coefficients;
94  QuaternionType x(Coefficients::Random()), y(Coefficients::Random()), qi = QuaternionType::Identity();
95  std::vector<QuaternionType> v(10, qi), w(20, y);
96  v[5] = x;
97  w[6] = v[5];
98  VERIFY_IS_APPROX(w[6], v[5]);
99  v = w;
100  for (int i = 0; i < 20; i++) {
101  VERIFY_IS_APPROX(w[i], v[i]);
102  }
103 
104  v.resize(21);
105  v[20] = x;
106  VERIFY_IS_APPROX(v[20], x);
107  v.resize(22, y);
108  VERIFY_IS_APPROX(v[21], y);
109  v.push_back(x);
110  VERIFY_IS_APPROX(v[22], x);
111  VERIFY((std::uintptr_t) & (v[22]) == (std::uintptr_t) & (v[21]) + sizeof(QuaternionType));
112 
113  // do a lot of push_back such that the vector gets internally resized
114  // (with memory reallocation)
115  QuaternionType* ref = &w[0];
116  for (int i = 0; i < 30 || ((ref == &w[0]) && i < 300); ++i) v.push_back(w[i % w.size()]);
117  for (unsigned int i = 23; i < v.size(); ++i) {
118  VERIFY(v[i].coeffs() == w[(i - 23) % w.size()].coeffs());
119  }
120 }

References i, v, VERIFY, VERIFY_IS_APPROX, w, plotDoE::x, and y.

Referenced by EIGEN_DECLARE_TEST().

◆ check_stdvector_transform()

template<typename TransformType >
void check_stdvector_transform ( const TransformType &  )
61  {
62  typedef typename TransformType::MatrixType MatrixType;
63  TransformType x(MatrixType::Random()), y(MatrixType::Random());
64  std::vector<TransformType> v(10), w(20, y);
65  v[5] = x;
66  w[6] = v[5];
67  VERIFY_IS_APPROX(w[6], v[5]);
68  v = w;
69  for (int i = 0; i < 20; i++) {
70  VERIFY_IS_APPROX(w[i], v[i]);
71  }
72 
73  v.resize(21);
74  v[20] = x;
75  VERIFY_IS_APPROX(v[20], x);
76  v.resize(22, y);
77  VERIFY_IS_APPROX(v[21], y);
78  v.push_back(x);
79  VERIFY_IS_APPROX(v[22], x);
80  VERIFY((std::uintptr_t) & (v[22]) == (std::uintptr_t) & (v[21]) + sizeof(TransformType));
81 
82  // do a lot of push_back such that the vector gets internally resized
83  // (with memory reallocation)
84  TransformType* ref = &w[0];
85  for (int i = 0; i < 30 || ((ref == &w[0]) && i < 300); ++i) v.push_back(w[i % w.size()]);
86  for (unsigned int i = 23; i < v.size(); ++i) {
87  VERIFY(v[i].matrix() == w[(i - 23) % w.size()].matrix());
88  }
89 }
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85

References i, matrix(), v, VERIFY, VERIFY_IS_APPROX, w, plotDoE::x, and y.

Referenced by EIGEN_DECLARE_TEST().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( stdvector_overload  )
122  {
123  // some non vectorizable fixed sizes
127 
128  // some vectorizable fixed sizes
133 
134  // some dynamic sizes
135  CALL_SUBTEST_3(check_stdvector_matrix(MatrixXd(1, 1)));
136  CALL_SUBTEST_3(check_stdvector_matrix(VectorXd(20)));
137  CALL_SUBTEST_3(check_stdvector_matrix(RowVectorXf(20)));
138  CALL_SUBTEST_3(check_stdvector_matrix(MatrixXcf(10, 10)));
139 
140  // some Transform
141  CALL_SUBTEST_4(check_stdvector_transform(Affine2f())); // does not need the specialization (2+1)^2 = 9
144 
145  // some Quaternion
148 }
Transform< double, 3, Affine > Affine3d
Definition: Transform.h:686
Quaternion< double > Quaterniond
Definition: Eigen/Eigen/src/Geometry/Quaternion.h:387
Quaternion< float > Quaternionf
Definition: Eigen/Eigen/src/Geometry/Quaternion.h:384
Transform< float, 3, Affine > Affine3f
Definition: Transform.h:682
Transform< float, 2, Affine > Affine2f
Definition: Transform.h:680
#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_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
void check_stdvector_matrix(const MatrixType &m)
Definition: stdvector_overload.cpp:29
void check_stdvector_transform(const TransformType &)
Definition: stdvector_overload.cpp:61
void check_stdvector_quaternion(const QuaternionType &)
Definition: stdvector_overload.cpp:92

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, check_stdvector_matrix(), check_stdvector_quaternion(), and check_stdvector_transform().