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