DenseStorage.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 // Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
00007 //
00008 // This Source Code Form is subject to the terms of the Mozilla
00009 // Public License v. 2.0. If a copy of the MPL was not distributed
00010 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00011 
00012 #ifndef EIGEN_MATRIXSTORAGE_H
00013 #define EIGEN_MATRIXSTORAGE_H
00014 
00015 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
00016   #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
00017 #else
00018   #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00019 #endif
00020 
00021 namespace Eigen {
00022 
00023 namespace internal {
00024 
00025 struct constructor_without_unaligned_array_assert {};
00026 
00027 template<typename T, int Size> void check_static_allocation_size()
00028 {
00029   // if EIGEN_STACK_ALLOCATION_LIMIT is defined to 0, then no limit
00030   #if EIGEN_STACK_ALLOCATION_LIMIT
00031   EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
00032   #endif
00033 }
00034 
00039 template <typename T, int Size, int MatrixOrArrayOptions,
00040           int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
00041                         : (((Size*sizeof(T))%16)==0) ? 16
00042                         : 0 >
00043 struct plain_array
00044 {
00045   T array[Size];
00046 
00047   plain_array() 
00048   { 
00049     check_static_allocation_size<T,Size>();
00050   }
00051 
00052   plain_array(constructor_without_unaligned_array_assert) 
00053   { 
00054     check_static_allocation_size<T,Size>();
00055   }
00056 };
00057 
00058 #if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
00059   #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
00060 #elif EIGEN_GNUC_AT_LEAST(4,7) 
00061   // 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.
00062   // See this bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900
00063   // Hiding the origin of the array pointer behind a function argument seems to do the trick even if the function is inlined:
00064   template<typename PtrType>
00065   EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) { return array; }
00066   #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
00067     eigen_assert((reinterpret_cast<size_t>(eigen_unaligned_array_assert_workaround_gcc47(array)) & sizemask) == 0 \
00068               && "this assertion is explained here: " \
00069               "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
00070               " **** READ THIS WEB PAGE !!! ****");
00071 #else
00072   #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
00073     eigen_assert((reinterpret_cast<size_t>(array) & sizemask) == 0 \
00074               && "this assertion is explained here: " \
00075               "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
00076               " **** READ THIS WEB PAGE !!! ****");
00077 #endif
00078 
00079 template <typename T, int Size, int MatrixOrArrayOptions>
00080 struct plain_array<T, Size, MatrixOrArrayOptions, 16>
00081 {
00082   EIGEN_USER_ALIGN16 T array[Size];
00083 
00084   plain_array() 
00085   { 
00086     EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(0xf);
00087     check_static_allocation_size<T,Size>();
00088   }
00089 
00090   plain_array(constructor_without_unaligned_array_assert) 
00091   { 
00092     check_static_allocation_size<T,Size>();
00093   }
00094 };
00095 
00096 template <typename T, int MatrixOrArrayOptions, int Alignment>
00097 struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
00098 {
00099   EIGEN_USER_ALIGN16 T array[1];
00100   plain_array() {}
00101   plain_array(constructor_without_unaligned_array_assert) {}
00102 };
00103 
00104 } // end namespace internal
00105 
00118 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage;
00119 
00120 // purely fixed-size matrix
00121 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage
00122 {
00123     internal::plain_array<T,Size,_Options> m_data;
00124   public:
00125     inline DenseStorage() {}
00126     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00127       : m_data(internal::constructor_without_unaligned_array_assert()) {}
00128     inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
00129     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); }
00130     static inline DenseIndex rows(void) {return _Rows;}
00131     static inline DenseIndex cols(void) {return _Cols;}
00132     inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
00133     inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
00134     inline const T *data() const { return m_data.array; }
00135     inline T *data() { return m_data.array; }
00136 };
00137 
00138 // null matrix
00139 template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options>
00140 {
00141   public:
00142     inline DenseStorage() {}
00143     inline DenseStorage(internal::constructor_without_unaligned_array_assert) {}
00144     inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
00145     inline void swap(DenseStorage& ) {}
00146     static inline DenseIndex rows(void) {return _Rows;}
00147     static inline DenseIndex cols(void) {return _Cols;}
00148     inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
00149     inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
00150     inline const T *data() const { return 0; }
00151     inline T *data() { return 0; }
00152 };
00153 
00154 // more specializations for null matrices; these are necessary to resolve ambiguities
00155 template<typename T, int _Options> class DenseStorage<T, 0, Dynamic, Dynamic, _Options>
00156 : public DenseStorage<T, 0, 0, 0, _Options> { };
00157 
00158 template<typename T, int _Rows, int _Options> class DenseStorage<T, 0, _Rows, Dynamic, _Options>
00159 : public DenseStorage<T, 0, 0, 0, _Options> { };
00160 
00161 template<typename T, int _Cols, int _Options> class DenseStorage<T, 0, Dynamic, _Cols, _Options>
00162 : public DenseStorage<T, 0, 0, 0, _Options> { };
00163 
00164 // dynamic-size matrix with fixed-size storage
00165 template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
00166 {
00167     internal::plain_array<T,Size,_Options> m_data;
00168     DenseIndex m_rows;
00169     DenseIndex m_cols;
00170   public:
00171     inline DenseStorage() : m_rows(0), m_cols(0) {}
00172     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00173       : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
00174     inline DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) : m_rows(nbRows), m_cols(nbCols) {}
00175     inline void swap(DenseStorage& other)
00176     { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00177     inline DenseIndex rows() const {return m_rows;}
00178     inline DenseIndex cols() const {return m_cols;}
00179     inline void conservativeResize(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) { m_rows = nbRows; m_cols = nbCols; }
00180     inline void resize(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) { m_rows = nbRows; m_cols = nbCols; }
00181     inline const T *data() const { return m_data.array; }
00182     inline T *data() { return m_data.array; }
00183 };
00184 
00185 // dynamic-size matrix with fixed-size storage and fixed width
00186 template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options>
00187 {
00188     internal::plain_array<T,Size,_Options> m_data;
00189     DenseIndex m_rows;
00190   public:
00191     inline DenseStorage() : m_rows(0) {}
00192     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00193       : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
00194     inline DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex) : m_rows(nbRows) {}
00195     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00196     inline DenseIndex rows(void) const {return m_rows;}
00197     inline DenseIndex cols(void) const {return _Cols;}
00198     inline void conservativeResize(DenseIndex, DenseIndex nbRows, DenseIndex) { m_rows = nbRows; }
00199     inline void resize(DenseIndex, DenseIndex nbRows, DenseIndex) { m_rows = nbRows; }
00200     inline const T *data() const { return m_data.array; }
00201     inline T *data() { return m_data.array; }
00202 };
00203 
00204 // dynamic-size matrix with fixed-size storage and fixed height
00205 template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options>
00206 {
00207     internal::plain_array<T,Size,_Options> m_data;
00208     DenseIndex m_cols;
00209   public:
00210     inline DenseStorage() : m_cols(0) {}
00211     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00212       : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
00213     inline DenseStorage(DenseIndex, DenseIndex, DenseIndex nbCols) : m_cols(nbCols) {}
00214     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00215     inline DenseIndex rows(void) const {return _Rows;}
00216     inline DenseIndex cols(void) const {return m_cols;}
00217     inline void conservativeResize(DenseIndex, DenseIndex, DenseIndex nbCols) { m_cols = nbCols; }
00218     inline void resize(DenseIndex, DenseIndex, DenseIndex nbCols) { m_cols = nbCols; }
00219     inline const T *data() const { return m_data.array; }
00220     inline T *data() { return m_data.array; }
00221 };
00222 
00223 // purely dynamic matrix.
00224 template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
00225 {
00226     T *m_data;
00227     DenseIndex m_rows;
00228     DenseIndex m_cols;
00229   public:
00230     inline DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
00231     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00232        : m_data(0), m_rows(0), m_cols(0) {}
00233     inline DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
00234       : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows), m_cols(nbCols)
00235     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00236     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
00237     inline void swap(DenseStorage& other)
00238     { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00239     inline DenseIndex rows(void) const {return m_rows;}
00240     inline DenseIndex cols(void) const {return m_cols;}
00241     inline void conservativeResize(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
00242     {
00243       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
00244       m_rows = nbRows;
00245       m_cols = nbCols;
00246     }
00247     void resize(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
00248     {
00249       if(size != m_rows*m_cols)
00250       {
00251         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
00252         if (size)
00253           m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
00254         else
00255           m_data = 0;
00256         EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00257       }
00258       m_rows = nbRows;
00259       m_cols = nbCols;
00260     }
00261     inline const T *data() const { return m_data; }
00262     inline T *data() { return m_data; }
00263 };
00264 
00265 // matrix with dynamic width and fixed height (so that matrix has dynamic size).
00266 template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
00267 {
00268     T *m_data;
00269     DenseIndex m_cols;
00270   public:
00271     inline DenseStorage() : m_data(0), m_cols(0) {}
00272     inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
00273     inline DenseStorage(DenseIndex size, DenseIndex, DenseIndex nbCols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(nbCols)
00274     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00275     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
00276     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00277     static inline DenseIndex rows(void) {return _Rows;}
00278     inline DenseIndex cols(void) const {return m_cols;}
00279     inline void conservativeResize(DenseIndex size, DenseIndex, DenseIndex nbCols)
00280     {
00281       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
00282       m_cols = nbCols;
00283     }
00284     EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex, DenseIndex nbCols)
00285     {
00286       if(size != _Rows*m_cols)
00287       {
00288         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
00289         if (size)
00290           m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
00291         else
00292           m_data = 0;
00293         EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00294       }
00295       m_cols = nbCols;
00296     }
00297     inline const T *data() const { return m_data; }
00298     inline T *data() { return m_data; }
00299 };
00300 
00301 // matrix with dynamic height and fixed width (so that matrix has dynamic size).
00302 template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
00303 {
00304     T *m_data;
00305     DenseIndex m_rows;
00306   public:
00307     inline DenseStorage() : m_data(0), m_rows(0) {}
00308     inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
00309     inline DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows)
00310     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00311     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
00312     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00313     inline DenseIndex rows(void) const {return m_rows;}
00314     static inline DenseIndex cols(void) {return _Cols;}
00315     inline void conservativeResize(DenseIndex size, DenseIndex nbRows, DenseIndex)
00316     {
00317       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
00318       m_rows = nbRows;
00319     }
00320     EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex nbRows, DenseIndex)
00321     {
00322       if(size != m_rows*_Cols)
00323       {
00324         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
00325         if (size)
00326           m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
00327         else
00328           m_data = 0;
00329         EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00330       }
00331       m_rows = nbRows;
00332     }
00333     inline const T *data() const { return m_data; }
00334     inline T *data() { return m_data; }
00335 };
00336 
00337 } // end namespace Eigen
00338 
00339 #endif // EIGEN_MATRIX_H


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 20:58:00