![]() |
Eigen
3.3.3
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> 00005 // Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com> 00006 // Copyright (C) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com> 00007 // 00008 // This Source Code Form is subject to the terms of the Mozilla 00009 // Public License v. 2.0. If a copy of the MPL was not distributed 00010 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00011 00012 #ifndef EIGEN_MATRIXSTORAGE_H 00013 #define EIGEN_MATRIXSTORAGE_H 00014 00015 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN 00016 #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) X; EIGEN_DENSE_STORAGE_CTOR_PLUGIN; 00017 #else 00018 #define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) 00019 #endif 00020 00021 namespace Eigen { 00022 00023 namespace internal { 00024 00025 struct constructor_without_unaligned_array_assert {}; 00026 00027 template<typename T, int Size> 00028 EIGEN_DEVICE_FUNC 00029 void check_static_allocation_size() 00030 { 00031 // if EIGEN_STACK_ALLOCATION_LIMIT is defined to 0, then no limit 00032 #if EIGEN_STACK_ALLOCATION_LIMIT 00033 EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG); 00034 #endif 00035 } 00036 00041 template <typename T, int Size, int MatrixOrArrayOptions, 00042 int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0 00043 : compute_default_alignment<T,Size>::value > 00044 struct plain_array 00045 { 00046 T array[Size]; 00047 00048 EIGEN_DEVICE_FUNC 00049 plain_array() 00050 { 00051 check_static_allocation_size<T,Size>(); 00052 } 00053 00054 EIGEN_DEVICE_FUNC 00055 plain_array(constructor_without_unaligned_array_assert) 00056 { 00057 check_static_allocation_size<T,Size>(); 00058 } 00059 }; 00060 00061 #if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT) 00062 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) 00063 #elif EIGEN_GNUC_AT_LEAST(4,7) 00064 // GCC 4.7 is too aggressive in its optimizations and remove the alignement test based on the fact the array is declared to be aligned. 00065 // See this bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900 00066 // Hiding the origin of the array pointer behind a function argument seems to do the trick even if the function is inlined: 00067 template<typename PtrType> 00068 EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) { return array; } 00069 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \ 00070 eigen_assert((internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (sizemask)) == 0 \ 00071 && "this assertion is explained here: " \ 00072 "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \ 00073 " **** READ THIS WEB PAGE !!! ****"); 00074 #else 00075 #define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \ 00076 eigen_assert((internal::UIntPtr(array) & (sizemask)) == 0 \ 00077 && "this assertion is explained here: " \ 00078 "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \ 00079 " **** READ THIS WEB PAGE !!! ****"); 00080 #endif 00081 00082 template <typename T, int Size, int MatrixOrArrayOptions> 00083 struct plain_array<T, Size, MatrixOrArrayOptions, 8> 00084 { 00085 EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size]; 00086 00087 EIGEN_DEVICE_FUNC 00088 plain_array() 00089 { 00090 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7); 00091 check_static_allocation_size<T,Size>(); 00092 } 00093 00094 EIGEN_DEVICE_FUNC 00095 plain_array(constructor_without_unaligned_array_assert) 00096 { 00097 check_static_allocation_size<T,Size>(); 00098 } 00099 }; 00100 00101 template <typename T, int Size, int MatrixOrArrayOptions> 00102 struct plain_array<T, Size, MatrixOrArrayOptions, 16> 00103 { 00104 EIGEN_ALIGN_TO_BOUNDARY(16) T array[Size]; 00105 00106 EIGEN_DEVICE_FUNC 00107 plain_array() 00108 { 00109 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15); 00110 check_static_allocation_size<T,Size>(); 00111 } 00112 00113 EIGEN_DEVICE_FUNC 00114 plain_array(constructor_without_unaligned_array_assert) 00115 { 00116 check_static_allocation_size<T,Size>(); 00117 } 00118 }; 00119 00120 template <typename T, int Size, int MatrixOrArrayOptions> 00121 struct plain_array<T, Size, MatrixOrArrayOptions, 32> 00122 { 00123 EIGEN_ALIGN_TO_BOUNDARY(32) T array[Size]; 00124 00125 EIGEN_DEVICE_FUNC 00126 plain_array() 00127 { 00128 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31); 00129 check_static_allocation_size<T,Size>(); 00130 } 00131 00132 EIGEN_DEVICE_FUNC 00133 plain_array(constructor_without_unaligned_array_assert) 00134 { 00135 check_static_allocation_size<T,Size>(); 00136 } 00137 }; 00138 00139 template <typename T, int Size, int MatrixOrArrayOptions> 00140 struct plain_array<T, Size, MatrixOrArrayOptions, 64> 00141 { 00142 EIGEN_ALIGN_TO_BOUNDARY(64) T array[Size]; 00143 00144 EIGEN_DEVICE_FUNC 00145 plain_array() 00146 { 00147 EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(63); 00148 check_static_allocation_size<T,Size>(); 00149 } 00150 00151 EIGEN_DEVICE_FUNC 00152 plain_array(constructor_without_unaligned_array_assert) 00153 { 00154 check_static_allocation_size<T,Size>(); 00155 } 00156 }; 00157 00158 template <typename T, int MatrixOrArrayOptions, int Alignment> 00159 struct plain_array<T, 0, MatrixOrArrayOptions, Alignment> 00160 { 00161 T array[1]; 00162 EIGEN_DEVICE_FUNC plain_array() {} 00163 EIGEN_DEVICE_FUNC plain_array(constructor_without_unaligned_array_assert) {} 00164 }; 00165 00166 } // end namespace internal 00167 00180 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage; 00181 00182 // purely fixed-size matrix 00183 template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage 00184 { 00185 internal::plain_array<T,Size,_Options> m_data; 00186 public: 00187 EIGEN_DEVICE_FUNC DenseStorage() { 00188 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size) 00189 } 00190 EIGEN_DEVICE_FUNC 00191 explicit DenseStorage(internal::constructor_without_unaligned_array_assert) 00192 : m_data(internal::constructor_without_unaligned_array_assert()) {} 00193 EIGEN_DEVICE_FUNC 00194 DenseStorage(const DenseStorage& other) : m_data(other.m_data) { 00195 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size) 00196 } 00197 EIGEN_DEVICE_FUNC 00198 DenseStorage& operator=(const DenseStorage& other) 00199 { 00200 if (this != &other) m_data = other.m_data; 00201 return *this; 00202 } 00203 EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) { 00204 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) 00205 eigen_internal_assert(size==rows*cols && rows==_Rows && cols==_Cols); 00206 EIGEN_UNUSED_VARIABLE(size); 00207 EIGEN_UNUSED_VARIABLE(rows); 00208 EIGEN_UNUSED_VARIABLE(cols); 00209 } 00210 EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { std::swap(m_data,other.m_data); } 00211 EIGEN_DEVICE_FUNC static Index rows(void) {return _Rows;} 00212 EIGEN_DEVICE_FUNC static Index cols(void) {return _Cols;} 00213 EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {} 00214 EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {} 00215 EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; } 00216 EIGEN_DEVICE_FUNC T *data() { return m_data.array; } 00217 }; 00218 00219 // null matrix 00220 template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options> 00221 { 00222 public: 00223 EIGEN_DEVICE_FUNC DenseStorage() {} 00224 EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) {} 00225 EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) {} 00226 EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) { return *this; } 00227 EIGEN_DEVICE_FUNC DenseStorage(Index,Index,Index) {} 00228 EIGEN_DEVICE_FUNC void swap(DenseStorage& ) {} 00229 EIGEN_DEVICE_FUNC static Index rows(void) {return _Rows;} 00230 EIGEN_DEVICE_FUNC static Index cols(void) {return _Cols;} 00231 EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {} 00232 EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {} 00233 EIGEN_DEVICE_FUNC const T *data() const { return 0; } 00234 EIGEN_DEVICE_FUNC T *data() { return 0; } 00235 }; 00236 00237 // more specializations for null matrices; these are necessary to resolve ambiguities 00238 template<typename T, int _Options> class DenseStorage<T, 0, Dynamic, Dynamic, _Options> 00239 : public DenseStorage<T, 0, 0, 0, _Options> { }; 00240 00241 template<typename T, int _Rows, int _Options> class DenseStorage<T, 0, _Rows, Dynamic, _Options> 00242 : public DenseStorage<T, 0, 0, 0, _Options> { }; 00243 00244 template<typename T, int _Cols, int _Options> class DenseStorage<T, 0, Dynamic, _Cols, _Options> 00245 : public DenseStorage<T, 0, 0, 0, _Options> { }; 00246 00247 // dynamic-size matrix with fixed-size storage 00248 template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options> 00249 { 00250 internal::plain_array<T,Size,_Options> m_data; 00251 Index m_rows; 00252 Index m_cols; 00253 public: 00254 EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {} 00255 EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) 00256 : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {} 00257 EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows), m_cols(other.m_cols) {} 00258 EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) 00259 { 00260 if (this != &other) 00261 { 00262 m_data = other.m_data; 00263 m_rows = other.m_rows; 00264 m_cols = other.m_cols; 00265 } 00266 return *this; 00267 } 00268 EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index cols) : m_rows(rows), m_cols(cols) {} 00269 EIGEN_DEVICE_FUNC void swap(DenseStorage& other) 00270 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); } 00271 EIGEN_DEVICE_FUNC Index rows() const {return m_rows;} 00272 EIGEN_DEVICE_FUNC Index cols() const {return m_cols;} 00273 EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; } 00274 EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; } 00275 EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; } 00276 EIGEN_DEVICE_FUNC T *data() { return m_data.array; } 00277 }; 00278 00279 // dynamic-size matrix with fixed-size storage and fixed width 00280 template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options> 00281 { 00282 internal::plain_array<T,Size,_Options> m_data; 00283 Index m_rows; 00284 public: 00285 EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {} 00286 EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) 00287 : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {} 00288 EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows) {} 00289 EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) 00290 { 00291 if (this != &other) 00292 { 00293 m_data = other.m_data; 00294 m_rows = other.m_rows; 00295 } 00296 return *this; 00297 } 00298 EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index) : m_rows(rows) {} 00299 EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); } 00300 EIGEN_DEVICE_FUNC Index rows(void) const {return m_rows;} 00301 EIGEN_DEVICE_FUNC Index cols(void) const {return _Cols;} 00302 EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index) { m_rows = rows; } 00303 EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index) { m_rows = rows; } 00304 EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; } 00305 EIGEN_DEVICE_FUNC T *data() { return m_data.array; } 00306 }; 00307 00308 // dynamic-size matrix with fixed-size storage and fixed height 00309 template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options> 00310 { 00311 internal::plain_array<T,Size,_Options> m_data; 00312 Index m_cols; 00313 public: 00314 EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {} 00315 EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) 00316 : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {} 00317 EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_cols(other.m_cols) {} 00318 EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) 00319 { 00320 if (this != &other) 00321 { 00322 m_data = other.m_data; 00323 m_cols = other.m_cols; 00324 } 00325 return *this; 00326 } 00327 EIGEN_DEVICE_FUNC DenseStorage(Index, Index, Index cols) : m_cols(cols) {} 00328 EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); } 00329 EIGEN_DEVICE_FUNC Index rows(void) const {return _Rows;} 00330 EIGEN_DEVICE_FUNC Index cols(void) const {return m_cols;} 00331 void conservativeResize(Index, Index, Index cols) { m_cols = cols; } 00332 void resize(Index, Index, Index cols) { m_cols = cols; } 00333 EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; } 00334 EIGEN_DEVICE_FUNC T *data() { return m_data.array; } 00335 }; 00336 00337 // purely dynamic matrix. 00338 template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options> 00339 { 00340 T *m_data; 00341 Index m_rows; 00342 Index m_cols; 00343 public: 00344 EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0), m_cols(0) {} 00345 EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) 00346 : m_data(0), m_rows(0), m_cols(0) {} 00347 EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) 00348 : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols) 00349 { 00350 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) 00351 eigen_internal_assert(size==rows*cols && rows>=0 && cols >=0); 00352 } 00353 EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) 00354 : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*other.m_cols)) 00355 , m_rows(other.m_rows) 00356 , m_cols(other.m_cols) 00357 { 00358 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*m_cols) 00359 internal::smart_copy(other.m_data, other.m_data+other.m_rows*other.m_cols, m_data); 00360 } 00361 EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) 00362 { 00363 if (this != &other) 00364 { 00365 DenseStorage tmp(other); 00366 this->swap(tmp); 00367 } 00368 return *this; 00369 } 00370 #if EIGEN_HAS_RVALUE_REFERENCES 00371 EIGEN_DEVICE_FUNC 00372 DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT 00373 : m_data(std::move(other.m_data)) 00374 , m_rows(std::move(other.m_rows)) 00375 , m_cols(std::move(other.m_cols)) 00376 { 00377 other.m_data = nullptr; 00378 other.m_rows = 0; 00379 other.m_cols = 0; 00380 } 00381 EIGEN_DEVICE_FUNC 00382 DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT 00383 { 00384 using std::swap; 00385 swap(m_data, other.m_data); 00386 swap(m_rows, other.m_rows); 00387 swap(m_cols, other.m_cols); 00388 return *this; 00389 } 00390 #endif 00391 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); } 00392 EIGEN_DEVICE_FUNC void swap(DenseStorage& other) 00393 { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); } 00394 EIGEN_DEVICE_FUNC Index rows(void) const {return m_rows;} 00395 EIGEN_DEVICE_FUNC Index cols(void) const {return m_cols;} 00396 void conservativeResize(Index size, Index rows, Index cols) 00397 { 00398 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols); 00399 m_rows = rows; 00400 m_cols = cols; 00401 } 00402 EIGEN_DEVICE_FUNC void resize(Index size, Index rows, Index cols) 00403 { 00404 if(size != m_rows*m_cols) 00405 { 00406 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); 00407 if (size) 00408 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size); 00409 else 00410 m_data = 0; 00411 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) 00412 } 00413 m_rows = rows; 00414 m_cols = cols; 00415 } 00416 EIGEN_DEVICE_FUNC const T *data() const { return m_data; } 00417 EIGEN_DEVICE_FUNC T *data() { return m_data; } 00418 }; 00419 00420 // matrix with dynamic width and fixed height (so that matrix has dynamic size). 00421 template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options> 00422 { 00423 T *m_data; 00424 Index m_cols; 00425 public: 00426 EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_cols(0) {} 00427 explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {} 00428 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) 00429 { 00430 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) 00431 eigen_internal_assert(size==rows*cols && rows==_Rows && cols >=0); 00432 EIGEN_UNUSED_VARIABLE(rows); 00433 } 00434 EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) 00435 : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(_Rows*other.m_cols)) 00436 , m_cols(other.m_cols) 00437 { 00438 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_cols*_Rows) 00439 internal::smart_copy(other.m_data, other.m_data+_Rows*m_cols, m_data); 00440 } 00441 EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) 00442 { 00443 if (this != &other) 00444 { 00445 DenseStorage tmp(other); 00446 this->swap(tmp); 00447 } 00448 return *this; 00449 } 00450 #if EIGEN_HAS_RVALUE_REFERENCES 00451 EIGEN_DEVICE_FUNC 00452 DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT 00453 : m_data(std::move(other.m_data)) 00454 , m_cols(std::move(other.m_cols)) 00455 { 00456 other.m_data = nullptr; 00457 other.m_cols = 0; 00458 } 00459 EIGEN_DEVICE_FUNC 00460 DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT 00461 { 00462 using std::swap; 00463 swap(m_data, other.m_data); 00464 swap(m_cols, other.m_cols); 00465 return *this; 00466 } 00467 #endif 00468 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); } 00469 EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); } 00470 EIGEN_DEVICE_FUNC static Index rows(void) {return _Rows;} 00471 EIGEN_DEVICE_FUNC Index cols(void) const {return m_cols;} 00472 EIGEN_DEVICE_FUNC void conservativeResize(Index size, Index, Index cols) 00473 { 00474 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols); 00475 m_cols = cols; 00476 } 00477 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index, Index cols) 00478 { 00479 if(size != _Rows*m_cols) 00480 { 00481 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); 00482 if (size) 00483 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size); 00484 else 00485 m_data = 0; 00486 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) 00487 } 00488 m_cols = cols; 00489 } 00490 EIGEN_DEVICE_FUNC const T *data() const { return m_data; } 00491 EIGEN_DEVICE_FUNC T *data() { return m_data; } 00492 }; 00493 00494 // matrix with dynamic height and fixed width (so that matrix has dynamic size). 00495 template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options> 00496 { 00497 T *m_data; 00498 Index m_rows; 00499 public: 00500 EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0) {} 00501 explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {} 00502 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) 00503 { 00504 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) 00505 eigen_internal_assert(size==rows*cols && rows>=0 && cols == _Cols); 00506 EIGEN_UNUSED_VARIABLE(cols); 00507 } 00508 EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) 00509 : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*_Cols)) 00510 , m_rows(other.m_rows) 00511 { 00512 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*_Cols) 00513 internal::smart_copy(other.m_data, other.m_data+other.m_rows*_Cols, m_data); 00514 } 00515 EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) 00516 { 00517 if (this != &other) 00518 { 00519 DenseStorage tmp(other); 00520 this->swap(tmp); 00521 } 00522 return *this; 00523 } 00524 #if EIGEN_HAS_RVALUE_REFERENCES 00525 EIGEN_DEVICE_FUNC 00526 DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT 00527 : m_data(std::move(other.m_data)) 00528 , m_rows(std::move(other.m_rows)) 00529 { 00530 other.m_data = nullptr; 00531 other.m_rows = 0; 00532 } 00533 EIGEN_DEVICE_FUNC 00534 DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT 00535 { 00536 using std::swap; 00537 swap(m_data, other.m_data); 00538 swap(m_rows, other.m_rows); 00539 return *this; 00540 } 00541 #endif 00542 EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); } 00543 EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); } 00544 EIGEN_DEVICE_FUNC Index rows(void) const {return m_rows;} 00545 EIGEN_DEVICE_FUNC static Index cols(void) {return _Cols;} 00546 void conservativeResize(Index size, Index rows, Index) 00547 { 00548 m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols); 00549 m_rows = rows; 00550 } 00551 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index rows, Index) 00552 { 00553 if(size != m_rows*_Cols) 00554 { 00555 internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); 00556 if (size) 00557 m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size); 00558 else 00559 m_data = 0; 00560 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) 00561 } 00562 m_rows = rows; 00563 } 00564 EIGEN_DEVICE_FUNC const T *data() const { return m_data; } 00565 EIGEN_DEVICE_FUNC T *data() { return m_data; } 00566 }; 00567 00568 } // end namespace Eigen 00569 00570 #endif // EIGEN_MATRIX_H