12 #ifndef EIGEN_MATRIXSTORAGE_H
13 #define EIGEN_MATRIXSTORAGE_H
15 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
16 #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
18 #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
25 struct constructor_without_unaligned_array_assert {};
31 template <
typename T,
int Size,
int MatrixOrArrayOptions,
32 int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
33 : (((Size*
sizeof(T))%16)==0) ? 16
39 plain_array(constructor_without_unaligned_array_assert) {}
42 #if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
43 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
44 #elif EIGEN_GNUC_AT_LEAST(4,7)
48 template<
typename PtrType>
49 EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) {
return array; }
50 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
51 eigen_assert((reinterpret_cast<size_t>(eigen_unaligned_array_assert_workaround_gcc47(array)) & sizemask) == 0 \
52 && "this assertion is explained here: " \
53 "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
54 " **** READ THIS WEB PAGE !!! ****");
56 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
57 eigen_assert((reinterpret_cast<size_t>(array) & sizemask) == 0 \
58 && "this assertion is explained here: " \
59 "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
60 " **** READ THIS WEB PAGE !!! ****");
63 template <
typename T,
int Size,
int MatrixOrArrayOptions>
64 struct plain_array<T, Size, MatrixOrArrayOptions, 16>
66 EIGEN_USER_ALIGN16 T array[Size];
67 plain_array() { EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(0xf) }
68 plain_array(constructor_without_unaligned_array_assert) {}
71 template <
typename T,
int MatrixOrArrayOptions,
int Alignment>
72 struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
74 EIGEN_USER_ALIGN16 T array[1];
76 plain_array(constructor_without_unaligned_array_assert) {}
93 template<
typename T,
int Size,
int _Rows,
int _Cols,
int _Options>
class DenseStorage;
96 template<
typename T,
int Size,
int _Rows,
int _Cols,
int _Options>
class DenseStorage
98 internal::plain_array<T,Size,_Options> m_data;
100 inline explicit DenseStorage() {}
101 inline DenseStorage(internal::constructor_without_unaligned_array_assert)
102 : m_data(internal::constructor_without_unaligned_array_assert()) {}
103 inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
104 inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); }
105 static inline DenseIndex rows(
void) {
return _Rows;}
106 static inline DenseIndex cols(
void) {
return _Cols;}
107 inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
108 inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
109 inline const T *data()
const {
return m_data.array; }
110 inline T *data() {
return m_data.array; }
114 template<
typename T,
int _Rows,
int _Cols,
int _Options>
class DenseStorage<T, 0, _Rows, _Cols, _Options>
117 inline explicit DenseStorage() {}
118 inline DenseStorage(internal::constructor_without_unaligned_array_assert) {}
119 inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
120 inline void swap(DenseStorage& ) {}
121 static inline DenseIndex rows(
void) {
return _Rows;}
122 static inline DenseIndex cols(
void) {
return _Cols;}
123 inline void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
124 inline void resize(DenseIndex,DenseIndex,DenseIndex) {}
125 inline const T *data()
const {
return 0; }
126 inline T *data() {
return 0; }
130 template<
typename T,
int _Options>
class DenseStorage<T, 0, Dynamic, Dynamic, _Options>
131 :
public DenseStorage<T, 0, 0, 0, _Options> { };
133 template<
typename T,
int _Rows,
int _Options>
class DenseStorage<T, 0, _Rows, Dynamic, _Options>
134 :
public DenseStorage<T, 0, 0, 0, _Options> { };
136 template<
typename T,
int _Cols,
int _Options>
class DenseStorage<T, 0, Dynamic, _Cols, _Options>
137 :
public DenseStorage<T, 0, 0, 0, _Options> { };
140 template<
typename T,
int Size,
int _Options>
class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
142 internal::plain_array<T,Size,_Options> m_data;
146 inline explicit DenseStorage() : m_rows(0), m_cols(0) {}
147 inline DenseStorage(internal::constructor_without_unaligned_array_assert)
148 : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
149 inline DenseStorage(DenseIndex, DenseIndex rows, DenseIndex cols) : m_rows(rows), m_cols(cols) {}
150 inline void swap(DenseStorage& other)
151 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
152 inline DenseIndex rows(
void)
const {
return m_rows;}
153 inline DenseIndex cols(
void)
const {
return m_cols;}
154 inline void conservativeResize(DenseIndex, DenseIndex rows, DenseIndex cols) { m_rows = rows; m_cols = cols; }
155 inline void resize(DenseIndex, DenseIndex rows, DenseIndex cols) { m_rows = rows; m_cols = cols; }
156 inline const T *data()
const {
return m_data.array; }
157 inline T *data() {
return m_data.array; }
161 template<
typename T,
int Size,
int _Cols,
int _Options>
class DenseStorage<T, Size, Dynamic, _Cols, _Options>
163 internal::plain_array<T,Size,_Options> m_data;
166 inline explicit DenseStorage() : m_rows(0) {}
167 inline DenseStorage(internal::constructor_without_unaligned_array_assert)
168 : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
169 inline DenseStorage(DenseIndex, DenseIndex rows, DenseIndex) : m_rows(rows) {}
170 inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
171 inline DenseIndex rows(
void)
const {
return m_rows;}
172 inline DenseIndex cols(
void)
const {
return _Cols;}
173 inline void conservativeResize(DenseIndex, DenseIndex rows, DenseIndex) { m_rows = rows; }
174 inline void resize(DenseIndex, DenseIndex rows, DenseIndex) { m_rows = rows; }
175 inline const T *data()
const {
return m_data.array; }
176 inline T *data() {
return m_data.array; }
180 template<
typename T,
int Size,
int _Rows,
int _Options>
class DenseStorage<T, Size, _Rows, Dynamic, _Options>
182 internal::plain_array<T,Size,_Options> m_data;
185 inline explicit DenseStorage() : m_cols(0) {}
186 inline DenseStorage(internal::constructor_without_unaligned_array_assert)
187 : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
188 inline DenseStorage(DenseIndex, DenseIndex, DenseIndex cols) : m_cols(cols) {}
189 inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
190 inline DenseIndex rows(
void)
const {
return _Rows;}
191 inline DenseIndex cols(
void)
const {
return m_cols;}
192 inline void conservativeResize(DenseIndex, DenseIndex, DenseIndex cols) { m_cols = cols; }
193 inline void resize(DenseIndex, DenseIndex, DenseIndex cols) { m_cols = cols; }
194 inline const T *data()
const {
return m_data.array; }
195 inline T *data() {
return m_data.array; }
199 template<
typename T,
int _Options>
class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
205 inline explicit DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
206 inline DenseStorage(internal::constructor_without_unaligned_array_assert)
207 : m_data(0), m_rows(0), m_cols(0) {}
208 inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex cols)
209 : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
210 { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
211 inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
212 inline void swap(DenseStorage& other)
213 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
214 inline DenseIndex rows(
void)
const {
return m_rows;}
215 inline DenseIndex cols(
void)
const {
return m_cols;}
216 inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex cols)
218 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
222 void resize(DenseIndex size, DenseIndex rows, DenseIndex cols)
224 if(size != m_rows*m_cols)
226 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
228 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
231 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
236 inline const T *data()
const {
return m_data; }
237 inline T *data() {
return m_data; }
241 template<
typename T,
int _Rows,
int _Options>
class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
246 inline explicit DenseStorage() : m_data(0), m_cols(0) {}
247 inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
248 inline DenseStorage(DenseIndex size, DenseIndex, DenseIndex cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(cols)
249 { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
250 inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
251 inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
252 static inline DenseIndex rows(
void) {
return _Rows;}
253 inline DenseIndex cols(
void)
const {
return m_cols;}
254 inline void conservativeResize(DenseIndex size, DenseIndex, DenseIndex cols)
256 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
259 EIGEN_STRONG_INLINE
void resize(DenseIndex size, DenseIndex, DenseIndex cols)
261 if(size != _Rows*m_cols)
263 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
265 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
268 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
272 inline const T *data()
const {
return m_data; }
273 inline T *data() {
return m_data; }
277 template<
typename T,
int _Cols,
int _Options>
class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
282 inline explicit DenseStorage() : m_data(0), m_rows(0) {}
283 inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
284 inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows)
285 { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
286 inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
287 inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
288 inline DenseIndex rows(
void)
const {
return m_rows;}
289 static inline DenseIndex cols(
void) {
return _Cols;}
290 inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex)
292 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
295 EIGEN_STRONG_INLINE
void resize(DenseIndex size, DenseIndex rows, DenseIndex)
297 if(size != m_rows*_Cols)
299 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
301 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
304 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
308 inline const T *data()
const {
return m_data; }
309 inline T *data() {
return m_data; }
314 #endif // EIGEN_MATRIX_H