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 // Eigen is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Lesser General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 3 of the License, or (at your option) any later version.
00012 //
00013 // Alternatively, you can redistribute it and/or
00014 // modify it under the terms of the GNU General Public License as
00015 // published by the Free Software Foundation; either version 2 of
00016 // the License, or (at your option) any later version.
00017 //
00018 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00019 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00020 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00021 // GNU General Public License for more details.
00022 //
00023 // You should have received a copy of the GNU Lesser General Public
00024 // License and a copy of the GNU General Public License along with
00025 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 #ifndef EIGEN_MATRIXSTORAGE_H
00028 #define EIGEN_MATRIXSTORAGE_H
00029 
00030 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
00031   #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
00032 #else
00033   #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00034 #endif
00035 
00036 namespace internal {
00037 
00038 struct constructor_without_unaligned_array_assert {};
00039 
00044 template <typename T, int Size, int MatrixOrArrayOptions,
00045           int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
00046                         : (((Size*sizeof(T))%16)==0) ? 16
00047                         : 0 >
00048 struct plain_array
00049 {
00050   T array[Size];
00051   plain_array() {}
00052   plain_array(constructor_without_unaligned_array_assert) {}
00053 };
00054 
00055 #ifdef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00056   #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
00057 #else
00058   #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
00059     eigen_assert((reinterpret_cast<size_t>(array) & sizemask) == 0 \
00060               && "this assertion is explained here: " \
00061               "http://eigen.tuxfamily.org/dox-devel/TopicUnalignedArrayAssert.html" \
00062               " **** READ THIS WEB PAGE !!! ****");
00063 #endif
00064 
00065 template <typename T, int Size, int MatrixOrArrayOptions>
00066 struct plain_array<T, Size, MatrixOrArrayOptions, 16>
00067 {
00068   EIGEN_USER_ALIGN16 T array[Size];
00069   plain_array() { EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(0xf) }
00070   plain_array(constructor_without_unaligned_array_assert) {}
00071 };
00072 
00073 template <typename T, int MatrixOrArrayOptions, int Alignment>
00074 struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
00075 {
00076   EIGEN_USER_ALIGN16 T array[1];
00077   plain_array() {}
00078   plain_array(constructor_without_unaligned_array_assert) {}
00079 };
00080 
00081 } // end namespace internal
00082 
00095 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage;
00096 
00097 // purely fixed-size matrix
00098 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage
00099 {
00100     internal::plain_array<T,Size,_Options> m_data;
00101   public:
00102     inline explicit DenseStorage() {}
00103     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00104       : m_data(internal::constructor_without_unaligned_array_assert()) {}
00105     inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
00106     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); }
00107     inline static DenseIndex rows(void) {return _Rows;}
00108     inline static DenseIndex cols(void) {return _Cols;}
00109     inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
00110     inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
00111     inline const T *data() const { return m_data.array; }
00112     inline T *data() { return m_data.array; }
00113 };
00114 
00115 // null matrix
00116 template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options>
00117 {
00118   public:
00119     inline explicit DenseStorage() {}
00120     inline DenseStorage(internal::constructor_without_unaligned_array_assert) {}
00121     inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
00122     inline void swap(DenseStorage& ) {}
00123     inline static DenseIndex rows(void) {return _Rows;}
00124     inline static DenseIndex cols(void) {return _Cols;}
00125     inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
00126     inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
00127     inline const T *data() const { return 0; }
00128     inline T *data() { return 0; }
00129 };
00130 
00131 // dynamic-size matrix with fixed-size storage
00132 template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
00133 {
00134     internal::plain_array<T,Size,_Options> m_data;
00135     DenseIndex m_rows;
00136     DenseIndex m_cols;
00137   public:
00138     inline explicit DenseStorage() : m_rows(0), m_cols(0) {}
00139     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00140       : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
00141     inline DenseStorage(DenseIndex, DenseIndex rows, DenseIndex cols) : m_rows(rows), m_cols(cols) {}
00142     inline void swap(DenseStorage& other)
00143     { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00144     inline DenseIndex rows(void) const {return m_rows;}
00145     inline DenseIndex cols(void) const {return m_cols;}
00146     inline void conservativeResize(DenseIndex, DenseIndex rows, DenseIndex cols) { m_rows = rows; m_cols = cols; }
00147     inline void resize(DenseIndex, DenseIndex rows, DenseIndex cols) { m_rows = rows; m_cols = cols; }
00148     inline const T *data() const { return m_data.array; }
00149     inline T *data() { return m_data.array; }
00150 };
00151 
00152 // dynamic-size matrix with fixed-size storage and fixed width
00153 template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options>
00154 {
00155     internal::plain_array<T,Size,_Options> m_data;
00156     DenseIndex m_rows;
00157   public:
00158     inline explicit DenseStorage() : m_rows(0) {}
00159     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00160       : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
00161     inline DenseStorage(DenseIndex, DenseIndex rows, DenseIndex) : m_rows(rows) {}
00162     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00163     inline DenseIndex rows(void) const {return m_rows;}
00164     inline DenseIndex cols(void) const {return _Cols;}
00165     inline void conservativeResize(DenseIndex, DenseIndex rows, DenseIndex) { m_rows = rows; }
00166     inline void resize(DenseIndex, DenseIndex rows, DenseIndex) { m_rows = rows; }
00167     inline const T *data() const { return m_data.array; }
00168     inline T *data() { return m_data.array; }
00169 };
00170 
00171 // dynamic-size matrix with fixed-size storage and fixed height
00172 template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options>
00173 {
00174     internal::plain_array<T,Size,_Options> m_data;
00175     DenseIndex m_cols;
00176   public:
00177     inline explicit DenseStorage() : m_cols(0) {}
00178     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00179       : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
00180     inline DenseStorage(DenseIndex, DenseIndex, DenseIndex cols) : m_cols(cols) {}
00181     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00182     inline DenseIndex rows(void) const {return _Rows;}
00183     inline DenseIndex cols(void) const {return m_cols;}
00184     inline void conservativeResize(DenseIndex, DenseIndex, DenseIndex cols) { m_cols = cols; }
00185     inline void resize(DenseIndex, DenseIndex, DenseIndex cols) { m_cols = cols; }
00186     inline const T *data() const { return m_data.array; }
00187     inline T *data() { return m_data.array; }
00188 };
00189 
00190 // purely dynamic matrix.
00191 template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
00192 {
00193     T *m_data;
00194     DenseIndex m_rows;
00195     DenseIndex m_cols;
00196   public:
00197     inline explicit DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
00198     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00199        : m_data(0), m_rows(0), m_cols(0) {}
00200     inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex cols)
00201       : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols) 
00202     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00203     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
00204     inline void swap(DenseStorage& other)
00205     { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00206     inline DenseIndex rows(void) const {return m_rows;}
00207     inline DenseIndex cols(void) const {return m_cols;}
00208     inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex cols)
00209     {
00210       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
00211       m_rows = rows;
00212       m_cols = cols;
00213     }
00214     void resize(DenseIndex size, DenseIndex rows, DenseIndex cols)
00215     {
00216       if(size != m_rows*m_cols)
00217       {
00218         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
00219         if (size)
00220           m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
00221         else
00222           m_data = 0;
00223         EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00224       }
00225       m_rows = rows;
00226       m_cols = cols;
00227     }
00228     inline const T *data() const { return m_data; }
00229     inline T *data() { return m_data; }
00230 };
00231 
00232 // matrix with dynamic width and fixed height (so that matrix has dynamic size).
00233 template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
00234 {
00235     T *m_data;
00236     DenseIndex m_cols;
00237   public:
00238     inline explicit DenseStorage() : m_data(0), m_cols(0) {}
00239     inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
00240     inline DenseStorage(DenseIndex size, DenseIndex, DenseIndex cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(cols)
00241     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00242     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
00243     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00244     inline static DenseIndex rows(void) {return _Rows;}
00245     inline DenseIndex cols(void) const {return m_cols;}
00246     inline void conservativeResize(DenseIndex size, DenseIndex, DenseIndex cols)
00247     {
00248       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
00249       m_cols = cols;
00250     }
00251     EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex, DenseIndex cols)
00252     {
00253       if(size != _Rows*m_cols)
00254       {
00255         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
00256         if (size)
00257           m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
00258         else
00259           m_data = 0;
00260         EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00261       }
00262       m_cols = cols;
00263     }
00264     inline const T *data() const { return m_data; }
00265     inline T *data() { return m_data; }
00266 };
00267 
00268 // matrix with dynamic height and fixed width (so that matrix has dynamic size).
00269 template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
00270 {
00271     T *m_data;
00272     DenseIndex m_rows;
00273   public:
00274     inline explicit DenseStorage() : m_data(0), m_rows(0) {}
00275     inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
00276     inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows)
00277     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00278     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
00279     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00280     inline DenseIndex rows(void) const {return m_rows;}
00281     inline static DenseIndex cols(void) {return _Cols;}
00282     inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex)
00283     {
00284       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
00285       m_rows = rows;
00286     }
00287     EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex rows, DenseIndex)
00288     {
00289       if(size != m_rows*_Cols)
00290       {
00291         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
00292         if (size)
00293           m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
00294         else
00295           m_data = 0;
00296         EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00297       }
00298       m_rows = rows;
00299     }
00300     inline const T *data() const { return m_data; }
00301     inline T *data() { return m_data; }
00302 };
00303 
00304 #endif // EIGEN_MATRIX_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:37