qtvector.cpp File Reference
#include "main.h"
#include <QtCore/QVector>
#include <Eigen/Geometry>
#include <Eigen/QtAlignedMalloc>

Macros

#define EIGEN_WORK_AROUND_QT_BUG_CALLING_WRONG_OPERATOR_NEW_FIXED_IN_QT_4_5
 

Functions

template<typename MatrixType >
void check_qtvector_matrix (const MatrixType &m)
 
template<typename TransformType >
void check_qtvector_transform (const TransformType &)
 
template<typename QuaternionType >
void check_qtvector_quaternion (const QuaternionType &)
 
 EIGEN_DECLARE_TEST (qtvector)
 

Macro Definition Documentation

◆ EIGEN_WORK_AROUND_QT_BUG_CALLING_WRONG_OPERATOR_NEW_FIXED_IN_QT_4_5

#define EIGEN_WORK_AROUND_QT_BUG_CALLING_WRONG_OPERATOR_NEW_FIXED_IN_QT_4_5

Function Documentation

◆ check_qtvector_matrix()

template<typename MatrixType >
void check_qtvector_matrix ( const MatrixType m)
19  {
20  Index rows = m.rows();
21  Index cols = m.cols();
22  MatrixType x = MatrixType::Random(rows, cols), y = MatrixType::Random(rows, cols);
23  QVector<MatrixType> v(10, MatrixType(rows, cols)), w(20, y);
24  for (int i = 0; i < 20; i++) {
25  VERIFY_IS_APPROX(w[i], y);
26  }
27  v[5] = x;
28  w[6] = v[5];
29  VERIFY_IS_APPROX(w[6], v[5]);
30  v = w;
31  for (int i = 0; i < 20; i++) {
32  VERIFY_IS_APPROX(w[i], v[i]);
33  }
34 
35  v.resize(21);
36  v[20] = x;
37  VERIFY_IS_APPROX(v[20], x);
38  v.fill(y, 22);
39  VERIFY_IS_APPROX(v[21], y);
40  v.push_back(x);
41  VERIFY_IS_APPROX(v[22], x);
42  VERIFY((size_t) & (v[22]) == (size_t) & (v[21]) + sizeof(MatrixType));
43 
44  // do a lot of push_back such that the vector gets internally resized
45  // (with memory reallocation)
46  MatrixType* ref = &w[0];
47  for (int i = 0; i < 30 || ((ref == &w[0]) && i < 300); ++i) v.push_back(w[i % w.size()]);
48  for (int i = 23; i < v.size(); ++i) {
49  VERIFY(v[i] == w[(i - 23) % w.size()]);
50  }
51 }
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
list x
Definition: plotDoE.py:28

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

Referenced by EIGEN_DECLARE_TEST().

◆ check_qtvector_quaternion()

template<typename QuaternionType >
void check_qtvector_quaternion ( const QuaternionType &  )
85  {
86  typedef typename QuaternionType::Coefficients Coefficients;
87  QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
88  QVector<QuaternionType> v(10), w(20, y);
89  v[5] = x;
90  w[6] = v[5];
91  VERIFY_IS_APPROX(w[6], v[5]);
92  v = w;
93  for (int i = 0; i < 20; i++) {
94  VERIFY_IS_APPROX(w[i], v[i]);
95  }
96 
97  v.resize(21);
98  v[20] = x;
99  VERIFY_IS_APPROX(v[20], x);
100  v.fill(y, 22);
101  VERIFY_IS_APPROX(v[21], y);
102  v.push_back(x);
103  VERIFY_IS_APPROX(v[22], x);
104  VERIFY((size_t) & (v[22]) == (size_t) & (v[21]) + sizeof(QuaternionType));
105 
106  // do a lot of push_back such that the vector gets internally resized
107  // (with memory reallocation)
108  QuaternionType* ref = &w[0];
109  for (int i = 0; i < 30 || ((ref == &w[0]) && i < 300); ++i) v.push_back(w[i % w.size()]);
110  for (unsigned int i = 23; int(i) < v.size(); ++i) {
111  VERIFY(v[i].coeffs() == w[(i - 23) % w.size()].coeffs());
112  }
113 }
return int(ret)+1

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

Referenced by EIGEN_DECLARE_TEST().

◆ check_qtvector_transform()

template<typename TransformType >
void check_qtvector_transform ( const TransformType &  )
54  {
55  typedef typename TransformType::MatrixType MatrixType;
56  TransformType x(MatrixType::Random()), y(MatrixType::Random());
57  QVector<TransformType> v(10), w(20, y);
58  v[5] = x;
59  w[6] = v[5];
60  VERIFY_IS_APPROX(w[6], v[5]);
61  v = w;
62  for (int i = 0; i < 20; i++) {
63  VERIFY_IS_APPROX(w[i], v[i]);
64  }
65 
66  v.resize(21);
67  v[20] = x;
68  VERIFY_IS_APPROX(v[20], x);
69  v.fill(y, 22);
70  VERIFY_IS_APPROX(v[21], y);
71  v.push_back(x);
72  VERIFY_IS_APPROX(v[22], x);
73  VERIFY((size_t) & (v[22]) == (size_t) & (v[21]) + sizeof(TransformType));
74 
75  // do a lot of push_back such that the vector gets internally resized
76  // (with memory reallocation)
77  TransformType* ref = &w[0];
78  for (int i = 0; i < 30 || ((ref == &w[0]) && i < 300); ++i) v.push_back(w[i % w.size()]);
79  for (unsigned int i = 23; int(i) < v.size(); ++i) {
80  VERIFY(v[i].matrix() == w[(i - 23) % w.size()].matrix());
81  }
82 }
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, int(), matrix(), v, VERIFY, VERIFY_IS_APPROX, w, plotDoE::x, and y.

Referenced by EIGEN_DECLARE_TEST().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( qtvector  )
115  {
116  // some non vectorizable fixed sizes
117  CALL_SUBTEST(check_qtvector_matrix(Vector2f()));
118  CALL_SUBTEST(check_qtvector_matrix(Matrix3f()));
119  CALL_SUBTEST(check_qtvector_matrix(Matrix3d()));
120 
121  // some vectorizable fixed sizes
122  CALL_SUBTEST(check_qtvector_matrix(Matrix2f()));
123  CALL_SUBTEST(check_qtvector_matrix(Vector4f()));
124  CALL_SUBTEST(check_qtvector_matrix(Matrix4f()));
125  CALL_SUBTEST(check_qtvector_matrix(Matrix4d()));
126 
127  // some dynamic sizes
128  CALL_SUBTEST(check_qtvector_matrix(MatrixXd(1, 1)));
129  CALL_SUBTEST(check_qtvector_matrix(VectorXd(20)));
130  CALL_SUBTEST(check_qtvector_matrix(RowVectorXf(20)));
131  CALL_SUBTEST(check_qtvector_matrix(MatrixXcf(10, 10)));
132 
133  // some Transform
137  // CALL_SUBTEST(check_qtvector_transform(Transform4d()));
138 
139  // some Quaternion
142 }
Transform< double, 3, Affine > Affine3d
Definition: Transform.h:686
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(FUNC)
Definition: main.h:382
void check_qtvector_quaternion(const QuaternionType &)
Definition: qtvector.cpp:85
void check_qtvector_matrix(const MatrixType &m)
Definition: qtvector.cpp:19
void check_qtvector_transform(const TransformType &)
Definition: qtvector.cpp:54

References CALL_SUBTEST, check_qtvector_matrix(), check_qtvector_quaternion(), and check_qtvector_transform().