DenseStorage.h
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 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
6 // Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
7 //
8 // This Source Code Form is subject to the terms of the Mozilla
9 // Public License v. 2.0. If a copy of the MPL was not distributed
10 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 
12 #ifndef EIGEN_MATRIXSTORAGE_H
13 #define EIGEN_MATRIXSTORAGE_H
14 
15 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
16  #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
17 #else
18  #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
19 #endif
20 
21 namespace Eigen {
22 
23 namespace internal {
24 
26 
31 template <typename T, int Size, int MatrixOrArrayOptions,
32  int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
33  : (((Size*sizeof(T))%16)==0) ? 16
34  : 0 >
36 {
37  T array[Size];
38 
40  {
41  EIGEN_STATIC_ASSERT(Size * sizeof(T) <= 128 * 128 * 8, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
42  }
43 
45  {
46  EIGEN_STATIC_ASSERT(Size * sizeof(T) <= 128 * 128 * 8, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
47  }
48 };
49 
50 #if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
51  #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
52 #elif EIGEN_GNUC_AT_LEAST(4,7)
53  // GCC 4.7 is too aggressive in its optimizations and remove the alignement test based on the fact the array is declared to be aligned.
54  // See this bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900
55  // Hiding the origin of the array pointer behind a function argument seems to do the trick even if the function is inlined:
56  template<typename PtrType>
57  EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) { return array; }
58  #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
59  eigen_assert((reinterpret_cast<size_t>(eigen_unaligned_array_assert_workaround_gcc47(array)) & sizemask) == 0 \
60  && "this assertion is explained here: " \
61  "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
62  " **** READ THIS WEB PAGE !!! ****");
63 #else
64  #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
65  eigen_assert((reinterpret_cast<size_t>(array) & sizemask) == 0 \
66  && "this assertion is explained here: " \
67  "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
68  " **** READ THIS WEB PAGE !!! ****");
69 #endif
70 
71 template <typename T, int Size, int MatrixOrArrayOptions>
73 {
74  EIGEN_USER_ALIGN16 T array[Size];
75 
77  {
79  EIGEN_STATIC_ASSERT(Size * sizeof(T) <= 128 * 128 * 8, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
80  }
81 
83  {
84  EIGEN_STATIC_ASSERT(Size * sizeof(T) <= 128 * 128 * 8, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
85  }
86 };
87 
88 template <typename T, int MatrixOrArrayOptions, int Alignment>
90 {
94 };
95 
96 } // end namespace internal
97 
110 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage;
111 
112 // purely fixed-size matrix
113 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage
114 {
116  public:
117  inline DenseStorage() {}
119  : m_data(internal::constructor_without_unaligned_array_assert()) {}
121  inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); }
122  static inline DenseIndex rows(void) {return _Rows;}
123  static inline DenseIndex cols(void) {return _Cols;}
126  inline const T *data() const { return m_data.array; }
127  inline T *data() { return m_data.array; }
128 };
129 
130 // null matrix
131 template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options>
132 {
133  public:
134  inline DenseStorage() {}
137  inline void swap(DenseStorage& ) {}
138  static inline DenseIndex rows(void) {return _Rows;}
139  static inline DenseIndex cols(void) {return _Cols;}
142  inline const T *data() const { return 0; }
143  inline T *data() { return 0; }
144 };
145 
146 // more specializations for null matrices; these are necessary to resolve ambiguities
147 template<typename T, int _Options> class DenseStorage<T, 0, Dynamic, Dynamic, _Options>
149 
150 template<typename T, int _Rows, int _Options> class DenseStorage<T, 0, _Rows, Dynamic, _Options>
152 
153 template<typename T, int _Cols, int _Options> class DenseStorage<T, 0, Dynamic, _Cols, _Options>
155 
156 // dynamic-size matrix with fixed-size storage
157 template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
158 {
162  public:
163  inline DenseStorage() : m_rows(0), m_cols(0) {}
165  : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
166  inline DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) : m_rows(nbRows), m_cols(nbCols) {}
167  inline void swap(DenseStorage& other)
168  { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
169  inline DenseIndex rows() const {return m_rows;}
170  inline DenseIndex cols() const {return m_cols;}
171  inline void conservativeResize(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) { m_rows = nbRows; m_cols = nbCols; }
172  inline void resize(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) { m_rows = nbRows; m_cols = nbCols; }
173  inline const T *data() const { return m_data.array; }
174  inline T *data() { return m_data.array; }
175 };
176 
177 // dynamic-size matrix with fixed-size storage and fixed width
178 template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options>
179 {
182  public:
183  inline DenseStorage() : m_rows(0) {}
185  : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
186  inline DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex) : m_rows(nbRows) {}
187  inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
188  inline DenseIndex rows(void) const {return m_rows;}
189  inline DenseIndex cols(void) const {return _Cols;}
190  inline void conservativeResize(DenseIndex, DenseIndex nbRows, DenseIndex) { m_rows = nbRows; }
191  inline void resize(DenseIndex, DenseIndex nbRows, DenseIndex) { m_rows = nbRows; }
192  inline const T *data() const { return m_data.array; }
193  inline T *data() { return m_data.array; }
194 };
195 
196 // dynamic-size matrix with fixed-size storage and fixed height
197 template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options>
198 {
201  public:
202  inline DenseStorage() : m_cols(0) {}
204  : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
205  inline DenseStorage(DenseIndex, DenseIndex, DenseIndex nbCols) : m_cols(nbCols) {}
206  inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
207  inline DenseIndex rows(void) const {return _Rows;}
208  inline DenseIndex cols(void) const {return m_cols;}
209  inline void conservativeResize(DenseIndex, DenseIndex, DenseIndex nbCols) { m_cols = nbCols; }
210  inline void resize(DenseIndex, DenseIndex, DenseIndex nbCols) { m_cols = nbCols; }
211  inline const T *data() const { return m_data.array; }
212  inline T *data() { return m_data.array; }
213 };
214 
215 // purely dynamic matrix.
216 template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
217 {
221  public:
222  inline DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
224  : m_data(0), m_rows(0), m_cols(0) {}
225  inline DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
226  : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows), m_cols(nbCols)
228  inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
229  inline void swap(DenseStorage& other)
230  { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
231  inline DenseIndex rows(void) const {return m_rows;}
232  inline DenseIndex cols(void) const {return m_cols;}
233  inline void conservativeResize(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
234  {
235  m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
236  m_rows = nbRows;
237  m_cols = nbCols;
238  }
239  void resize(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
240  {
241  if(size != m_rows*m_cols)
242  {
243  internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
244  if (size)
245  m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
246  else
247  m_data = 0;
249  }
250  m_rows = nbRows;
251  m_cols = nbCols;
252  }
253  inline const T *data() const { return m_data; }
254  inline T *data() { return m_data; }
255 };
256 
257 // matrix with dynamic width and fixed height (so that matrix has dynamic size).
258 template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
259 {
262  public:
263  inline DenseStorage() : m_data(0), m_cols(0) {}
265  inline DenseStorage(DenseIndex size, DenseIndex, DenseIndex nbCols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(nbCols)
267  inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
268  inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
269  static inline DenseIndex rows(void) {return _Rows;}
270  inline DenseIndex cols(void) const {return m_cols;}
272  {
273  m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
274  m_cols = nbCols;
275  }
277  {
278  if(size != _Rows*m_cols)
279  {
280  internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
281  if (size)
282  m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
283  else
284  m_data = 0;
286  }
287  m_cols = nbCols;
288  }
289  inline const T *data() const { return m_data; }
290  inline T *data() { return m_data; }
291 };
292 
293 // matrix with dynamic height and fixed width (so that matrix has dynamic size).
294 template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
295 {
298  public:
299  inline DenseStorage() : m_data(0), m_rows(0) {}
301  inline DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows)
303  inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
304  inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
305  inline DenseIndex rows(void) const {return m_rows;}
306  static inline DenseIndex cols(void) {return _Cols;}
308  {
309  m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
310  m_rows = nbRows;
311  }
313  {
314  if(size != m_rows*_Cols)
315  {
316  internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
317  if (size)
318  m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
319  else
320  m_data = 0;
322  }
323  m_rows = nbRows;
324  }
325  inline const T *data() const { return m_data; }
326  inline T *data() { return m_data; }
327 };
328 
329 } // end namespace Eigen
330 
331 #endif // EIGEN_MATRIX_H
DenseStorage(DenseIndex size, DenseIndex, DenseIndex nbCols)
Definition: DenseStorage.h:265
static DenseIndex rows(void)
Definition: DenseStorage.h:122
#define EIGEN_STRONG_INLINE
DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex)
Definition: DenseStorage.h:301
DenseStorage(internal::constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:135
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
DenseStorage(internal::constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:164
internal::plain_array< T, Size, _Options > m_data
Definition: DenseStorage.h:180
DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
Definition: DenseStorage.h:225
void resize(DenseIndex, DenseIndex, DenseIndex nbCols)
Definition: DenseStorage.h:210
DenseStorage(internal::constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:184
DenseStorage(DenseIndex, DenseIndex, DenseIndex)
Definition: DenseStorage.h:136
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
DenseStorage(internal::constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:264
EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex, DenseIndex nbCols)
Definition: DenseStorage.h:276
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
void conservativeResize(DenseIndex size, DenseIndex, DenseIndex nbCols)
Definition: DenseStorage.h:271
DenseStorage(DenseIndex, DenseIndex, DenseIndex nbCols)
Definition: DenseStorage.h:205
T * conditional_aligned_new_auto(size_t size)
void swap(DenseStorage &other)
Definition: DenseStorage.h:121
internal::plain_array< T, Size, _Options > m_data
Definition: DenseStorage.h:199
void conservativeResize(DenseIndex, DenseIndex, DenseIndex)
Definition: DenseStorage.h:140
void conservativeResize(DenseIndex, DenseIndex nbRows, DenseIndex nbCols)
Definition: DenseStorage.h:171
DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex nbCols)
Definition: DenseStorage.h:166
DenseStorage(internal::constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:118
const T * data() const
Definition: DenseStorage.h:126
void resize(DenseIndex, DenseIndex nbRows, DenseIndex)
Definition: DenseStorage.h:191
void resize(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
Definition: DenseStorage.h:239
void resize(DenseIndex, DenseIndex, DenseIndex)
Definition: DenseStorage.h:141
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
Definition: DenseStorage.h:18
plain_array(constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:93
#define EIGEN_USER_ALIGN16
void conservativeResize(DenseIndex, DenseIndex nbRows, DenseIndex)
Definition: DenseStorage.h:190
void conservativeResize(DenseIndex, DenseIndex, DenseIndex)
Definition: DenseStorage.h:124
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
Definition: DenseStorage.h:64
EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex nbRows, DenseIndex)
Definition: DenseStorage.h:312
void resize(DenseIndex, DenseIndex nbRows, DenseIndex nbCols)
Definition: DenseStorage.h:172
static DenseIndex cols(void)
Definition: DenseStorage.h:123
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: XprHelper.h:27
plain_array(constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:44
void resize(DenseIndex, DenseIndex, DenseIndex)
Definition: DenseStorage.h:125
void conservativeResize(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
Definition: DenseStorage.h:233
DenseStorage(internal::constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:300
DenseStorage(internal::constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:203
#define EIGEN_ALWAYS_INLINE
void conservativeResize(DenseIndex, DenseIndex, DenseIndex nbCols)
Definition: DenseStorage.h:209
internal::plain_array< T, Size, _Options > m_data
Definition: DenseStorage.h:159
plain_array(constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:82
DenseStorage(DenseIndex, DenseIndex, DenseIndex)
Definition: DenseStorage.h:120
DenseStorage(internal::constructor_without_unaligned_array_assert)
Definition: DenseStorage.h:223
internal::plain_array< T, Size, _Options > m_data
Definition: DenseStorage.h:115
void conservativeResize(DenseIndex size, DenseIndex nbRows, DenseIndex)
Definition: DenseStorage.h:307
DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex)
Definition: DenseStorage.h:186


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:32