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