Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
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) X; EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
17 #else
18  #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X)
19 #endif
20 
21 #include "./InternalHeaderCheck.h"
22 
23 namespace Eigen {
24 
25 namespace internal {
26 
27 struct constructor_without_unaligned_array_assert {};
28 
29 template<typename T, int Size>
30 EIGEN_DEVICE_FUNC
31 void check_static_allocation_size()
32 {
33  // if EIGEN_STACK_ALLOCATION_LIMIT is defined to 0, then no limit
34  #if EIGEN_STACK_ALLOCATION_LIMIT
35  EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
36  #endif
37 }
38 
43 template <typename T, int Size, int MatrixOrArrayOptions,
44  int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
45  : compute_default_alignment<T,Size>::value >
46 struct plain_array
47 {
48  T array[Size];
49 
50  EIGEN_DEVICE_FUNC
51  plain_array()
52  {
53  check_static_allocation_size<T,Size>();
54  }
55 
56  EIGEN_DEVICE_FUNC
57  plain_array(constructor_without_unaligned_array_assert)
58  {
59  check_static_allocation_size<T,Size>();
60  }
61 };
62 
63 #if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
64  #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
65 #elif EIGEN_COMP_GNUC
66  // GCC 4.7 is too aggressive in its optimizations and remove the alignment test based on the fact the array is declared to be aligned.
67  // See this bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900
68  // Hiding the origin of the array pointer behind a function argument seems to do the trick even if the function is inlined:
69  template<typename PtrType>
70  EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) { return array; }
71  #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
72  eigen_assert((internal::is_constant_evaluated() \
73  || (internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (sizemask)) == 0) \
74  && "this assertion is explained here: " \
75  "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
76  " **** READ THIS WEB PAGE !!! ****");
77 #else
78  #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
79  eigen_assert((internal::is_constant_evaluated() || (internal::UIntPtr(array) & (sizemask)) == 0) \
80  && "this assertion is explained here: " \
81  "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
82  " **** READ THIS WEB PAGE !!! ****");
83 #endif
84 
85 template <typename T, int Size, int MatrixOrArrayOptions>
86 struct plain_array<T, Size, MatrixOrArrayOptions, 8>
87 {
88  EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size];
89 
90  EIGEN_DEVICE_FUNC
91  plain_array()
92  {
93  EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7);
94  check_static_allocation_size<T,Size>();
95  }
96 
97  EIGEN_DEVICE_FUNC
98  plain_array(constructor_without_unaligned_array_assert)
99  {
100  check_static_allocation_size<T,Size>();
101  }
102 };
103 
104 template <typename T, int Size, int MatrixOrArrayOptions>
105 struct plain_array<T, Size, MatrixOrArrayOptions, 16>
106 {
107  EIGEN_ALIGN_TO_BOUNDARY(16) T array[Size];
108 
109  EIGEN_DEVICE_FUNC
110  plain_array()
111  {
112  EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15);
113  check_static_allocation_size<T,Size>();
114  }
115 
116  EIGEN_DEVICE_FUNC
117  plain_array(constructor_without_unaligned_array_assert)
118  {
119  check_static_allocation_size<T,Size>();
120  }
121 };
122 
123 template <typename T, int Size, int MatrixOrArrayOptions>
124 struct plain_array<T, Size, MatrixOrArrayOptions, 32>
125 {
126  EIGEN_ALIGN_TO_BOUNDARY(32) T array[Size];
127 
128  EIGEN_DEVICE_FUNC
129  plain_array()
130  {
131  EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31);
132  check_static_allocation_size<T,Size>();
133  }
134 
135  EIGEN_DEVICE_FUNC
136  plain_array(constructor_without_unaligned_array_assert)
137  {
138  check_static_allocation_size<T,Size>();
139  }
140 };
141 
142 template <typename T, int Size, int MatrixOrArrayOptions>
143 struct plain_array<T, Size, MatrixOrArrayOptions, 64>
144 {
145  EIGEN_ALIGN_TO_BOUNDARY(64) T array[Size];
146 
147  EIGEN_DEVICE_FUNC
148  plain_array()
149  {
150  EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(63);
151  check_static_allocation_size<T,Size>();
152  }
153 
154  EIGEN_DEVICE_FUNC
155  plain_array(constructor_without_unaligned_array_assert)
156  {
157  check_static_allocation_size<T,Size>();
158  }
159 };
160 
161 template <typename T, int MatrixOrArrayOptions, int Alignment>
162 struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
163 {
164  T array[1];
165  EIGEN_DEVICE_FUNC plain_array() {}
166  EIGEN_DEVICE_FUNC plain_array(constructor_without_unaligned_array_assert) {}
167 };
168 
169 struct plain_array_helper {
170  template<typename T, int Size, int MatrixOrArrayOptions, int Alignment>
171  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
172  static void copy(const plain_array<T, Size, MatrixOrArrayOptions, Alignment>& src, const Eigen::Index size,
173  plain_array<T, Size, MatrixOrArrayOptions, Alignment>& dst) {
174  smart_copy(src.array, src.array + size, dst.array);
175  }
176 
177  template<typename T, int Size, int MatrixOrArrayOptions, int Alignment>
178  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
179  static void swap(plain_array<T, Size, MatrixOrArrayOptions, Alignment>& a, const Eigen::Index a_size,
180  plain_array<T, Size, MatrixOrArrayOptions, Alignment>& b, const Eigen::Index b_size) {
181  if (a_size < b_size) {
182  std::swap_ranges(b.array, b.array + a_size, a.array);
183  smart_move(b.array + a_size, b.array + b_size, a.array + a_size);
184  } else if (a_size > b_size) {
185  std::swap_ranges(a.array, a.array + b_size, b.array);
186  smart_move(a.array + b_size, a.array + a_size, b.array + b_size);
187  } else {
188  std::swap_ranges(a.array, a.array + a_size, b.array);
189  }
190  }
191 };
192 
193 } // end namespace internal
194 
207 template<typename T, int Size, int Rows_, int Cols_, int Options_> class DenseStorage;
208 
209 // purely fixed-size matrix
210 template<typename T, int Size, int Rows_, int Cols_, int Options_> class DenseStorage
211 {
212  internal::plain_array<T,Size,Options_> m_data;
213  public:
214  EIGEN_DEVICE_FUNC DenseStorage() {
215  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
216  }
217  EIGEN_DEVICE_FUNC
218  explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
219  : m_data(internal::constructor_without_unaligned_array_assert()) {}
220 #if defined(EIGEN_DENSE_STORAGE_CTOR_PLUGIN)
221  EIGEN_DEVICE_FUNC
222  DenseStorage(const DenseStorage& other) : m_data(other.m_data) {
223  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
224  }
225 #else
226  EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) = default;
227 #endif
228  EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) = default;
229  EIGEN_DEVICE_FUNC DenseStorage(DenseStorage&&) = default;
230  EIGEN_DEVICE_FUNC DenseStorage& operator=(DenseStorage&&) = default;
231  EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) {
232  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
233  eigen_internal_assert(size==rows*cols && rows==Rows_ && cols==Cols_);
234  EIGEN_UNUSED_VARIABLE(size);
235  EIGEN_UNUSED_VARIABLE(rows);
236  EIGEN_UNUSED_VARIABLE(cols);
237  }
238  EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
239  numext::swap(m_data, other.m_data);
240  }
241  EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return Rows_;}
242  EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) EIGEN_NOEXCEPT {return Cols_;}
243  EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {}
244  EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {}
245  EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
246  EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
247 };
248 
249 // null matrix
250 template<typename T, int Rows_, int Cols_, int Options_> class DenseStorage<T, 0, Rows_, Cols_, Options_>
251 {
252  public:
253  EIGEN_DEVICE_FUNC DenseStorage() {}
254  EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) {}
255  EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) {}
256  EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) { return *this; }
257  EIGEN_DEVICE_FUNC DenseStorage(Index,Index,Index) {}
258  EIGEN_DEVICE_FUNC void swap(DenseStorage& ) {}
259  EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return Rows_;}
260  EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) EIGEN_NOEXCEPT {return Cols_;}
261  EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {}
262  EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {}
263  EIGEN_DEVICE_FUNC const T *data() const { return 0; }
264  EIGEN_DEVICE_FUNC T *data() { return 0; }
265 };
266 
267 // more specializations for null matrices; these are necessary to resolve ambiguities
268 template<typename T, int Options_> class DenseStorage<T, 0, Dynamic, Dynamic, Options_>
269 : public DenseStorage<T, 0, 0, 0, Options_> { };
270 
271 template<typename T, int Rows_, int Options_> class DenseStorage<T, 0, Rows_, Dynamic, Options_>
272 : public DenseStorage<T, 0, 0, 0, Options_> { };
273 
274 template<typename T, int Cols_, int Options_> class DenseStorage<T, 0, Dynamic, Cols_, Options_>
275 : public DenseStorage<T, 0, 0, 0, Options_> { };
276 
277 // dynamic-size matrix with fixed-size storage
278 template<typename T, int Size, int Options_> class DenseStorage<T, Size, Dynamic, Dynamic, Options_>
279 {
280  internal::plain_array<T,Size,Options_> m_data;
281  Index m_rows;
282  Index m_cols;
283  public:
284  EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {}
285  EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
286  : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
287  EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
288  : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows), m_cols(other.m_cols)
289  {
290  internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data);
291  }
292  EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
293  {
294  if (this != &other)
295  {
296  m_rows = other.m_rows;
297  m_cols = other.m_cols;
298  internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data);
299  }
300  return *this;
301  }
302  EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index cols) : m_rows(rows), m_cols(cols) {}
303  EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
304  {
305  internal::plain_array_helper::swap(m_data, m_rows * m_cols, other.m_data, other.m_rows * other.m_cols);
306  numext::swap(m_rows,other.m_rows);
307  numext::swap(m_cols,other.m_cols);
308  }
309  EIGEN_DEVICE_FUNC Index rows() const {return m_rows;}
310  EIGEN_DEVICE_FUNC Index cols() const {return m_cols;}
311  EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; }
312  EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; }
313  EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
314  EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
315 };
316 
317 // dynamic-size matrix with fixed-size storage and fixed width
318 template<typename T, int Size, int Cols_, int Options_> class DenseStorage<T, Size, Dynamic, Cols_, Options_>
319 {
320  internal::plain_array<T,Size,Options_> m_data;
321  Index m_rows;
322  public:
323  EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {}
324  EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
325  : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
326  EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
327  : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows)
328  {
329  internal::plain_array_helper::copy(other.m_data, m_rows * Cols_, m_data);
330  }
331 
332  EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
333  {
334  if (this != &other)
335  {
336  m_rows = other.m_rows;
337  internal::plain_array_helper::copy(other.m_data, m_rows * Cols_, m_data);
338  }
339  return *this;
340  }
341  EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index) : m_rows(rows) {}
342  EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
343  {
344  internal::plain_array_helper::swap(m_data, m_rows * Cols_, other.m_data, other.m_rows * Cols_);
345  numext::swap(m_rows, other.m_rows);
346  }
347  EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
348  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols(void) const EIGEN_NOEXCEPT {return Cols_;}
349  EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index) { m_rows = rows; }
350  EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index) { m_rows = rows; }
351  EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
352  EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
353 };
354 
355 // dynamic-size matrix with fixed-size storage and fixed height
356 template<typename T, int Size, int Rows_, int Options_> class DenseStorage<T, Size, Rows_, Dynamic, Options_>
357 {
358  internal::plain_array<T,Size,Options_> m_data;
359  Index m_cols;
360  public:
361  EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {}
362  EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
363  : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
364  EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
365  : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(other.m_cols)
366  {
367  internal::plain_array_helper::copy(other.m_data, Rows_ * m_cols, m_data);
368  }
369  EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
370  {
371  if (this != &other)
372  {
373  m_cols = other.m_cols;
374  internal::plain_array_helper::copy(other.m_data, Rows_ * m_cols, m_data);
375  }
376  return *this;
377  }
378  EIGEN_DEVICE_FUNC DenseStorage(Index, Index, Index cols) : m_cols(cols) {}
379  EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
380  internal::plain_array_helper::swap(m_data, Rows_ * m_cols, other.m_data, Rows_ * other.m_cols);
381  numext::swap(m_cols, other.m_cols);
382  }
383  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows(void) const EIGEN_NOEXCEPT {return Rows_;}
384  EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
385  EIGEN_DEVICE_FUNC void conservativeResize(Index, Index, Index cols) { m_cols = cols; }
386  EIGEN_DEVICE_FUNC void resize(Index, Index, Index cols) { m_cols = cols; }
387  EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
388  EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
389 };
390 
391 // purely dynamic matrix.
392 template<typename T, int Options_> class DenseStorage<T, Dynamic, Dynamic, Dynamic, Options_>
393 {
394  T *m_data;
395  Index m_rows;
396  Index m_cols;
397  public:
398  EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
399  EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
400  : m_data(0), m_rows(0), m_cols(0) {}
401  EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols)
402  : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
403  {
404  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
405  eigen_internal_assert(size==rows*cols && rows>=0 && cols >=0);
406  }
407  EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
408  : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(other.m_rows*other.m_cols))
409  , m_rows(other.m_rows)
410  , m_cols(other.m_cols)
411  {
412  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*m_cols)
413  internal::smart_copy(other.m_data, other.m_data+other.m_rows*other.m_cols, m_data);
414  }
415  EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
416  {
417  if (this != &other)
418  {
419  DenseStorage tmp(other);
420  this->swap(tmp);
421  }
422  return *this;
423  }
424  EIGEN_DEVICE_FUNC
425  DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
426  : m_data(std::move(other.m_data))
427  , m_rows(std::move(other.m_rows))
428  , m_cols(std::move(other.m_cols))
429  {
430  other.m_data = nullptr;
431  other.m_rows = 0;
432  other.m_cols = 0;
433  }
434  EIGEN_DEVICE_FUNC
435  DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
436  {
437  numext::swap(m_data, other.m_data);
438  numext::swap(m_rows, other.m_rows);
439  numext::swap(m_cols, other.m_cols);
440  return *this;
441  }
442  EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, m_rows*m_cols); }
443  EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
444  {
445  numext::swap(m_data,other.m_data);
446  numext::swap(m_rows,other.m_rows);
447  numext::swap(m_cols,other.m_cols);
448  }
449  EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
450  EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
451  void conservativeResize(Index size, Index rows, Index cols)
452  {
453  m_data = internal::conditional_aligned_realloc_new_auto<T,(Options_&DontAlign)==0>(m_data, size, m_rows*m_cols);
454  m_rows = rows;
455  m_cols = cols;
456  }
457  EIGEN_DEVICE_FUNC void resize(Index size, Index rows, Index cols)
458  {
459  if(size != m_rows*m_cols)
460  {
461  internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, m_rows*m_cols);
462  if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
463  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size);
464  else
465  m_data = 0;
466  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
467  }
468  m_rows = rows;
469  m_cols = cols;
470  }
471  EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
472  EIGEN_DEVICE_FUNC T *data() { return m_data; }
473 };
474 
475 // matrix with dynamic width and fixed height (so that matrix has dynamic size).
476 template<typename T, int Rows_, int Options_> class DenseStorage<T, Dynamic, Rows_, Dynamic, Options_>
477 {
478  T *m_data;
479  Index m_cols;
480  public:
481  EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_cols(0) {}
482  explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
483  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)
484  {
485  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
486  eigen_internal_assert(size==rows*cols && rows==Rows_ && cols >=0);
487  EIGEN_UNUSED_VARIABLE(rows);
488  }
489  EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
490  : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(Rows_*other.m_cols))
491  , m_cols(other.m_cols)
492  {
493  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_cols*Rows_)
494  internal::smart_copy(other.m_data, other.m_data+Rows_*m_cols, m_data);
495  }
496  EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
497  {
498  if (this != &other)
499  {
500  DenseStorage tmp(other);
501  this->swap(tmp);
502  }
503  return *this;
504  }
505  EIGEN_DEVICE_FUNC
506  DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
507  : m_data(std::move(other.m_data))
508  , m_cols(std::move(other.m_cols))
509  {
510  other.m_data = nullptr;
511  other.m_cols = 0;
512  }
513  EIGEN_DEVICE_FUNC
514  DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
515  {
516  numext::swap(m_data, other.m_data);
517  numext::swap(m_cols, other.m_cols);
518  return *this;
519  }
520  EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, Rows_*m_cols); }
521  EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
522  numext::swap(m_data,other.m_data);
523  numext::swap(m_cols,other.m_cols);
524  }
525  EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return Rows_;}
526  EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
527  EIGEN_DEVICE_FUNC void conservativeResize(Index size, Index, Index cols)
528  {
529  m_data = internal::conditional_aligned_realloc_new_auto<T,(Options_&DontAlign)==0>(m_data, size, Rows_*m_cols);
530  m_cols = cols;
531  }
532  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index, Index cols)
533  {
534  if(size != Rows_*m_cols)
535  {
536  internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, Rows_*m_cols);
537  if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
538  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size);
539  else
540  m_data = 0;
541  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
542  }
543  m_cols = cols;
544  }
545  EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
546  EIGEN_DEVICE_FUNC T *data() { return m_data; }
547 };
548 
549 // matrix with dynamic height and fixed width (so that matrix has dynamic size).
550 template<typename T, int Cols_, int Options_> class DenseStorage<T, Dynamic, Dynamic, Cols_, Options_>
551 {
552  T *m_data;
553  Index m_rows;
554  public:
555  EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0) {}
556  explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
557  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)
558  {
559  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
560  eigen_internal_assert(size==rows*cols && rows>=0 && cols == Cols_);
561  EIGEN_UNUSED_VARIABLE(cols);
562  }
563  EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
564  : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(other.m_rows*Cols_))
565  , m_rows(other.m_rows)
566  {
567  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*Cols_)
568  internal::smart_copy(other.m_data, other.m_data+other.m_rows*Cols_, m_data);
569  }
570  EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
571  {
572  if (this != &other)
573  {
574  DenseStorage tmp(other);
575  this->swap(tmp);
576  }
577  return *this;
578  }
579  EIGEN_DEVICE_FUNC
580  DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
581  : m_data(std::move(other.m_data))
582  , m_rows(std::move(other.m_rows))
583  {
584  other.m_data = nullptr;
585  other.m_rows = 0;
586  }
587  EIGEN_DEVICE_FUNC
588  DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
589  {
590  numext::swap(m_data, other.m_data);
591  numext::swap(m_rows, other.m_rows);
592  return *this;
593  }
594  EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, Cols_*m_rows); }
595  EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
596  numext::swap(m_data,other.m_data);
597  numext::swap(m_rows,other.m_rows);
598  }
599  EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
600  EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) {return Cols_;}
601  void conservativeResize(Index size, Index rows, Index)
602  {
603  m_data = internal::conditional_aligned_realloc_new_auto<T,(Options_&DontAlign)==0>(m_data, size, m_rows*Cols_);
604  m_rows = rows;
605  }
606  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index rows, Index)
607  {
608  if(size != m_rows*Cols_)
609  {
610  internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, Cols_*m_rows);
611  if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
612  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size);
613  else
614  m_data = 0;
615  EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
616  }
617  m_rows = rows;
618  }
619  EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
620  EIGEN_DEVICE_FUNC T *data() { return m_data; }
621 };
622 
623 } // end namespace Eigen
624 
625 #endif // EIGEN_MATRIX_H
@ DontAlign
Definition: Constants.h:327
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59