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