$darkmode
Eigen  5.0.1-dev
DenseStorage.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
6 // Copyright (C) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com>
7 //
8 // This Source Code Form is subject to the terms of the Mozilla
9 // Public License v. 2.0. If a copy of the MPL was not distributed
10 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 
12 #ifndef EIGEN_MATRIXSTORAGE_H
13 #define EIGEN_MATRIXSTORAGE_H
14 
15 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
16 #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) \
17  X; \
18  EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
19 #else
20 #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X)
21 #endif
22 
23 // IWYU pragma: private
24 #include "./InternalHeaderCheck.h"
25 
26 namespace Eigen {
27 
28 namespace internal {
29 
30 #if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
31 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(Alignment)
32 #else
33 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(Alignment) \
34  eigen_assert((is_constant_evaluated() || (std::uintptr_t(array) % Alignment == 0)) && \
35  "this assertion is explained here: " \
36  "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
37  " **** READ THIS WEB PAGE !!! ****");
38 #endif
39 
40 #if EIGEN_STACK_ALLOCATION_LIMIT
41 #define EIGEN_MAKE_STACK_ALLOCATION_ASSERT(X) \
42  EIGEN_STATIC_ASSERT(X <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG)
43 #else
44 #define EIGEN_MAKE_STACK_ALLOCATION_ASSERT(X)
45 #endif
46 
52 template <typename T, int Size, int MatrixOrArrayOptions,
53  int Alignment = (MatrixOrArrayOptions & DontAlign) ? 0 : compute_default_alignment<T, Size>::value>
54 struct plain_array {
55  EIGEN_ALIGN_TO_BOUNDARY(Alignment) T array[Size];
56 #if defined(EIGEN_NO_DEBUG) || defined(EIGEN_TESTING_PLAINOBJECT_CTOR)
57  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() = default;
58 #else
59  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() {
60  EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(Alignment)
61  EIGEN_MAKE_STACK_ALLOCATION_ASSERT(Size * sizeof(T))
62  }
63 #endif
64 };
65 
66 template <typename T, int Size, int MatrixOrArrayOptions>
67 struct plain_array<T, Size, MatrixOrArrayOptions, 0> {
68  // on some 32-bit platforms, stack-allocated arrays are aligned to 4 bytes, not the preferred alignment of T
69  EIGEN_ALIGN_TO_BOUNDARY(alignof(T)) T array[Size];
70 #if defined(EIGEN_NO_DEBUG) || defined(EIGEN_TESTING_PLAINOBJECT_CTOR)
71  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() = default;
72 #else
73  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr plain_array() { EIGEN_MAKE_STACK_ALLOCATION_ASSERT(Size * sizeof(T)) }
74 #endif
75 };
76 
77 template <typename T, int Size, int Options, int Alignment>
78 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap_plain_array(plain_array<T, Size, Options, Alignment>& a,
79  plain_array<T, Size, Options, Alignment>& b,
80  Index a_size, Index b_size) {
81  Index common_size = numext::mini(a_size, b_size);
82  std::swap_ranges(a.array, a.array + common_size, b.array);
83  if (a_size > b_size)
84  smart_copy(a.array + common_size, a.array + a_size, b.array + common_size);
85  else if (b_size > a_size)
86  smart_copy(b.array + common_size, b.array + b_size, a.array + common_size);
87 }
88 
89 template <typename T, int Size, int Rows, int Cols, int Options>
90 class DenseStorage_impl {
91  plain_array<T, Size, Options> m_data;
92 
93  public:
94 #ifndef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
95  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
96  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl&) = default;
97 #else
98  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() {
99  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
100  }
101  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl& other) {
102  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
103  smart_copy(other.m_data.array, other.m_data.array + Size, m_data.array);
104  }
105 #endif
106  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index /*size*/, Index /*rows*/, Index /*cols*/) {}
107  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl&) = default;
108  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) {
109  numext::swap(m_data, other.m_data);
110  }
111  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index /*rows*/,
112  Index /*cols*/) {}
113  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index /*rows*/, Index /*cols*/) {}
114  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return Rows; }
115  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
116  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return Rows * Cols; }
117  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data.array; }
118  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data.array; }
119 };
120 template <typename T, int Size, int Cols, int Options>
121 class DenseStorage_impl<T, Size, Dynamic, Cols, Options> {
122  plain_array<T, Size, Options> m_data;
123  Index m_rows = 0;
124 
125  public:
126  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
127  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl& other)
128  : m_rows(other.m_rows) {
129  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = other.size())
130  smart_copy(other.m_data.array, other.m_data.array + other.size(), m_data.array);
131  }
132  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index size, Index rows, Index /*cols*/)
133  : m_rows(rows) {
134  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
135  EIGEN_UNUSED_VARIABLE(size)
136  }
137  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl& other) {
138  smart_copy(other.m_data.array, other.m_data.array + other.size(), m_data.array);
139  m_rows = other.m_rows;
140  return *this;
141  }
142  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) {
143  swap_plain_array(m_data, other.m_data, size(), other.size());
144  numext::swap(m_rows, other.m_rows);
145  }
146  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index rows, Index /*cols*/) {
147  m_rows = rows;
148  }
149  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index rows, Index /*cols*/) {
150  m_rows = rows;
151  }
152  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return m_rows; }
153  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
154  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return m_rows * Cols; }
155  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data.array; }
156  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data.array; }
157 };
158 template <typename T, int Size, int Rows, int Options>
159 class DenseStorage_impl<T, Size, Rows, Dynamic, Options> {
160  plain_array<T, Size, Options> m_data;
161  Index m_cols = 0;
162 
163  public:
164  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
165  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl& other)
166  : m_cols(other.m_cols) {
167  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = other.size())
168  smart_copy(other.m_data.array, other.m_data.array + other.size(), m_data.array);
169  }
170  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index size, Index /*rows*/, Index cols)
171  : m_cols(cols) {
172  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
173  EIGEN_UNUSED_VARIABLE(size)
174  }
175  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl& other) {
176  smart_copy(other.m_data.array, other.m_data.array + other.size(), m_data.array);
177  m_cols = other.m_cols;
178  return *this;
179  }
180  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) {
181  swap_plain_array(m_data, other.m_data, size(), other.size());
182  numext::swap(m_cols, other.m_cols);
183  }
184  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index /*rows*/, Index cols) {
185  m_cols = cols;
186  }
187  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index /*rows*/, Index cols) {
188  m_cols = cols;
189  }
190  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return Rows; }
191  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return m_cols; }
192  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return Rows * m_cols; }
193  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data.array; }
194  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data.array; }
195 };
196 template <typename T, int Size, int Options>
197 class DenseStorage_impl<T, Size, Dynamic, Dynamic, Options> {
198  plain_array<T, Size, Options> m_data;
199  Index m_rows = 0;
200  Index m_cols = 0;
201 
202  public:
203  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
204  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl& other)
205  : m_rows(other.m_rows), m_cols(other.m_cols) {
206  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = other.size())
207  smart_copy(other.m_data.array, other.m_data.array + other.size(), m_data.array);
208  }
209  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index size, Index rows, Index cols)
210  : m_rows(rows), m_cols(cols) {
211  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
212  EIGEN_UNUSED_VARIABLE(size)
213  }
214  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl& other) {
215  smart_copy(other.m_data.array, other.m_data.array + other.size(), m_data.array);
216  m_rows = other.m_rows;
217  m_cols = other.m_cols;
218  return *this;
219  }
220  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) {
221  swap_plain_array(m_data, other.m_data, size(), other.size());
222  numext::swap(m_rows, other.m_rows);
223  numext::swap(m_cols, other.m_cols);
224  }
225  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index rows, Index cols) {
226  m_rows = rows;
227  m_cols = cols;
228  }
229  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index rows, Index cols) {
230  m_rows = rows;
231  m_cols = cols;
232  }
233  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return m_rows; }
234  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return m_cols; }
235  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return m_rows * m_cols; }
236  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data.array; }
237  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data.array; }
238 };
239 // null matrix variants
240 template <typename T, int Rows, int Cols, int Options>
241 class DenseStorage_impl<T, 0, Rows, Cols, Options> {
242  public:
243  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
244  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl&) = default;
245  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index /*size*/, Index /*rows*/, Index /*cols*/) {}
246  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl&) = default;
247  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl&) {}
248  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index /*rows*/,
249  Index /*cols*/) {}
250  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index /*rows*/, Index /*cols*/) {}
251  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return Rows; }
252  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
253  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return Rows * Cols; }
254  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return nullptr; }
255  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return nullptr; }
256 };
257 template <typename T, int Cols, int Options>
258 class DenseStorage_impl<T, 0, Dynamic, Cols, Options> {
259  Index m_rows = 0;
260 
261  public:
262  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
263  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl&) = default;
264  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index /*size*/, Index rows, Index /*cols*/)
265  : m_rows(rows) {}
266  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl&) = default;
267  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) noexcept {
268  numext::swap(m_rows, other.m_rows);
269  }
270  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index rows, Index /*cols*/) {
271  m_rows = rows;
272  }
273  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index rows, Index /*cols*/) {
274  m_rows = rows;
275  }
276  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return m_rows; }
277  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
278  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return m_rows * Cols; }
279  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return nullptr; }
280  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return nullptr; }
281 };
282 template <typename T, int Rows, int Options>
283 class DenseStorage_impl<T, 0, Rows, Dynamic, Options> {
284  Index m_cols = 0;
285 
286  public:
287  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
288  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl&) = default;
289  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index /*size*/, Index /*rows*/, Index cols)
290  : m_cols(cols) {}
291  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl&) = default;
292  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) noexcept {
293  numext::swap(m_cols, other.m_cols);
294  }
295  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index /*rows*/, Index cols) {
296  m_cols = cols;
297  }
298  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index /*rows*/, Index cols) {
299  m_cols = cols;
300  }
301  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return Rows; }
302  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return m_cols; }
303  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return Rows * m_cols; }
304  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return nullptr; }
305  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return nullptr; }
306 };
307 template <typename T, int Options>
308 class DenseStorage_impl<T, 0, Dynamic, Dynamic, Options> {
309  Index m_rows = 0;
310  Index m_cols = 0;
311 
312  public:
313  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
314  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl&) = default;
315  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index /*size*/, Index rows, Index cols)
316  : m_rows(rows), m_cols(cols) {}
317  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl&) = default;
318  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) noexcept {
319  numext::swap(m_rows, other.m_rows);
320  numext::swap(m_cols, other.m_cols);
321  }
322  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index /*size*/, Index rows, Index cols) {
323  m_rows = rows;
324  m_cols = cols;
325  }
326  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index /*size*/, Index rows, Index cols) {
327  m_rows = rows;
328  m_cols = cols;
329  }
330  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return m_rows; }
331  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return m_cols; }
332  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return m_rows * m_cols; }
333  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return nullptr; }
334  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return nullptr; }
335 };
336 // fixed-size matrix with dynamic memory allocation not currently supported
337 template <typename T, int Rows, int Cols, int Options>
338 class DenseStorage_impl<T, Dynamic, Rows, Cols, Options> {};
339 // dynamic-sized variants
340 template <typename T, int Cols, int Options>
341 class DenseStorage_impl<T, Dynamic, Dynamic, Cols, Options> {
342  static constexpr bool Align = (Options & DontAlign) == 0;
343  T* m_data = nullptr;
344  Index m_rows = 0;
345 
346  public:
347  static constexpr int Size = Dynamic;
348  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
349  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl& other)
350  : m_data(conditional_aligned_new_auto<T, Align>(other.size())), m_rows(other.m_rows) {
351  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = other.size())
352  smart_copy(other.m_data, other.m_data + other.size(), m_data);
353  }
354  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index size, Index rows, Index /*cols*/)
355  : m_data(conditional_aligned_new_auto<T, Align>(size)), m_rows(rows) {
356  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
357  }
358  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(DenseStorage_impl&& other) noexcept
359  : m_data(other.m_data), m_rows(other.m_rows) {
360  other.m_data = nullptr;
361  other.m_rows = 0;
362  }
363  EIGEN_DEVICE_FUNC ~DenseStorage_impl() { conditional_aligned_delete_auto<T, Align>(m_data, size()); }
364  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl& other) {
365  resize(other.size(), other.rows(), other.cols());
366  smart_copy(other.m_data, other.m_data + other.size(), m_data);
367  return *this;
368  }
369  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(DenseStorage_impl&& other) noexcept {
370  this->swap(other);
371  return *this;
372  }
373  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) noexcept {
374  numext::swap(m_data, other.m_data);
375  numext::swap(m_rows, other.m_rows);
376  }
377  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index size, Index rows, Index /*cols*/) {
378  m_data = conditional_aligned_realloc_new_auto<T, Align>(m_data, size, this->size());
379  m_rows = rows;
380  }
381  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index size, Index rows, Index /*cols*/) {
382  Index oldSize = this->size();
383  if (oldSize != size) {
384  conditional_aligned_delete_auto<T, Align>(m_data, oldSize);
385  m_data = conditional_aligned_new_auto<T, Align>(size);
386  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
387  }
388  m_rows = rows;
389  }
390  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return m_rows; }
391  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return Cols; }
392  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return m_rows * Cols; }
393  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data; }
394  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data; }
395 };
396 template <typename T, int Rows, int Options>
397 class DenseStorage_impl<T, Dynamic, Rows, Dynamic, Options> {
398  static constexpr bool Align = (Options & DontAlign) == 0;
399  T* m_data = nullptr;
400  Index m_cols = 0;
401 
402  public:
403  static constexpr int Size = Dynamic;
404  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
405  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl& other)
406  : m_data(conditional_aligned_new_auto<T, Align>(other.size())), m_cols(other.m_cols) {
407  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = other.size())
408  smart_copy(other.m_data, other.m_data + other.size(), m_data);
409  }
410  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index size, Index /*rows*/, Index cols)
411  : m_data(conditional_aligned_new_auto<T, Align>(size)), m_cols(cols) {
412  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
413  }
414  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(DenseStorage_impl&& other) noexcept
415  : m_data(other.m_data), m_cols(other.m_cols) {
416  other.m_data = nullptr;
417  other.m_cols = 0;
418  }
419  EIGEN_DEVICE_FUNC ~DenseStorage_impl() { conditional_aligned_delete_auto<T, Align>(m_data, size()); }
420  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl& other) {
421  resize(other.size(), other.rows(), other.cols());
422  smart_copy(other.m_data, other.m_data + other.size(), m_data);
423  return *this;
424  }
425  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(DenseStorage_impl&& other) noexcept {
426  this->swap(other);
427  return *this;
428  }
429  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) noexcept {
430  numext::swap(m_data, other.m_data);
431  numext::swap(m_cols, other.m_cols);
432  }
433  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index size, Index /*rows*/, Index cols) {
434  m_data = conditional_aligned_realloc_new_auto<T, Align>(m_data, size, this->size());
435  m_cols = cols;
436  }
437  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index size, Index /*rows*/, Index cols) {
438  Index oldSize = this->size();
439  if (oldSize != size) {
440  conditional_aligned_delete_auto<T, Align>(m_data, oldSize);
441  m_data = conditional_aligned_new_auto<T, Align>(size);
442  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
443  }
444  m_cols = cols;
445  }
446  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return Rows; }
447  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return m_cols; }
448  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return Rows * m_cols; }
449  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data; }
450  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data; }
451 };
452 template <typename T, int Options>
453 class DenseStorage_impl<T, Dynamic, Dynamic, Dynamic, Options> {
454  static constexpr bool Align = (Options & DontAlign) == 0;
455  T* m_data = nullptr;
456  Index m_rows = 0;
457  Index m_cols = 0;
458 
459  public:
460  static constexpr int Size = Dynamic;
461  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl() = default;
462  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(const DenseStorage_impl& other)
463  : m_data(conditional_aligned_new_auto<T, Align>(other.size())), m_rows(other.m_rows), m_cols(other.m_cols) {
464  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = other.size())
465  smart_copy(other.m_data, other.m_data + other.size(), m_data);
466  }
467  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(Index size, Index rows, Index cols)
468  : m_data(conditional_aligned_new_auto<T, Align>(size)), m_rows(rows), m_cols(cols) {
469  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
470  }
471  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl(DenseStorage_impl&& other) noexcept
472  : m_data(other.m_data), m_rows(other.m_rows), m_cols(other.m_cols) {
473  other.m_data = nullptr;
474  other.m_rows = 0;
475  other.m_cols = 0;
476  }
477  EIGEN_DEVICE_FUNC ~DenseStorage_impl() { conditional_aligned_delete_auto<T, Align>(m_data, size()); }
478  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(const DenseStorage_impl& other) {
479  resize(other.size(), other.rows(), other.cols());
480  smart_copy(other.m_data, other.m_data + other.size(), m_data);
481  return *this;
482  }
483  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage_impl& operator=(DenseStorage_impl&& other) noexcept {
484  this->swap(other);
485  return *this;
486  }
487  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void swap(DenseStorage_impl& other) noexcept {
488  numext::swap(m_data, other.m_data);
489  numext::swap(m_rows, other.m_rows);
490  numext::swap(m_cols, other.m_cols);
491  }
492  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void conservativeResize(Index size, Index rows, Index cols) {
493  m_data = conditional_aligned_realloc_new_auto<T, Align>(m_data, size, this->size());
494  m_rows = rows;
495  m_cols = cols;
496  }
497  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index size, Index rows, Index cols) {
498  Index oldSize = this->size();
499  if (oldSize != size) {
500  conditional_aligned_delete_auto<T, Align>(m_data, oldSize);
501  m_data = conditional_aligned_new_auto<T, Align>(size);
502  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
503  }
504  m_rows = rows;
505  m_cols = cols;
506  }
507  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const { return m_rows; }
508  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const { return m_cols; }
509  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index size() const { return m_rows * m_cols; }
510  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return m_data; }
511  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return m_data; }
512 };
513 template <typename T, int Size, int Rows, int Cols>
514 struct use_default_move {
515  static constexpr bool DynamicObject = Size == Dynamic;
516  static constexpr bool TrivialObject =
517  (!NumTraits<T>::RequireInitialization) && (Rows >= 0) && (Cols >= 0) && (Size == Rows * Cols);
518  static constexpr bool value = DynamicObject || TrivialObject;
519 };
520 } // end namespace internal
521 
534 template <typename T, int Size, int Rows, int Cols, int Options,
535  bool Trivial = internal::use_default_move<T, Size, Rows, Cols>::value>
536 class DenseStorage : public internal::DenseStorage_impl<T, Size, Rows, Cols, Options> {
537  using Base = internal::DenseStorage_impl<T, Size, Rows, Cols, Options>;
538 
539  public:
540  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage() = default;
541  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(const DenseStorage&) = default;
542  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(Index size, Index rows, Index cols)
543  : Base(size, rows, cols) {}
544  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(const DenseStorage&) = default;
545  // if DenseStorage meets the requirements of use_default_move, then use the move construction and move assignment
546  // operation defined in DenseStorage_impl, or the compiler-generated version if none is defined
547  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(DenseStorage&&) = default;
548  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(DenseStorage&&) = default;
549 };
550 template <typename T, int Size, int Rows, int Cols, int Options>
551 class DenseStorage<T, Size, Rows, Cols, Options, false>
552  : public internal::DenseStorage_impl<T, Size, Rows, Cols, Options> {
553  using Base = internal::DenseStorage_impl<T, Size, Rows, Cols, Options>;
554 
555  public:
556  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage() = default;
557  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(const DenseStorage&) = default;
558  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(Index size, Index rows, Index cols)
559  : Base(size, rows, cols) {}
560  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(const DenseStorage&) = default;
561  // if DenseStorage does not meet the requirements of use_default_move, then defer to the copy construction and copy
562  // assignment behavior
563  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage(DenseStorage&& other)
564  : DenseStorage(static_cast<const DenseStorage&>(other)) {}
565  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseStorage& operator=(DenseStorage&& other) {
566  *this = other;
567  return *this;
568  }
569 };
570 
571 } // end namespace Eigen
572 
573 #endif // EIGEN_MATRIX_H
Definition: Constants.h:324
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
std::enable_if_t< std::is_base_of< DenseBase< std::decay_t< DerivedA > >, std::decay_t< DerivedA > >::value &&std::is_base_of< DenseBase< std::decay_t< DerivedB > >, std::decay_t< DerivedB > >::value, void > swap(DerivedA &&a, DerivedB &&b)
Definition: DenseBase.h:667
const int Dynamic
Definition: Constants.h:25