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 
00031 template <typename T, int Size, int MatrixOrArrayOptions,
00032           int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
00033                         : (((Size*sizeof(T))%16)==0) ? 16
00034                         : 0 >
00035 struct plain_array
00036 {
00037   T array[Size];
00038   plain_array() {}
00039   plain_array(constructor_without_unaligned_array_assert) {}
00040 };
00041 
00042 #ifdef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00043   #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
00044 #else
00045   #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
00046     eigen_assert((reinterpret_cast<size_t>(array) & sizemask) == 0 \
00047               && "this assertion is explained here: " \
00048               "http://eigen.tuxfamily.org/dox-devel/TopicUnalignedArrayAssert.html" \
00049               " **** READ THIS WEB PAGE !!! ****");
00050 #endif
00051 
00052 template <typename T, int Size, int MatrixOrArrayOptions>
00053 struct plain_array<T, Size, MatrixOrArrayOptions, 16>
00054 {
00055   EIGEN_USER_ALIGN16 T array[Size];
00056   plain_array() { EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(0xf) }
00057   plain_array(constructor_without_unaligned_array_assert) {}
00058 };
00059 
00060 template <typename T, int MatrixOrArrayOptions, int Alignment>
00061 struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
00062 {
00063   EIGEN_USER_ALIGN16 T array[1];
00064   plain_array() {}
00065   plain_array(constructor_without_unaligned_array_assert) {}
00066 };
00067 
00068 } // end namespace internal
00069 
00082 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage;
00083 
00084 // purely fixed-size matrix
00085 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage
00086 {
00087     internal::plain_array<T,Size,_Options> m_data;
00088   public:
00089     inline explicit DenseStorage() {}
00090     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00091       : m_data(internal::constructor_without_unaligned_array_assert()) {}
00092     inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
00093     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); }
00094     static inline DenseIndex rows(void) {return _Rows;}
00095     static inline DenseIndex cols(void) {return _Cols;}
00096     inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
00097     inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
00098     inline const T *data() const { return m_data.array; }
00099     inline T *data() { return m_data.array; }
00100 };
00101 
00102 // null matrix
00103 template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options>
00104 {
00105   public:
00106     inline explicit DenseStorage() {}
00107     inline DenseStorage(internal::constructor_without_unaligned_array_assert) {}
00108     inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
00109     inline void swap(DenseStorage& ) {}
00110     static inline DenseIndex rows(void) {return _Rows;}
00111     static inline DenseIndex cols(void) {return _Cols;}
00112     inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
00113     inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
00114     inline const T *data() const { return 0; }
00115     inline T *data() { return 0; }
00116 };
00117 
00118 // more specializations for null matrices; these are necessary to resolve ambiguities
00119 template<typename T, int _Options> class DenseStorage<T, 0, Dynamic, Dynamic, _Options>
00120 : public DenseStorage<T, 0, 0, 0, _Options> { };
00121 
00122 template<typename T, int _Rows, int _Options> class DenseStorage<T, 0, _Rows, Dynamic, _Options>
00123 : public DenseStorage<T, 0, 0, 0, _Options> { };
00124 
00125 template<typename T, int _Cols, int _Options> class DenseStorage<T, 0, Dynamic, _Cols, _Options>
00126 : public DenseStorage<T, 0, 0, 0, _Options> { };
00127 
00128 // dynamic-size matrix with fixed-size storage
00129 template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
00130 {
00131     internal::plain_array<T,Size,_Options> m_data;
00132     DenseIndex m_rows;
00133     DenseIndex m_cols;
00134   public:
00135     inline explicit DenseStorage() : m_rows(0), m_cols(0) {}
00136     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00137       : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
00138     inline DenseStorage(DenseIndex, DenseIndex rows, DenseIndex cols) : m_rows(rows), m_cols(cols) {}
00139     inline void swap(DenseStorage& other)
00140     { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00141     inline DenseIndex rows(void) const {return m_rows;}
00142     inline DenseIndex cols(void) const {return m_cols;}
00143     inline void conservativeResize(DenseIndex, DenseIndex rows, DenseIndex cols) { m_rows = rows; m_cols = cols; }
00144     inline void resize(DenseIndex, DenseIndex rows, DenseIndex cols) { m_rows = rows; m_cols = cols; }
00145     inline const T *data() const { return m_data.array; }
00146     inline T *data() { return m_data.array; }
00147 };
00148 
00149 // dynamic-size matrix with fixed-size storage and fixed width
00150 template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options>
00151 {
00152     internal::plain_array<T,Size,_Options> m_data;
00153     DenseIndex m_rows;
00154   public:
00155     inline explicit DenseStorage() : m_rows(0) {}
00156     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00157       : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
00158     inline DenseStorage(DenseIndex, DenseIndex rows, DenseIndex) : m_rows(rows) {}
00159     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00160     inline DenseIndex rows(void) const {return m_rows;}
00161     inline DenseIndex cols(void) const {return _Cols;}
00162     inline void conservativeResize(DenseIndex, DenseIndex rows, DenseIndex) { m_rows = rows; }
00163     inline void resize(DenseIndex, DenseIndex rows, DenseIndex) { m_rows = rows; }
00164     inline const T *data() const { return m_data.array; }
00165     inline T *data() { return m_data.array; }
00166 };
00167 
00168 // dynamic-size matrix with fixed-size storage and fixed height
00169 template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options>
00170 {
00171     internal::plain_array<T,Size,_Options> m_data;
00172     DenseIndex m_cols;
00173   public:
00174     inline explicit DenseStorage() : m_cols(0) {}
00175     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00176       : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
00177     inline DenseStorage(DenseIndex, DenseIndex, DenseIndex cols) : m_cols(cols) {}
00178     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00179     inline DenseIndex rows(void) const {return _Rows;}
00180     inline DenseIndex cols(void) const {return m_cols;}
00181     inline void conservativeResize(DenseIndex, DenseIndex, DenseIndex cols) { m_cols = cols; }
00182     inline void resize(DenseIndex, DenseIndex, DenseIndex cols) { m_cols = cols; }
00183     inline const T *data() const { return m_data.array; }
00184     inline T *data() { return m_data.array; }
00185 };
00186 
00187 // purely dynamic matrix.
00188 template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
00189 {
00190     T *m_data;
00191     DenseIndex m_rows;
00192     DenseIndex m_cols;
00193   public:
00194     inline explicit DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
00195     inline DenseStorage(internal::constructor_without_unaligned_array_assert)
00196        : m_data(0), m_rows(0), m_cols(0) {}
00197     inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex cols)
00198       : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols) 
00199     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00200     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
00201     inline void swap(DenseStorage& other)
00202     { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
00203     inline DenseIndex rows(void) const {return m_rows;}
00204     inline DenseIndex cols(void) const {return m_cols;}
00205     inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex cols)
00206     {
00207       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
00208       m_rows = rows;
00209       m_cols = cols;
00210     }
00211     void resize(DenseIndex size, DenseIndex rows, DenseIndex cols)
00212     {
00213       if(size != m_rows*m_cols)
00214       {
00215         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
00216         if (size)
00217           m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
00218         else
00219           m_data = 0;
00220         EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00221       }
00222       m_rows = rows;
00223       m_cols = cols;
00224     }
00225     inline const T *data() const { return m_data; }
00226     inline T *data() { return m_data; }
00227 };
00228 
00229 // matrix with dynamic width and fixed height (so that matrix has dynamic size).
00230 template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
00231 {
00232     T *m_data;
00233     DenseIndex m_cols;
00234   public:
00235     inline explicit DenseStorage() : m_data(0), m_cols(0) {}
00236     inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
00237     inline DenseStorage(DenseIndex size, DenseIndex, DenseIndex cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(cols)
00238     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00239     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
00240     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
00241     static inline DenseIndex rows(void) {return _Rows;}
00242     inline DenseIndex cols(void) const {return m_cols;}
00243     inline void conservativeResize(DenseIndex size, DenseIndex, DenseIndex cols)
00244     {
00245       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
00246       m_cols = cols;
00247     }
00248     EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex, DenseIndex cols)
00249     {
00250       if(size != _Rows*m_cols)
00251       {
00252         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
00253         if (size)
00254           m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
00255         else
00256           m_data = 0;
00257         EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
00258       }
00259       m_cols = cols;
00260     }
00261     inline const T *data() const { return m_data; }
00262     inline T *data() { return m_data; }
00263 };
00264 
00265 // matrix with dynamic height and fixed width (so that matrix has dynamic size).
00266 template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
00267 {
00268     T *m_data;
00269     DenseIndex m_rows;
00270   public:
00271     inline explicit DenseStorage() : m_data(0), m_rows(0) {}
00272     inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
00273     inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows)
00274     { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
00275     inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
00276     inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
00277     inline DenseIndex rows(void) const {return m_rows;}
00278     static inline DenseIndex cols(void) {return _Cols;}
00279     inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex)
00280     {
00281       m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
00282       m_rows = rows;
00283     }
00284     EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex rows, DenseIndex)
00285     {
00286       if(size != m_rows*_Cols)
00287       {
00288         internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
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_rows = rows;
00296     }
00297     inline const T *data() const { return m_data; }
00298     inline T *data() { return m_data; }
00299 };
00300 
00301 } // end namespace Eigen
00302 
00303 #endif // EIGEN_MATRIX_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:24:22