stddeque.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #include "main.h"
12 #include <Eigen/StdDeque>
13 #include <Eigen/Geometry>
14 
15 template<typename MatrixType>
17 {
18  Index rows = m.rows();
19  Index cols = m.cols();
20  MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
21  std::deque<MatrixType,Eigen::aligned_allocator<MatrixType> > v(10, MatrixType(rows,cols)), w(20, y);
22  v.front() = x;
23  w.front() = w.back();
24  VERIFY_IS_APPROX(w.front(), w.back());
25  v = w;
26 
27  typename std::deque<MatrixType,Eigen::aligned_allocator<MatrixType> >::iterator vi = v.begin();
28  typename std::deque<MatrixType,Eigen::aligned_allocator<MatrixType> >::iterator wi = w.begin();
29  for(int i = 0; i < 20; i++)
30  {
31  VERIFY_IS_APPROX(*vi, *wi);
32  ++vi;
33  ++wi;
34  }
35 
36  v.resize(21);
37  v.back() = x;
38  VERIFY_IS_APPROX(v.back(), x);
39  v.resize(22,y);
40  VERIFY_IS_APPROX(v.back(), y);
41  v.push_back(x);
42  VERIFY_IS_APPROX(v.back(), x);
43 }
44 
45 template<typename TransformType>
46 void check_stddeque_transform(const TransformType&)
47 {
48  typedef typename TransformType::MatrixType MatrixType;
49  TransformType x(MatrixType::Random()), y(MatrixType::Random());
50  std::deque<TransformType,Eigen::aligned_allocator<TransformType> > v(10), w(20, y);
51  v.front() = x;
52  w.front() = w.back();
53  VERIFY_IS_APPROX(w.front(), w.back());
54  v = w;
55 
56  typename std::deque<TransformType,Eigen::aligned_allocator<TransformType> >::iterator vi = v.begin();
57  typename std::deque<TransformType,Eigen::aligned_allocator<TransformType> >::iterator wi = w.begin();
58  for(int i = 0; i < 20; i++)
59  {
60  VERIFY_IS_APPROX(*vi, *wi);
61  ++vi;
62  ++wi;
63  }
64 
65  v.resize(21);
66  v.back() = x;
67  VERIFY_IS_APPROX(v.back(), x);
68  v.resize(22,y);
69  VERIFY_IS_APPROX(v.back(), y);
70  v.push_back(x);
71  VERIFY_IS_APPROX(v.back(), x);
72 }
73 
74 template<typename QuaternionType>
75 void check_stddeque_quaternion(const QuaternionType&)
76 {
77  typedef typename QuaternionType::Coefficients Coefficients;
78  QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
79  std::deque<QuaternionType,Eigen::aligned_allocator<QuaternionType> > v(10), w(20, y);
80  v.front() = x;
81  w.front() = w.back();
82  VERIFY_IS_APPROX(w.front(), w.back());
83  v = w;
84 
85  typename std::deque<QuaternionType,Eigen::aligned_allocator<QuaternionType> >::iterator vi = v.begin();
86  typename std::deque<QuaternionType,Eigen::aligned_allocator<QuaternionType> >::iterator wi = w.begin();
87  for(int i = 0; i < 20; i++)
88  {
89  VERIFY_IS_APPROX(*vi, *wi);
90  ++vi;
91  ++wi;
92  }
93 
94  v.resize(21);
95  v.back() = x;
96  VERIFY_IS_APPROX(v.back(), x);
97  v.resize(22,y);
98  VERIFY_IS_APPROX(v.back(), y);
99  v.push_back(x);
100  VERIFY_IS_APPROX(v.back(), x);
101 }
102 
104 {
105  // some non vectorizable fixed sizes
106  CALL_SUBTEST_1(check_stddeque_matrix(Vector2f()));
107  CALL_SUBTEST_1(check_stddeque_matrix(Matrix3f()));
108  CALL_SUBTEST_2(check_stddeque_matrix(Matrix3d()));
109 
110  // some vectorizable fixed sizes
111  CALL_SUBTEST_1(check_stddeque_matrix(Matrix2f()));
112  CALL_SUBTEST_1(check_stddeque_matrix(Vector4f()));
113  CALL_SUBTEST_1(check_stddeque_matrix(Matrix4f()));
114  CALL_SUBTEST_2(check_stddeque_matrix(Matrix4d()));
115 
116  // some dynamic sizes
117  CALL_SUBTEST_3(check_stddeque_matrix(MatrixXd(1,1)));
118  CALL_SUBTEST_3(check_stddeque_matrix(VectorXd(20)));
119  CALL_SUBTEST_3(check_stddeque_matrix(RowVectorXf(20)));
120  CALL_SUBTEST_3(check_stddeque_matrix(MatrixXcf(10,10)));
121 
122  // some Transform
123  CALL_SUBTEST_4(check_stddeque_transform(Affine2f()));
124  CALL_SUBTEST_4(check_stddeque_transform(Affine3f()));
125  CALL_SUBTEST_4(check_stddeque_transform(Affine3d()));
126 
127  // some Quaternion
128  CALL_SUBTEST_5(check_stddeque_quaternion(Quaternionf()));
129  CALL_SUBTEST_5(check_stddeque_quaternion(Quaterniond()));
130 }
Matrix3f m
void check_stddeque_quaternion(const QuaternionType &)
Definition: stddeque.cpp:75
Transform< float, 3, Affine > Affine3f
Definition: Transform.h:710
Scalar * y
ArrayXcf v
Definition: Cwise_arg.cpp:1
MatrixXf MatrixType
#define VERIFY_IS_APPROX(a, b)
Transform< double, 3, Affine > Affine3d
Definition: Transform.h:714
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
void test_stddeque()
Definition: stddeque.cpp:103
RowVector3d w
Transform< float, 2, Affine > Affine2f
Definition: Transform.h:708
void check_stddeque_matrix(const MatrixType &m)
Definition: stddeque.cpp:16
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
void check_stddeque_transform(const TransformType &)
Definition: stddeque.cpp:46


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:44:50