This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
View | Details | Raw Unified | Return to bug 1164 | Differences between
and this patch

Collapse All | Expand All

(-)a/Eigen/src/StlSupport/StdDeque.h (-13 / +5 lines)
Lines 13-44 Link Here
13
13
14
#include "details.h"
14
#include "details.h"
15
15
16
// Define the explicit instantiation (e.g. necessary for the Intel compiler)
17
#if EIGEN_COMP_GNUC || EIGEN_COMP_ICC
18
  #define EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(...) template class std::deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> >;
19
#else
20
  #define EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(...)
21
#endif
22
23
/**
16
/**
24
 * This section contains a convenience MACRO which allows an easy specialization of
17
 * This section contains a convenience MACRO which allows an easy specialization of
25
 * std::deque such that for data types with alignment issues the correct allocator
18
 * std::deque such that for data types with alignment issues the correct allocator
26
 * is used automatically.
19
 * is used automatically.
27
 */
20
 */
28
#define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) \
21
#define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) \
29
EIGEN_EXPLICIT_STL_DEQUE_INSTANTIATION(__VA_ARGS__) \
30
namespace std \
22
namespace std \
31
{ \
23
{ \
32
  template<typename _Ay> \
24
  template<> \
33
  class deque<__VA_ARGS__, _Ay>  \
25
  class deque<__VA_ARGS__, std::allocator<__VA_ARGS__> >           \
34
    : public deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
26
    : public deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
35
  { \
27
  { \
36
    typedef deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > deque_base; \
28
    typedef deque<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > deque_base; \
37
  public: \
29
  public: \
38
    typedef __VA_ARGS__ value_type; \
30
    typedef __VA_ARGS__ value_type; \
39
    typedef typename deque_base::allocator_type allocator_type; \
31
    typedef deque_base::allocator_type allocator_type; \
40
    typedef typename deque_base::size_type size_type;  \
32
    typedef deque_base::size_type size_type;  \
41
    typedef typename deque_base::iterator iterator;  \
33
    typedef deque_base::iterator iterator;  \
42
    explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {}  \
34
    explicit deque(const allocator_type& a = allocator_type()) : deque_base(a) {}  \
43
    template<typename InputIterator> \
35
    template<typename InputIterator> \
44
    deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : deque_base(first, last, a) {} \
36
    deque(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : deque_base(first, last, a) {} \
(-)a/Eigen/src/StlSupport/StdList.h (-13 / +5 lines)
Lines 12-43 Link Here
12
12
13
#include "details.h"
13
#include "details.h"
14
14
15
// Define the explicit instantiation (e.g. necessary for the Intel compiler)
16
#if EIGEN_COMP_GNUC || EIGEN_COMP_ICC
17
  #define EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(...) template class std::list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> >;
18
#else
19
  #define EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(...)
20
#endif
21
22
/**
15
/**
23
 * This section contains a convenience MACRO which allows an easy specialization of
16
 * This section contains a convenience MACRO which allows an easy specialization of
24
 * std::list such that for data types with alignment issues the correct allocator
17
 * std::list such that for data types with alignment issues the correct allocator
25
 * is used automatically.
18
 * is used automatically.
26
 */
19
 */
27
#define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) \
20
#define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) \
28
EIGEN_EXPLICIT_STL_LIST_INSTANTIATION(__VA_ARGS__) \
29
namespace std \
21
namespace std \
30
{ \
22
{ \
31
  template<typename _Ay> \
23
  template<> \
32
  class list<__VA_ARGS__, _Ay>  \
24
  class list<__VA_ARGS__, std::allocator<__VA_ARGS__> >           \
33
    : public list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
25
    : public list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \
34
  { \
26
  { \
35
    typedef list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > list_base; \
27
    typedef list<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > list_base; \
36
  public: \
28
  public: \
37
    typedef __VA_ARGS__ value_type; \
29
    typedef __VA_ARGS__ value_type; \
38
    typedef typename list_base::allocator_type allocator_type; \
30
    typedef list_base::allocator_type allocator_type; \
39
    typedef typename list_base::size_type size_type;  \
31
    typedef list_base::size_type size_type;  \
40
    typedef typename list_base::iterator iterator;  \
32
    typedef list_base::iterator iterator;  \
41
    explicit list(const allocator_type& a = allocator_type()) : list_base(a) {}  \
33
    explicit list(const allocator_type& a = allocator_type()) : list_base(a) {}  \
42
    template<typename InputIterator> \
34
    template<typename InputIterator> \
43
    list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : list_base(first, last, a) {} \
35
    list(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : list_base(first, last, a) {} \
(-)a/test/CMakeLists.txt (+2 lines)
Lines 226-232 Link Here
226
ei_add_test(stdvector)
226
ei_add_test(stdvector)
227
ei_add_test(stdvector_overload)
227
ei_add_test(stdvector_overload)
228
ei_add_test(stdlist)
228
ei_add_test(stdlist)
229
ei_add_test(stdlist_overload)
229
ei_add_test(stddeque)
230
ei_add_test(stddeque)
231
ei_add_test(stddeque_overload)
230
ei_add_test(sparse_basic)
232
ei_add_test(sparse_basic)
231
ei_add_test(sparse_block)
233
ei_add_test(sparse_block)
232
ei_add_test(sparse_vector)
234
ei_add_test(sparse_vector)
(-)0e89c9bffbb8 (+159 lines)
Added Link Here
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
13
#include <Eigen/StdDeque>
14
#include <Eigen/Geometry>
15
16
EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(Vector4f)
17
18
EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(Matrix2f)
19
EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(Matrix4f)
20
EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(Matrix4d)
21
22
EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(Affine3f)
23
EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(Affine3d)
24
25
EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(Quaternionf)
26
EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(Quaterniond)
27
28
template<typename MatrixType>
29
void check_stddeque_matrix(const MatrixType& m)
30
{
31
  typename MatrixType::Index rows = m.rows();
32
  typename MatrixType::Index cols = m.cols();
33
  MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
34
  std::deque<MatrixType> v(10, MatrixType(rows,cols)), w(20, y);
35
  v[5] = x;
36
  w[6] = v[5];
37
  VERIFY_IS_APPROX(w[6], v[5]);
38
  v = w;
39
  for(int i = 0; i < 20; i++)
40
  {
41
    VERIFY_IS_APPROX(w[i], v[i]);
42
  }
43
44
  v.resize(21);
45
  v[20] = x;
46
  VERIFY_IS_APPROX(v[20], x);
47
  v.resize(22,y);
48
  VERIFY_IS_APPROX(v[21], y);
49
  v.push_back(x);
50
  VERIFY_IS_APPROX(v[22], x);
51
  VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(MatrixType));
52
53
  // do a lot of push_back such that the deque gets internally resized
54
  // (with memory reallocation)
55
  MatrixType* ref = &w[0];
56
  for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
57
    v.push_back(w[i%w.size()]);
58
  for(unsigned int i=23; i<v.size(); ++i)
59
  {
60
    VERIFY(v[i]==w[(i-23)%w.size()]);
61
  }
62
}
63
64
template<typename TransformType>
65
void check_stddeque_transform(const TransformType&)
66
{
67
  typedef typename TransformType::MatrixType MatrixType;
68
  TransformType x(MatrixType::Random()), y(MatrixType::Random());
69
  std::deque<TransformType> v(10), w(20, y);
70
  v[5] = x;
71
  w[6] = v[5];
72
  VERIFY_IS_APPROX(w[6], v[5]);
73
  v = w;
74
  for(int i = 0; i < 20; i++)
75
  {
76
    VERIFY_IS_APPROX(w[i], v[i]);
77
  }
78
79
  v.resize(21);
80
  v[20] = x;
81
  VERIFY_IS_APPROX(v[20], x);
82
  v.resize(22,y);
83
  VERIFY_IS_APPROX(v[21], y);
84
  v.push_back(x);
85
  VERIFY_IS_APPROX(v[22], x);
86
87
  // do a lot of push_back such that the deque gets internally resized
88
  // (with memory reallocation)
89
  TransformType* ref = &w[0];
90
  for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
91
    v.push_back(w[i%w.size()]);
92
  for(unsigned int i=23; i<v.size(); ++i)
93
  {
94
    VERIFY(v[i].matrix()==w[(i-23)%w.size()].matrix());
95
  }
96
}
97
98
template<typename QuaternionType>
99
void check_stddeque_quaternion(const QuaternionType&)
100
{
101
  typedef typename QuaternionType::Coefficients Coefficients;
102
  QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
103
  std::deque<QuaternionType> v(10), w(20, y);
104
  v[5] = x;
105
  w[6] = v[5];
106
  VERIFY_IS_APPROX(w[6], v[5]);
107
  v = w;
108
  for(int i = 0; i < 20; i++)
109
  {
110
    VERIFY_IS_APPROX(w[i], v[i]);
111
  }
112
113
  v.resize(21);
114
  v[20] = x;
115
  VERIFY_IS_APPROX(v[20], x);
116
  v.resize(22,y);
117
  VERIFY_IS_APPROX(v[21], y);
118
  v.push_back(x);
119
  VERIFY_IS_APPROX(v[22], x);
120
121
  // do a lot of push_back such that the deque gets internally resized
122
  // (with memory reallocation)
123
  QuaternionType* ref = &w[0];
124
  for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
125
    v.push_back(w[i%w.size()]);
126
  for(unsigned int i=23; i<v.size(); ++i)
127
  {
128
    VERIFY(v[i].coeffs()==w[(i-23)%w.size()].coeffs());
129
  }
130
}
131
132
void test_stddeque_overload()
133
{
134
  // some non vectorizable fixed sizes
135
  CALL_SUBTEST_1(check_stddeque_matrix(Vector2f()));
136
  CALL_SUBTEST_1(check_stddeque_matrix(Matrix3f()));
137
  CALL_SUBTEST_2(check_stddeque_matrix(Matrix3d()));
138
139
  // some vectorizable fixed sizes
140
  CALL_SUBTEST_1(check_stddeque_matrix(Matrix2f()));
141
  CALL_SUBTEST_1(check_stddeque_matrix(Vector4f()));
142
  CALL_SUBTEST_1(check_stddeque_matrix(Matrix4f()));
143
  CALL_SUBTEST_2(check_stddeque_matrix(Matrix4d()));
144
145
  // some dynamic sizes
146
  CALL_SUBTEST_3(check_stddeque_matrix(MatrixXd(1,1)));
147
  CALL_SUBTEST_3(check_stddeque_matrix(VectorXd(20)));
148
  CALL_SUBTEST_3(check_stddeque_matrix(RowVectorXf(20)));
149
  CALL_SUBTEST_3(check_stddeque_matrix(MatrixXcf(10,10)));
150
151
  // some Transform
152
  CALL_SUBTEST_4(check_stddeque_transform(Affine2f())); // does not need the specialization (2+1)^2 = 9
153
  CALL_SUBTEST_4(check_stddeque_transform(Affine3f()));
154
  CALL_SUBTEST_4(check_stddeque_transform(Affine3d()));
155
156
  // some Quaternion
157
  CALL_SUBTEST_5(check_stddeque_quaternion(Quaternionf()));
158
  CALL_SUBTEST_5(check_stddeque_quaternion(Quaterniond()));
159
}
(-)0e89c9bffbb8 (+192 lines)
Added Link Here
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
13
#include <Eigen/StdList>
14
#include <Eigen/Geometry>
15
16
EIGEN_DEFINE_STL_LIST_SPECIALIZATION(Vector4f)
17
18
EIGEN_DEFINE_STL_LIST_SPECIALIZATION(Matrix2f)
19
EIGEN_DEFINE_STL_LIST_SPECIALIZATION(Matrix4f)
20
EIGEN_DEFINE_STL_LIST_SPECIALIZATION(Matrix4d)
21
22
EIGEN_DEFINE_STL_LIST_SPECIALIZATION(Affine3f)
23
EIGEN_DEFINE_STL_LIST_SPECIALIZATION(Affine3d)
24
25
EIGEN_DEFINE_STL_LIST_SPECIALIZATION(Quaternionf)
26
EIGEN_DEFINE_STL_LIST_SPECIALIZATION(Quaterniond)
27
28
template <class Container, class Position>
29
typename Container::iterator get(Container & c, Position position)
30
{
31
  typename Container::iterator it = c.begin();
32
  std::advance(it, position);
33
  return it;
34
}
35
36
template <class Container, class Position, class Value>
37
void set(Container & c, Position position, const Value & value)
38
{
39
  typename Container::iterator it = c.begin();
40
  std::advance(it, position);
41
  *it = value;
42
}
43
44
template<typename MatrixType>
45
void check_stdlist_matrix(const MatrixType& m)
46
{
47
  typename MatrixType::Index rows = m.rows();
48
  typename MatrixType::Index cols = m.cols();
49
  MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
50
  std::list<MatrixType> v(10, MatrixType(rows,cols)), w(20, y);
51
  typename std::list<MatrixType>::iterator itv = get(v, 5);
52
  typename std::list<MatrixType>::iterator itw = get(w, 6);
53
  *itv = x;
54
  *itw = *itv;
55
  VERIFY_IS_APPROX(*itw, *itv);
56
  v = w;
57
  itv = v.begin();
58
  itw = w.begin();
59
  for(int i = 0; i < 20; i++)
60
  {
61
    VERIFY_IS_APPROX(*itw, *itv);
62
    ++itv;
63
    ++itw;
64
  }
65
66
  v.resize(21);
67
  set(v, 20, x);
68
  VERIFY_IS_APPROX(*get(v, 20), x);
69
  v.resize(22,y);
70
  VERIFY_IS_APPROX(*get(v, 21), y);
71
  v.push_back(x);
72
  VERIFY_IS_APPROX(*get(v, 22), x);
73
74
  // do a lot of push_back such that the deque gets internally resized
75
  // (with memory reallocation)
76
  MatrixType* ref = &(*get(w, 0));
77
  for(int i=0; i<30 || ((ref==&(*get(w, 0))) && i<300); ++i)
78
    v.push_back(*get(w, i%w.size()));
79
  for(unsigned int i=23; i<v.size(); ++i)
80
  {
81
    VERIFY((*get(v, i))==(*get(w, (i-23)%w.size())));
82
  }
83
}
84
85
template<typename TransformType>
86
void check_stdlist_transform(const TransformType&)
87
{
88
  typedef typename TransformType::MatrixType MatrixType;
89
  TransformType x(MatrixType::Random()), y(MatrixType::Random());
90
  std::list<TransformType> v(10), w(20, y);
91
  typename std::list<TransformType>::iterator itv = get(v, 5);
92
  typename std::list<TransformType>::iterator itw = get(w, 6);
93
  *itv = x;
94
  *itw = *itv;
95
  VERIFY_IS_APPROX(*itw, *itv);
96
  v = w;
97
  itv = v.begin();
98
  itw = w.begin();
99
  for(int i = 0; i < 20; i++)
100
  {
101
    VERIFY_IS_APPROX(*itw, *itv);
102
    ++itv;
103
    ++itw;
104
  }
105
106
  v.resize(21);
107
  set(v, 20, x);
108
  VERIFY_IS_APPROX(*get(v, 20), x);
109
  v.resize(22,y);
110
  VERIFY_IS_APPROX(*get(v, 21), y);
111
  v.push_back(x);
112
  VERIFY_IS_APPROX(*get(v, 22), x);
113
114
  // do a lot of push_back such that the deque gets internally resized
115
  // (with memory reallocation)
116
  TransformType* ref = &(*get(w, 0));
117
  for(int i=0; i<30 || ((ref==&(*get(w, 0))) && i<300); ++i)
118
    v.push_back(*get(w, i%w.size()));
119
  for(unsigned int i=23; i<v.size(); ++i)
120
  {
121
    VERIFY(get(v, i)->matrix()==get(w, (i-23)%w.size())->matrix());
122
  }
123
}
124
125
template<typename QuaternionType>
126
void check_stdlist_quaternion(const QuaternionType&)
127
{
128
  typedef typename QuaternionType::Coefficients Coefficients;
129
  QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
130
  std::list<QuaternionType> v(10), w(20, y);
131
  typename std::list<QuaternionType>::iterator itv = get(v, 5);
132
  typename std::list<QuaternionType>::iterator itw = get(w, 6);
133
  *itv = x;
134
  *itw = *itv;
135
  VERIFY_IS_APPROX(*itw, *itv);
136
  v = w;
137
  itv = v.begin();
138
  itw = w.begin();
139
  for(int i = 0; i < 20; i++)
140
  {
141
    VERIFY_IS_APPROX(*itw, *itv);
142
    ++itv;
143
    ++itw;
144
  }
145
146
  v.resize(21);
147
  set(v, 20, x);
148
  VERIFY_IS_APPROX(*get(v, 20), x);
149
  v.resize(22,y);
150
  VERIFY_IS_APPROX(*get(v, 21), y);
151
  v.push_back(x);
152
  VERIFY_IS_APPROX(*get(v, 22), x);
153
154
  // do a lot of push_back such that the deque gets internally resized
155
  // (with memory reallocation)
156
  QuaternionType* ref = &(*get(w, 0));
157
  for(int i=0; i<30 || ((ref==&(*get(w, 0))) && i<300); ++i)
158
    v.push_back(*get(w, i%w.size()));
159
  for(unsigned int i=23; i<v.size(); ++i)
160
  {
161
    VERIFY(get(v, i)->coeffs()==get(w, (i-23)%w.size())->coeffs());
162
  }
163
}
164
165
void test_stdlist_overload()
166
{
167
  // some non vectorizable fixed sizes
168
  CALL_SUBTEST_1(check_stdlist_matrix(Vector2f()));
169
  CALL_SUBTEST_1(check_stdlist_matrix(Matrix3f()));
170
  CALL_SUBTEST_2(check_stdlist_matrix(Matrix3d()));
171
172
  // some vectorizable fixed sizes
173
  CALL_SUBTEST_1(check_stdlist_matrix(Matrix2f()));
174
  CALL_SUBTEST_1(check_stdlist_matrix(Vector4f()));
175
  CALL_SUBTEST_1(check_stdlist_matrix(Matrix4f()));
176
  CALL_SUBTEST_2(check_stdlist_matrix(Matrix4d()));
177
178
  // some dynamic sizes
179
  CALL_SUBTEST_3(check_stdlist_matrix(MatrixXd(1,1)));
180
  CALL_SUBTEST_3(check_stdlist_matrix(VectorXd(20)));
181
  CALL_SUBTEST_3(check_stdlist_matrix(RowVectorXf(20)));
182
  CALL_SUBTEST_3(check_stdlist_matrix(MatrixXcf(10,10)));
183
184
  // some Transform
185
  CALL_SUBTEST_4(check_stdlist_transform(Affine2f())); // does not need the specialization (2+1)^2 = 9
186
  CALL_SUBTEST_4(check_stdlist_transform(Affine3f()));
187
  CALL_SUBTEST_4(check_stdlist_transform(Affine3d()));
188
189
  // some Quaternion
190
  CALL_SUBTEST_5(check_stdlist_quaternion(Quaternionf()));
191
  CALL_SUBTEST_5(check_stdlist_quaternion(Quaterniond()));
192
}

Return to bug 1164