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(X) X; EIGEN_DENSE_STORAGE_CTOR_PLUGIN; 18 #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) 25 struct constructor_without_unaligned_array_assert {};
27 template<
typename T,
int Size>
29 void check_static_allocation_size()
32 #if EIGEN_STACK_ALLOCATION_LIMIT 33 EIGEN_STATIC_ASSERT(Size *
sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
41 template <
typename T,
int Size,
int MatrixOrArrayOptions,
42 int Alignment = (MatrixOrArrayOptions&
DontAlign) ? 0
43 : compute_default_alignment<T,Size>::value >
51 check_static_allocation_size<T,Size>();
55 plain_array(constructor_without_unaligned_array_assert)
57 check_static_allocation_size<T,Size>();
61 #if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT) 62 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) 63 #elif EIGEN_GNUC_AT_LEAST(4,7) 67 template<
typename PtrType>
68 EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) {
return array; }
69 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \ 70 eigen_assert((internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (sizemask)) == 0 \ 71 && "this assertion is explained here: " \ 72 "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \ 73 " **** READ THIS WEB PAGE !!! ****"); 75 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \ 76 eigen_assert((internal::UIntPtr(array) & (sizemask)) == 0 \ 77 && "this assertion is explained here: " \ 78 "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \ 79 " **** READ THIS WEB PAGE !!! ****"); 82 template <
typename T,
int Size,
int MatrixOrArrayOptions>
83 struct plain_array<T, Size, MatrixOrArrayOptions, 8>
85 EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size];
90 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7);
91 check_static_allocation_size<T,Size>();
95 plain_array(constructor_without_unaligned_array_assert)
97 check_static_allocation_size<T,Size>();
101 template <
typename T,
int Size,
int MatrixOrArrayOptions>
102 struct plain_array<T, Size, MatrixOrArrayOptions, 16>
104 EIGEN_ALIGN_TO_BOUNDARY(16) T array[Size];
109 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15);
110 check_static_allocation_size<T,Size>();
114 plain_array(constructor_without_unaligned_array_assert)
116 check_static_allocation_size<T,Size>();
120 template <
typename T,
int Size,
int MatrixOrArrayOptions>
121 struct plain_array<T, Size, MatrixOrArrayOptions, 32>
123 EIGEN_ALIGN_TO_BOUNDARY(32) T array[Size];
128 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31);
129 check_static_allocation_size<T,Size>();
133 plain_array(constructor_without_unaligned_array_assert)
135 check_static_allocation_size<T,Size>();
139 template <
typename T,
int Size,
int MatrixOrArrayOptions>
140 struct plain_array<T, Size, MatrixOrArrayOptions, 64>
142 EIGEN_ALIGN_TO_BOUNDARY(64) T array[Size];
147 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(63);
148 check_static_allocation_size<T,Size>();
152 plain_array(constructor_without_unaligned_array_assert)
154 check_static_allocation_size<T,Size>();
158 template <
typename T,
int MatrixOrArrayOptions,
int Alignment>
159 struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
162 EIGEN_DEVICE_FUNC plain_array() {}
163 EIGEN_DEVICE_FUNC plain_array(constructor_without_unaligned_array_assert) {}
180 template<
typename T,
int Size,
int _Rows,
int _Cols,
int _Options>
class DenseStorage;
183 template<
typename T,
int Size,
int _Rows,
int _Cols,
int _Options>
class DenseStorage
185 internal::plain_array<T,Size,_Options> m_data;
187 EIGEN_DEVICE_FUNC DenseStorage() {
188 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = Size)
191 explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
192 : m_data(
internal::constructor_without_unaligned_array_assert()) {}
194 DenseStorage(
const DenseStorage& other) : m_data(other.m_data) {
195 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = Size)
198 DenseStorage& operator=(
const DenseStorage& other)
200 if (
this != &other) m_data = other.m_data;
204 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
205 eigen_internal_assert(size==rows*cols && rows==_Rows && cols==_Cols);
206 EIGEN_UNUSED_VARIABLE(size);
207 EIGEN_UNUSED_VARIABLE(rows);
208 EIGEN_UNUSED_VARIABLE(cols);
210 EIGEN_DEVICE_FUNC
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); }
211 EIGEN_DEVICE_FUNC
static Index rows(
void) {
return _Rows;}
212 EIGEN_DEVICE_FUNC
static Index cols(
void) {
return _Cols;}
215 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data.array; }
216 EIGEN_DEVICE_FUNC T *data() {
return m_data.array; }
220 template<
typename T,
int _Rows,
int _Cols,
int _Options>
class DenseStorage<T, 0, _Rows, _Cols, _Options>
223 EIGEN_DEVICE_FUNC DenseStorage() {}
224 EIGEN_DEVICE_FUNC
explicit DenseStorage(internal::constructor_without_unaligned_array_assert) {}
225 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage&) {}
226 EIGEN_DEVICE_FUNC DenseStorage& operator=(
const DenseStorage&) {
return *
this; }
228 EIGEN_DEVICE_FUNC
void swap(DenseStorage& ) {}
229 EIGEN_DEVICE_FUNC
static Index rows(
void) {
return _Rows;}
230 EIGEN_DEVICE_FUNC
static Index cols(
void) {
return _Cols;}
233 EIGEN_DEVICE_FUNC
const T *data()
const {
return 0; }
234 EIGEN_DEVICE_FUNC T *data() {
return 0; }
238 template<
typename T,
int _Options>
class DenseStorage<T, 0, Dynamic, Dynamic, _Options>
239 :
public DenseStorage<T, 0, 0, 0, _Options> { };
241 template<
typename T,
int _Rows,
int _Options>
class DenseStorage<T, 0, _Rows, Dynamic, _Options>
242 :
public DenseStorage<T, 0, 0, 0, _Options> { };
244 template<
typename T,
int _Cols,
int _Options>
class DenseStorage<T, 0, Dynamic, _Cols, _Options>
245 :
public DenseStorage<T, 0, 0, 0, _Options> { };
248 template<
typename T,
int Size,
int _Options>
class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
250 internal::plain_array<T,Size,_Options> m_data;
254 EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {}
255 EIGEN_DEVICE_FUNC
explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
256 : m_data(
internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
257 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows), m_cols(other.m_cols) {}
258 EIGEN_DEVICE_FUNC DenseStorage& operator=(
const DenseStorage& other)
262 m_data = other.m_data;
263 m_rows = other.m_rows;
264 m_cols = other.m_cols;
268 EIGEN_DEVICE_FUNC DenseStorage(
Index,
Index rows,
Index cols) : m_rows(rows), m_cols(cols) {}
269 EIGEN_DEVICE_FUNC
void swap(DenseStorage& other)
270 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
271 EIGEN_DEVICE_FUNC
Index rows()
const {
return m_rows;}
272 EIGEN_DEVICE_FUNC
Index cols()
const {
return m_cols;}
273 EIGEN_DEVICE_FUNC
void conservativeResize(
Index,
Index rows,
Index cols) { m_rows = rows; m_cols = cols; }
274 EIGEN_DEVICE_FUNC
void resize(
Index,
Index rows,
Index cols) { m_rows = rows; m_cols = cols; }
275 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data.array; }
276 EIGEN_DEVICE_FUNC T *data() {
return m_data.array; }
280 template<
typename T,
int Size,
int _Cols,
int _Options>
class DenseStorage<T, Size, Dynamic, _Cols, _Options>
282 internal::plain_array<T,Size,_Options> m_data;
285 EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {}
286 EIGEN_DEVICE_FUNC
explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
287 : m_data(
internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
288 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows) {}
289 EIGEN_DEVICE_FUNC DenseStorage& operator=(
const DenseStorage& other)
293 m_data = other.m_data;
294 m_rows = other.m_rows;
298 EIGEN_DEVICE_FUNC DenseStorage(
Index,
Index rows,
Index) : m_rows(rows) {}
299 EIGEN_DEVICE_FUNC
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
300 EIGEN_DEVICE_FUNC
Index rows(
void)
const {
return m_rows;}
301 EIGEN_DEVICE_FUNC
Index cols(
void)
const {
return _Cols;}
302 EIGEN_DEVICE_FUNC
void conservativeResize(
Index,
Index rows,
Index) { m_rows = rows; }
303 EIGEN_DEVICE_FUNC
void resize(
Index,
Index rows,
Index) { m_rows = rows; }
304 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data.array; }
305 EIGEN_DEVICE_FUNC T *data() {
return m_data.array; }
309 template<
typename T,
int Size,
int _Rows,
int _Options>
class DenseStorage<T, Size, _Rows, Dynamic, _Options>
311 internal::plain_array<T,Size,_Options> m_data;
314 EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {}
315 EIGEN_DEVICE_FUNC
explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
316 : m_data(
internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
317 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other) : m_data(other.m_data), m_cols(other.m_cols) {}
318 EIGEN_DEVICE_FUNC DenseStorage& operator=(
const DenseStorage& other)
322 m_data = other.m_data;
323 m_cols = other.m_cols;
327 EIGEN_DEVICE_FUNC DenseStorage(
Index,
Index,
Index cols) : m_cols(cols) {}
328 EIGEN_DEVICE_FUNC
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
329 EIGEN_DEVICE_FUNC
Index rows(
void)
const {
return _Rows;}
330 EIGEN_DEVICE_FUNC
Index cols(
void)
const {
return m_cols;}
333 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data.array; }
334 EIGEN_DEVICE_FUNC T *data() {
return m_data.array; }
338 template<
typename T,
int _Options>
class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
344 EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
345 EIGEN_DEVICE_FUNC
explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
346 : m_data(0), m_rows(0), m_cols(0) {}
348 : m_data(
internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
350 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
351 eigen_internal_assert(size==rows*cols && rows>=0 && cols >=0);
353 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other)
354 : m_data(
internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(other.m_rows*other.m_cols))
355 , m_rows(other.m_rows)
356 , m_cols(other.m_cols)
358 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = m_rows*m_cols)
359 internal::smart_copy(other.m_data, other.m_data+other.m_rows*other.m_cols, m_data);
361 EIGEN_DEVICE_FUNC DenseStorage& operator=(
const DenseStorage& other)
365 DenseStorage tmp(other);
370 #if EIGEN_HAS_RVALUE_REFERENCES 372 DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
373 : m_data(std::move(other.m_data))
374 , m_rows(std::move(other.m_rows))
375 , m_cols(std::move(other.m_cols))
377 other.m_data =
nullptr;
382 DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
385 swap(m_data, other.m_data);
386 swap(m_rows, other.m_rows);
387 swap(m_cols, other.m_cols);
391 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
392 EIGEN_DEVICE_FUNC
void swap(DenseStorage& other)
393 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
394 EIGEN_DEVICE_FUNC
Index rows(
void)
const {
return m_rows;}
395 EIGEN_DEVICE_FUNC
Index cols(
void)
const {
return m_cols;}
398 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
404 if(size != m_rows*m_cols)
406 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
408 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
411 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
416 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data; }
417 EIGEN_DEVICE_FUNC T *data() {
return m_data; }
421 template<
typename T,
int _Rows,
int _Options>
class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
426 EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_cols(0) {}
427 explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
428 EIGEN_DEVICE_FUNC DenseStorage(
Index size,
Index rows,
Index cols) : m_data(
internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(size)), m_cols(cols)
430 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
431 eigen_internal_assert(size==rows*cols && rows==_Rows && cols >=0);
432 EIGEN_UNUSED_VARIABLE(rows);
434 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other)
435 : m_data(
internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(_Rows*other.m_cols))
436 , m_cols(other.m_cols)
438 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = m_cols*_Rows)
439 internal::smart_copy(other.m_data, other.m_data+_Rows*m_cols, m_data);
441 EIGEN_DEVICE_FUNC DenseStorage& operator=(
const DenseStorage& other)
445 DenseStorage tmp(other);
450 #if EIGEN_HAS_RVALUE_REFERENCES 452 DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
453 : m_data(std::move(other.m_data))
454 , m_cols(std::move(other.m_cols))
456 other.m_data =
nullptr;
460 DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
463 swap(m_data, other.m_data);
464 swap(m_cols, other.m_cols);
468 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
469 EIGEN_DEVICE_FUNC
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
470 EIGEN_DEVICE_FUNC
static Index rows(
void) {
return _Rows;}
471 EIGEN_DEVICE_FUNC
Index cols(
void)
const {
return m_cols;}
472 EIGEN_DEVICE_FUNC
void conservativeResize(
Index size,
Index,
Index cols)
474 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
477 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void resize(
Index size,
Index,
Index cols)
479 if(size != _Rows*m_cols)
481 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
483 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
486 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
490 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data; }
491 EIGEN_DEVICE_FUNC T *data() {
return m_data; }
495 template<
typename T,
int _Cols,
int _Options>
class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
500 EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0) {}
501 explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
502 EIGEN_DEVICE_FUNC DenseStorage(
Index size,
Index rows,
Index cols) : m_data(
internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(size)), m_rows(rows)
504 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
505 eigen_internal_assert(size==rows*cols && rows>=0 && cols == _Cols);
506 EIGEN_UNUSED_VARIABLE(cols);
508 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other)
509 : m_data(
internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(other.m_rows*_Cols))
510 , m_rows(other.m_rows)
512 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = m_rows*_Cols)
513 internal::smart_copy(other.m_data, other.m_data+other.m_rows*_Cols, m_data);
515 EIGEN_DEVICE_FUNC DenseStorage& operator=(
const DenseStorage& other)
519 DenseStorage tmp(other);
524 #if EIGEN_HAS_RVALUE_REFERENCES 526 DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
527 : m_data(std::move(other.m_data))
528 , m_rows(std::move(other.m_rows))
530 other.m_data =
nullptr;
534 DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
537 swap(m_data, other.m_data);
538 swap(m_rows, other.m_rows);
542 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
543 EIGEN_DEVICE_FUNC
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
544 EIGEN_DEVICE_FUNC
Index rows(
void)
const {
return m_rows;}
545 EIGEN_DEVICE_FUNC
static Index cols(
void) {
return _Cols;}
548 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
551 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void resize(
Index size,
Index rows,
Index)
553 if(size != m_rows*_Cols)
555 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
557 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
560 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
564 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data; }
565 EIGEN_DEVICE_FUNC T *data() {
return m_data; }
570 #endif // EIGEN_MATRIX_H Definition: Constants.h:326
Namespace containing all symbols from the Eigen library.
Definition: Core:287
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Eigen_Colamd.h:50