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)
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>();
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>
85 EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size];
90 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7);
91 check_static_allocation_size<T,Size>();
97 check_static_allocation_size<T,Size>();
101 template <
typename T,
int Size,
int MatrixOrArrayOptions>
104 EIGEN_ALIGN_TO_BOUNDARY(16) T array[Size];
109 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15);
110 check_static_allocation_size<T,Size>();
116 check_static_allocation_size<T,Size>();
120 template <
typename T,
int Size,
int MatrixOrArrayOptions>
123 EIGEN_ALIGN_TO_BOUNDARY(32) T array[Size];
128 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31);
129 check_static_allocation_size<T,Size>();
135 check_static_allocation_size<T,Size>();
139 template <
typename T,
int Size,
int MatrixOrArrayOptions>
142 EIGEN_ALIGN_TO_BOUNDARY(64) T array[Size];
147 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(63);
148 check_static_allocation_size<T,Size>();
154 check_static_allocation_size<T,Size>();
158 template <
typename T,
int MatrixOrArrayOptions,
int Alignment>
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
188 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = Size)
195 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = Size)
200 if (
this != &other) m_data = other.m_data;
203 #if EIGEN_HAS_RVALUE_REFERENCES
205 : m_data(std::move(other.m_data))
211 m_data = std::move(other.m_data);
216 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
217 eigen_internal_assert(size==rows*cols && rows==_Rows && cols==_Cols);
218 EIGEN_UNUSED_VARIABLE(size);
219 EIGEN_UNUSED_VARIABLE(rows);
220 EIGEN_UNUSED_VARIABLE(cols);
223 numext::swap(m_data, other.m_data);
225 EIGEN_DEVICE_FUNC
static Index rows(
void) {
return _Rows;}
226 EIGEN_DEVICE_FUNC
static Index cols(
void) {
return _Cols;}
229 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data.array; }
230 EIGEN_DEVICE_FUNC T *data() {
return m_data.array; }
243 EIGEN_DEVICE_FUNC
static Index rows(
void) {
return _Rows;}
244 EIGEN_DEVICE_FUNC
static Index cols(
void) {
return _Cols;}
247 EIGEN_DEVICE_FUNC
const T *data()
const {
return 0; }
248 EIGEN_DEVICE_FUNC T *data() {
return 0; }
268 EIGEN_DEVICE_FUNC
DenseStorage() : m_rows(0), m_cols(0) {}
271 EIGEN_DEVICE_FUNC
DenseStorage(
const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows), m_cols(other.m_cols) {}
276 m_data = other.m_data;
277 m_rows = other.m_rows;
278 m_cols = other.m_cols;
285 numext::swap(m_data,other.m_data);
286 numext::swap(m_rows,other.m_rows);
287 numext::swap(m_cols,other.m_cols);
289 EIGEN_DEVICE_FUNC
Index rows()
const {
return m_rows;}
290 EIGEN_DEVICE_FUNC
Index cols()
const {
return m_cols;}
291 EIGEN_DEVICE_FUNC
void conservativeResize(
Index,
Index rows,
Index cols) { m_rows = rows; m_cols = cols; }
292 EIGEN_DEVICE_FUNC
void resize(
Index,
Index rows,
Index cols) { m_rows = rows; m_cols = cols; }
293 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data.array; }
294 EIGEN_DEVICE_FUNC T *data() {
return m_data.array; }
311 m_data = other.m_data;
312 m_rows = other.m_rows;
319 numext::swap(m_data,other.m_data);
320 numext::swap(m_rows,other.m_rows);
322 EIGEN_DEVICE_FUNC
Index rows(
void)
const {
return m_rows;}
323 EIGEN_DEVICE_FUNC
Index cols(
void)
const {
return _Cols;}
324 EIGEN_DEVICE_FUNC
void conservativeResize(
Index,
Index rows,
Index) { m_rows = rows; }
325 EIGEN_DEVICE_FUNC
void resize(
Index,
Index rows,
Index) { m_rows = rows; }
326 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data.array; }
327 EIGEN_DEVICE_FUNC T *data() {
return m_data.array; }
344 m_data = other.m_data;
345 m_cols = other.m_cols;
351 numext::swap(m_data,other.m_data);
352 numext::swap(m_cols,other.m_cols);
354 EIGEN_DEVICE_FUNC
Index rows(
void)
const {
return _Rows;}
355 EIGEN_DEVICE_FUNC
Index cols(
void)
const {
return m_cols;}
356 EIGEN_DEVICE_FUNC
void conservativeResize(
Index,
Index,
Index cols) { m_cols = cols; }
357 EIGEN_DEVICE_FUNC
void resize(
Index,
Index,
Index cols) { m_cols = cols; }
358 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data.array; }
359 EIGEN_DEVICE_FUNC T *data() {
return m_data.array; }
369 EIGEN_DEVICE_FUNC
DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
371 : m_data(0), m_rows(0), m_cols(0) {}
373 : m_data(internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
375 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
376 eigen_internal_assert(size==rows*cols && rows>=0 && cols >=0);
379 : m_data(internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(other.m_rows*other.m_cols))
380 , m_rows(other.m_rows)
381 , m_cols(other.m_cols)
383 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = m_rows*m_cols)
384 internal::smart_copy(other.m_data, other.m_data+other.m_rows*other.m_cols, m_data);
395 #if EIGEN_HAS_RVALUE_REFERENCES
398 : m_data(std::move(other.m_data))
399 , m_rows(std::move(other.m_rows))
400 , m_cols(std::move(other.m_cols))
402 other.m_data =
nullptr;
409 numext::swap(m_data, other.m_data);
410 numext::swap(m_rows, other.m_rows);
411 numext::swap(m_cols, other.m_cols);
415 EIGEN_DEVICE_FUNC ~
DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
418 numext::swap(m_data,other.m_data);
419 numext::swap(m_rows,other.m_rows);
420 numext::swap(m_cols,other.m_cols);
422 EIGEN_DEVICE_FUNC
Index rows(
void)
const {
return m_rows;}
423 EIGEN_DEVICE_FUNC
Index cols(
void)
const {
return m_cols;}
426 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
432 if(size != m_rows*m_cols)
434 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
436 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
439 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
444 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data; }
445 EIGEN_DEVICE_FUNC T *data() {
return m_data; }
454 EIGEN_DEVICE_FUNC
DenseStorage() : m_data(0), m_cols(0) {}
458 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
459 eigen_internal_assert(size==rows*cols && rows==_Rows && cols >=0);
460 EIGEN_UNUSED_VARIABLE(rows);
463 : m_data(internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(_Rows*other.m_cols))
464 , m_cols(other.m_cols)
466 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = m_cols*_Rows)
467 internal::smart_copy(other.m_data, other.m_data+_Rows*m_cols, m_data);
478 #if EIGEN_HAS_RVALUE_REFERENCES
481 : m_data(std::move(other.m_data))
482 , m_cols(std::move(other.m_cols))
484 other.m_data =
nullptr;
490 numext::swap(m_data, other.m_data);
491 numext::swap(m_cols, other.m_cols);
495 EIGEN_DEVICE_FUNC ~
DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
497 numext::swap(m_data,other.m_data);
498 numext::swap(m_cols,other.m_cols);
500 EIGEN_DEVICE_FUNC
static Index rows(
void) {
return _Rows;}
501 EIGEN_DEVICE_FUNC
Index cols(
void)
const {
return m_cols;}
502 EIGEN_DEVICE_FUNC
void conservativeResize(
Index size,
Index,
Index cols)
504 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
507 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void resize(
Index size,
Index,
Index cols)
509 if(size != _Rows*m_cols)
511 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
513 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
516 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
520 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data; }
521 EIGEN_DEVICE_FUNC T *data() {
return m_data; }
530 EIGEN_DEVICE_FUNC
DenseStorage() : m_data(0), m_rows(0) {}
534 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
535 eigen_internal_assert(size==rows*cols && rows>=0 && cols == _Cols);
536 EIGEN_UNUSED_VARIABLE(cols);
539 : m_data(internal::conditional_aligned_new_auto<T,(_Options&
DontAlign)==0>(other.m_rows*_Cols))
540 , m_rows(other.m_rows)
542 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(
Index size = m_rows*_Cols)
543 internal::smart_copy(other.m_data, other.m_data+other.m_rows*_Cols, m_data);
554 #if EIGEN_HAS_RVALUE_REFERENCES
557 : m_data(std::move(other.m_data))
558 , m_rows(std::move(other.m_rows))
560 other.m_data =
nullptr;
566 numext::swap(m_data, other.m_data);
567 numext::swap(m_rows, other.m_rows);
571 EIGEN_DEVICE_FUNC ~
DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
573 numext::swap(m_data,other.m_data);
574 numext::swap(m_rows,other.m_rows);
576 EIGEN_DEVICE_FUNC
Index rows(
void)
const {
return m_rows;}
577 EIGEN_DEVICE_FUNC
static Index cols(
void) {
return _Cols;}
580 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
583 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void resize(
Index size,
Index rows,
Index)
585 if(size != m_rows*_Cols)
587 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
589 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
592 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
596 EIGEN_DEVICE_FUNC
const T *data()
const {
return m_data; }
597 EIGEN_DEVICE_FUNC T *data() {
return m_data; }
602 #endif // EIGEN_MATRIX_H