stdlist_overload.cpp File Reference
#include "main.h"
#include <Eigen/StdList>
#include <Eigen/Geometry>

Functions

template<class Container , class Position >
Container::iterator get (Container &c, Position position)
 
template<class Container , class Position , class Value >
void set (Container &c, Position position, const Value &value)
 
template<typename MatrixType >
void check_stdlist_matrix (const MatrixType &m)
 
template<typename TransformType >
void check_stdlist_transform (const TransformType &)
 
template<typename QuaternionType >
void check_stdlist_quaternion (const QuaternionType &)
 
 EIGEN_DECLARE_TEST (stdlist_overload)
 

Function Documentation

◆ check_stdlist_matrix()

template<typename MatrixType >
void check_stdlist_matrix ( const MatrixType m)
43  {
44  Index rows = m.rows();
45  Index cols = m.cols();
46  MatrixType x = MatrixType::Random(rows, cols), y = MatrixType::Random(rows, cols);
47  std::list<MatrixType> v(10, MatrixType::Zero(rows, cols)), w(20, y);
48  typename std::list<MatrixType>::iterator itv = get(v, 5);
49  typename std::list<MatrixType>::iterator itw = get(w, 6);
50  *itv = x;
51  *itw = *itv;
52  VERIFY_IS_APPROX(*itw, *itv);
53  v = w;
54  itv = v.begin();
55  itw = w.begin();
56  for (int i = 0; i < 20; i++) {
57  VERIFY_IS_APPROX(*itw, *itv);
58  ++itv;
59  ++itw;
60  }
61 
62  v.resize(21);
63  set(v, 20, x);
64  VERIFY_IS_APPROX(*get(v, 20), x);
65  v.resize(22, y);
66  VERIFY_IS_APPROX(*get(v, 21), y);
67  v.push_back(x);
68  VERIFY_IS_APPROX(*get(v, 22), x);
69 
70  // do a lot of push_back such that the list gets internally resized
71  // (with memory reallocation)
72  MatrixType* ref = &(*get(w, 0));
73  for (int i = 0; i < 30 || ((ref == &(*get(w, 0))) && i < 300); ++i) v.push_back(*get(w, i % w.size()));
74  for (unsigned int i = 23; i < v.size(); ++i) {
75  VERIFY((*get(v, i)) == (*get(w, (i - 23) % w.size())));
76  }
77 }
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
Container::iterator get(Container &c, Position position)
Definition: stdlist_overload.cpp:29
void set(Container &c, Position position, const Value &value)
Definition: stdlist_overload.cpp:36

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

Referenced by EIGEN_DECLARE_TEST().

◆ check_stdlist_quaternion()

template<typename QuaternionType >
void check_stdlist_quaternion ( const QuaternionType &  )
116  {
117  typedef typename QuaternionType::Coefficients Coefficients;
118  QuaternionType x(Coefficients::Random()), y(Coefficients::Random()), qi = QuaternionType::Identity();
119  std::list<QuaternionType> v(10, qi), w(20, y);
120  typename std::list<QuaternionType>::iterator itv = get(v, 5);
121  typename std::list<QuaternionType>::iterator itw = get(w, 6);
122  *itv = x;
123  *itw = *itv;
124  VERIFY_IS_APPROX(*itw, *itv);
125  v = w;
126  itv = v.begin();
127  itw = w.begin();
128  for (int i = 0; i < 20; i++) {
129  VERIFY_IS_APPROX(*itw, *itv);
130  ++itv;
131  ++itw;
132  }
133 
134  v.resize(21, qi);
135  set(v, 20, x);
136  VERIFY_IS_APPROX(*get(v, 20), x);
137  v.resize(22, y);
138  VERIFY_IS_APPROX(*get(v, 21), y);
139  v.push_back(x);
140  VERIFY_IS_APPROX(*get(v, 22), x);
141 
142  // do a lot of push_back such that the list gets internally resized
143  // (with memory reallocation)
144  QuaternionType* ref = &(*get(w, 0));
145  for (int i = 0; i < 30 || ((ref == &(*get(w, 0))) && i < 300); ++i) v.push_back(*get(w, i % w.size()));
146  for (unsigned int i = 23; i < v.size(); ++i) {
147  VERIFY(get(v, i)->coeffs() == get(w, (i - 23) % w.size())->coeffs());
148  }
149 }

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

Referenced by EIGEN_DECLARE_TEST().

◆ check_stdlist_transform()

template<typename TransformType >
void check_stdlist_transform ( const TransformType &  )
80  {
81  typedef typename TransformType::MatrixType MatrixType;
82  TransformType x(MatrixType::Random()), y(MatrixType::Random()), ti = TransformType::Identity();
83  std::list<TransformType> v(10, ti), w(20, y);
84  typename std::list<TransformType>::iterator itv = get(v, 5);
85  typename std::list<TransformType>::iterator itw = get(w, 6);
86  *itv = x;
87  *itw = *itv;
88  VERIFY_IS_APPROX(*itw, *itv);
89  v = w;
90  itv = v.begin();
91  itw = w.begin();
92  for (int i = 0; i < 20; i++) {
93  VERIFY_IS_APPROX(*itw, *itv);
94  ++itv;
95  ++itw;
96  }
97 
98  v.resize(21, ti);
99  set(v, 20, x);
100  VERIFY_IS_APPROX(*get(v, 20), x);
101  v.resize(22, y);
102  VERIFY_IS_APPROX(*get(v, 21), y);
103  v.push_back(x);
104  VERIFY_IS_APPROX(*get(v, 22), x);
105 
106  // do a lot of push_back such that the list gets internally resized
107  // (with memory reallocation)
108  TransformType* ref = &(*get(w, 0));
109  for (int i = 0; i < 30 || ((ref == &(*get(w, 0))) && i < 300); ++i) v.push_back(*get(w, i % w.size()));
110  for (unsigned int i = 23; i < v.size(); ++i) {
111  VERIFY(get(v, i)->matrix() == get(w, (i - 23) % w.size())->matrix());
112  }
113 }
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 get(), i, matrix(), set(), v, VERIFY, VERIFY_IS_APPROX, w, plotDoE::x, and y.

Referenced by EIGEN_DECLARE_TEST().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( stdlist_overload  )
151  {
152  // some non vectorizable fixed sizes
156 
157  // some vectorizable fixed sizes
162 
163  // some dynamic sizes
164  CALL_SUBTEST_3(check_stdlist_matrix(MatrixXd(1, 1)));
165  CALL_SUBTEST_3(check_stdlist_matrix(VectorXd(20)));
166  CALL_SUBTEST_3(check_stdlist_matrix(RowVectorXf(20)));
167  CALL_SUBTEST_3(check_stdlist_matrix(MatrixXcf(10, 10)));
168 
169  // some Transform
170  CALL_SUBTEST_4(check_stdlist_transform(Affine2f())); // does not need the specialization (2+1)^2 = 9
173 
174  // some Quaternion
177 }
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_stdlist_transform(const TransformType &)
Definition: stdlist_overload.cpp:80
void check_stdlist_quaternion(const QuaternionType &)
Definition: stdlist_overload.cpp:116
void check_stdlist_matrix(const MatrixType &m)
Definition: stdlist_overload.cpp:43

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, check_stdlist_matrix(), check_stdlist_quaternion(), and check_stdlist_transform().

◆ get()

◆ set()