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 struct constructor_without_unaligned_array_assert {};
29 template <
typename T,
int Size>
32 #if EIGEN_STACK_ALLOCATION_LIMIT
41 template <
typename T,
int Size,
int MatrixOrArrayOptions,
42 int Alignment = (MatrixOrArrayOptions&
DontAlign) ? 0
43 : compute_default_alignment<T,Size>::value >
48 EIGEN_DEVICE_FUNC constexpr plain_array() { check_static_allocation_size<T, Size>(); }
50 EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) {
51 check_static_allocation_size<T, Size>();
55 #if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
56 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
58 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
59 eigen_assert((internal::is_constant_evaluated() || (std::uintptr_t(array) & (sizemask)) == 0) \
60 && "this assertion is explained here: " \
61 "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
62 " **** READ THIS WEB PAGE !!! ****");
65 template <
typename T,
int Size,
int MatrixOrArrayOptions>
66 struct plain_array<T, Size, MatrixOrArrayOptions, 8>
72 check_static_allocation_size<T,Size>();
75 EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) {
76 check_static_allocation_size<T, Size>();
80 template <
typename T,
int Size,
int MatrixOrArrayOptions>
81 struct plain_array<T, Size, MatrixOrArrayOptions, 16>
87 check_static_allocation_size<T,Size>();
90 EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) {
91 check_static_allocation_size<T, Size>();
95 template <
typename T,
int Size,
int MatrixOrArrayOptions>
96 struct plain_array<T, Size, MatrixOrArrayOptions, 32>
102 check_static_allocation_size<T,Size>();
105 EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) {
106 check_static_allocation_size<T, Size>();
110 template <
typename T,
int Size,
int MatrixOrArrayOptions>
111 struct plain_array<T, Size, MatrixOrArrayOptions, 64>
117 check_static_allocation_size<T,Size>();
120 EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) {
121 check_static_allocation_size<T, Size>();
125 template <
typename T,
int MatrixOrArrayOptions,
int Alignment>
126 struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
130 EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) {}
133 struct plain_array_helper {
134 template<
typename T,
int Size,
int MatrixOrArrayOptions,
int Alignment>
136 static void copy(
const plain_array<T, Size, MatrixOrArrayOptions, Alignment>& src,
const Eigen::Index size,
137 plain_array<T, Size, MatrixOrArrayOptions, Alignment>& dst) {
141 template<
typename T,
int Size,
int MatrixOrArrayOptions,
int Alignment>
143 static void swap(plain_array<T, Size, MatrixOrArrayOptions, Alignment>&
a,
const Eigen::Index a_size,
144 plain_array<T, Size, MatrixOrArrayOptions, Alignment>&
b,
const Eigen::Index b_size) {
145 if (a_size < b_size) {
146 std::swap_ranges(
b.array,
b.array + a_size,
a.array);
147 smart_move(
b.array + a_size,
b.array + b_size,
a.array + a_size);
148 }
else if (a_size > b_size) {
149 std::swap_ranges(
a.array,
a.array + b_size,
b.array);
150 smart_move(
a.array + b_size,
a.array + a_size,
b.array + b_size);
152 std::swap_ranges(
a.array,
a.array + a_size,
b.array);
171 template<
typename T,
int Size,
int Rows_,
int Cols_,
int Options_>
class DenseStorage;
174 template<
typename T,
int Size,
int Rows_,
int Cols_,
int Options_>
class DenseStorage
176 internal::plain_array<T,Size,Options_>
m_data;
182 : m_data(
internal::constructor_without_unaligned_array_assert()) {}
183 #if defined(EIGEN_DENSE_STORAGE_CTOR_PLUGIN)
213 template<
typename T,
int Rows_,
int Cols_,
int Options_>
214 class DenseStorage<T, 0, Rows_, Cols_, Options_>
217 static_assert(Rows_ * Cols_ == 0,
"The fixed number of rows times columns must equal the storage size.");
219 EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) {}
221 EIGEN_DEVICE_FUNC constexpr DenseStorage& operator=(
const DenseStorage&) {
return *
this; }
233 template<
typename T,
int Options_>
234 class DenseStorage<T, 0, Dynamic, Dynamic, Options_> {
239 EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {}
240 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other) : m_rows(other.m_rows), m_cols(other.m_cols) {}
242 m_rows = other.m_rows;
243 m_cols = other.m_cols;
247 eigen_assert(m_rows * m_cols == 0 &&
"The number of rows times columns must equal the storage size.");
258 eigen_assert(m_rows * m_cols == 0 &&
"The number of rows times columns must equal the storage size.");
263 eigen_assert(m_rows * m_cols == 0 &&
"The number of rows times columns must equal the storage size.");
269 template<
typename T,
int Rows_,
int Options_>
270 class DenseStorage<T, 0, Rows_, Dynamic, Options_> {
274 EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {}
275 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other) : m_cols(other.m_cols) {}
277 m_cols = other.m_cols;
281 eigen_assert(Rows_ * m_cols == 0 &&
"The number of rows times columns must equal the storage size.");
290 eigen_assert(Rows_ * m_cols == 0 &&
"The number of rows times columns must equal the storage size.");
294 eigen_assert(Rows_ * m_cols == 0 &&
"The number of rows times columns must equal the storage size.");
300 template<
typename T,
int Cols_,
int Options_>
301 class DenseStorage<T, 0, Dynamic, Cols_, Options_> {
305 EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {}
306 EIGEN_DEVICE_FUNC DenseStorage(
const DenseStorage& other) : m_rows(other.m_rows) {}
308 m_rows = other.m_rows;
312 eigen_assert(m_rows * Cols_ == 0 &&
"The number of rows times columns must equal the storage size.");
321 eigen_assert(m_rows * Cols_ == 0 &&
"The number of rows times columns must equal the storage size.");
325 eigen_assert(m_rows * Cols_ == 0 &&
"The number of rows times columns must equal the storage size.");
332 template<
typename T,
int Size,
int Options_>
333 class DenseStorage<T, Size, Dynamic, Dynamic, Options_>
335 internal::plain_array<T,Size,Options_> m_data;
340 EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert)
341 : m_data(
internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
343 : m_data(
internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows), m_cols(other.m_cols) {
344 internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data);
350 m_rows = other.m_rows;
351 m_cols = other.m_cols;
352 internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data);
378 template<
typename T,
int Size,
int Cols_,
int Options_>
379 class DenseStorage<T, Size, Dynamic, Cols_, Options_>
381 internal::plain_array<T,Size,Options_> m_data;
385 EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert)
386 : m_data(
internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
388 : m_data(
internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows) {
389 internal::plain_array_helper::copy(other.m_data, m_rows * Cols_, m_data);
396 m_rows = other.m_rows;
397 internal::plain_array_helper::copy(other.m_data, m_rows * Cols_, m_data);
416 template<
typename T,
int Size,
int Rows_,
int Options_>
417 class DenseStorage<T, Size, Rows_, Dynamic, Options_>
419 internal::plain_array<T,Size,Options_> m_data;
423 EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert)
424 : m_data(
internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
426 : m_data(
internal::constructor_without_unaligned_array_assert()), m_cols(other.m_cols) {
427 internal::plain_array_helper::copy(other.m_data, Rows_ * m_cols, m_data);
433 m_cols = other.m_cols;
434 internal::plain_array_helper::copy(other.m_data, Rows_ * m_cols, m_data);
452 template<
typename T,
int Options_>
453 class DenseStorage<T, Dynamic, Dynamic, Dynamic, Options_>
460 EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert)
461 : m_data(0), m_rows(0), m_cols(0) {}
471 , m_rows(other.m_rows)
472 , m_cols(other.m_cols)
481 DenseStorage tmp(other);
488 : m_data(std::move(other.m_data))
489 , m_rows(std::move(other.m_rows))
490 , m_cols(std::move(other.m_cols))
492 other.m_data =
nullptr;
504 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, m_rows*m_cols); }
515 m_data = internal::conditional_aligned_realloc_new_auto<T,(Options_&DontAlign)==0>(m_data,
size, m_rows*m_cols);
521 if(
size != m_rows*m_cols)
523 internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, m_rows*m_cols);
525 m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(
size);
538 template<
typename T,
int Rows_,
int Options_>
539 class DenseStorage<T, Dynamic, Rows_, Dynamic, Options_> {
544 explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
553 , m_cols(other.m_cols)
562 DenseStorage tmp(other);
569 : m_data(std::move(other.m_data))
570 , m_cols(std::move(other.m_cols))
572 other.m_data =
nullptr;
582 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, Rows_*m_cols); }
591 m_data = internal::conditional_aligned_realloc_new_auto<T,(Options_&DontAlign)==0>(m_data,
size, Rows_*m_cols);
596 if(
size != Rows_*m_cols)
598 internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, Rows_*m_cols);
600 m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(
size);
612 template<
typename T,
int Cols_,
int Options_>
613 class DenseStorage<T, Dynamic, Dynamic, Cols_, Options_>
619 explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
628 , m_rows(other.m_rows)
637 DenseStorage tmp(other);
644 : m_data(std::move(other.m_data))
645 , m_rows(std::move(other.m_rows))
647 other.m_data =
nullptr;
657 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, Cols_*m_rows); }
666 m_data = internal::conditional_aligned_realloc_new_auto<T,(Options_&DontAlign)==0>(m_data,
size, m_rows*Cols_);
671 if(
size != m_rows*Cols_)
673 internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, Cols_*m_rows);
675 m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(
size);
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X)
#define eigen_internal_assert(x)
#define EIGEN_UNUSED_VARIABLE(var)
#define EIGEN_DEVICE_FUNC
#define EIGEN_STACK_ALLOCATION_LIMIT
#define EIGEN_STATIC_ASSERT(X, MSG)
Eigen::Triplet< double > T
constexpr void conservativeResize(Index, Index, Index)
constexpr DenseStorage(internal::constructor_without_unaligned_array_assert)
static constexpr Index cols(void) EIGEN_NOEXCEPT
constexpr DenseStorage & operator=(const DenseStorage &)=default
constexpr DenseStorage & operator=(DenseStorage &&)=default
static constexpr Index rows(void) EIGEN_NOEXCEPT
constexpr void resize(Index, Index, Index)
constexpr const T * data() const
constexpr DenseStorage(const DenseStorage &)=default
constexpr DenseStorage(Index size, Index rows, Index cols)
void swap(DenseStorage &other)
internal::plain_array< T, Size, Options_ > m_data
constexpr DenseStorage(DenseStorage &&)=default
T * conditional_aligned_new_auto(std::size_t size)
T * smart_move(T *start, T *end, T *target)
void smart_copy(const T *start, const T *end, T *target)
void swap(scoped_array< T > &a, scoped_array< T > &b)
constexpr void check_static_allocation_size()
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.