User | Revision | Line number | New contents of line |
ykuroda |
0:13a5d365ba16
|
1
|
// This file is part of Eigen, a lightweight C++ template library
|
ykuroda |
0:13a5d365ba16
|
2
|
// for linear algebra.
|
ykuroda |
0:13a5d365ba16
|
3
|
//
|
ykuroda |
0:13a5d365ba16
|
4
|
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
ykuroda |
0:13a5d365ba16
|
5
|
// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
ykuroda |
0:13a5d365ba16
|
6
|
// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
|
ykuroda |
0:13a5d365ba16
|
7
|
//
|
ykuroda |
0:13a5d365ba16
|
8
|
// This Source Code Form is subject to the terms of the Mozilla
|
ykuroda |
0:13a5d365ba16
|
9
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
ykuroda |
0:13a5d365ba16
|
10
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
ykuroda |
0:13a5d365ba16
|
11
|
|
ykuroda |
0:13a5d365ba16
|
12
|
#ifndef EIGEN_MATRIXSTORAGE_H
|
ykuroda |
0:13a5d365ba16
|
13
|
#define EIGEN_MATRIXSTORAGE_H
|
ykuroda |
0:13a5d365ba16
|
14
|
|
ykuroda |
0:13a5d365ba16
|
15
|
#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
|
ykuroda |
0:13a5d365ba16
|
16
|
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
|
ykuroda |
0:13a5d365ba16
|
17
|
#else
|
ykuroda |
0:13a5d365ba16
|
18
|
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
ykuroda |
0:13a5d365ba16
|
19
|
#endif
|
ykuroda |
0:13a5d365ba16
|
20
|
|
ykuroda |
0:13a5d365ba16
|
21
|
namespace Eigen {
|
ykuroda |
0:13a5d365ba16
|
22
|
|
ykuroda |
0:13a5d365ba16
|
23
|
namespace internal {
|
ykuroda |
0:13a5d365ba16
|
24
|
|
ykuroda |
0:13a5d365ba16
|
25
|
struct constructor_without_unaligned_array_assert {};
|
ykuroda |
0:13a5d365ba16
|
26
|
|
ykuroda |
0:13a5d365ba16
|
27
|
template<typename T, int Size> void check_static_allocation_size()
|
ykuroda |
0:13a5d365ba16
|
28
|
{
|
ykuroda |
0:13a5d365ba16
|
29
|
// if EIGEN_STACK_ALLOCATION_LIMIT is defined to 0, then no limit
|
ykuroda |
0:13a5d365ba16
|
30
|
#if EIGEN_STACK_ALLOCATION_LIMIT
|
ykuroda |
0:13a5d365ba16
|
31
|
EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
|
ykuroda |
0:13a5d365ba16
|
32
|
#endif
|
ykuroda |
0:13a5d365ba16
|
33
|
}
|
ykuroda |
0:13a5d365ba16
|
34
|
|
ykuroda |
0:13a5d365ba16
|
35
|
/** \internal
|
ykuroda |
0:13a5d365ba16
|
36
|
* Static array. If the MatrixOrArrayOptions require auto-alignment, the array will be automatically aligned:
|
ykuroda |
0:13a5d365ba16
|
37
|
* to 16 bytes boundary if the total size is a multiple of 16 bytes.
|
ykuroda |
0:13a5d365ba16
|
38
|
*/
|
ykuroda |
0:13a5d365ba16
|
39
|
template <typename T, int Size, int MatrixOrArrayOptions,
|
ykuroda |
0:13a5d365ba16
|
40
|
int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
|
ykuroda |
0:13a5d365ba16
|
41
|
: (((Size*sizeof(T))%16)==0) ? 16
|
ykuroda |
0:13a5d365ba16
|
42
|
: 0 >
|
ykuroda |
0:13a5d365ba16
|
43
|
struct plain_array
|
ykuroda |
0:13a5d365ba16
|
44
|
{
|
ykuroda |
0:13a5d365ba16
|
45
|
T array[Size];
|
ykuroda |
0:13a5d365ba16
|
46
|
|
ykuroda |
0:13a5d365ba16
|
47
|
plain_array()
|
ykuroda |
0:13a5d365ba16
|
48
|
{
|
ykuroda |
0:13a5d365ba16
|
49
|
check_static_allocation_size<T,Size>();
|
ykuroda |
0:13a5d365ba16
|
50
|
}
|
ykuroda |
0:13a5d365ba16
|
51
|
|
ykuroda |
0:13a5d365ba16
|
52
|
plain_array(constructor_without_unaligned_array_assert)
|
ykuroda |
0:13a5d365ba16
|
53
|
{
|
ykuroda |
0:13a5d365ba16
|
54
|
check_static_allocation_size<T,Size>();
|
ykuroda |
0:13a5d365ba16
|
55
|
}
|
ykuroda |
0:13a5d365ba16
|
56
|
};
|
ykuroda |
0:13a5d365ba16
|
57
|
|
ykuroda |
0:13a5d365ba16
|
58
|
#if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
|
ykuroda |
0:13a5d365ba16
|
59
|
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
|
ykuroda |
0:13a5d365ba16
|
60
|
#elif EIGEN_GNUC_AT_LEAST(4,7)
|
ykuroda |
0:13a5d365ba16
|
61
|
// 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.
|
ykuroda |
0:13a5d365ba16
|
62
|
// See this bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900
|
ykuroda |
0:13a5d365ba16
|
63
|
// Hiding the origin of the array pointer behind a function argument seems to do the trick even if the function is inlined:
|
ykuroda |
0:13a5d365ba16
|
64
|
template<typename PtrType>
|
ykuroda |
0:13a5d365ba16
|
65
|
EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) { return array; }
|
ykuroda |
0:13a5d365ba16
|
66
|
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
|
ykuroda |
0:13a5d365ba16
|
67
|
eigen_assert((reinterpret_cast<size_t>(eigen_unaligned_array_assert_workaround_gcc47(array)) & sizemask) == 0 \
|
ykuroda |
0:13a5d365ba16
|
68
|
&& "this assertion is explained here: " \
|
ykuroda |
0:13a5d365ba16
|
69
|
"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
|
ykuroda |
0:13a5d365ba16
|
70
|
" **** READ THIS WEB PAGE !!! ****");
|
ykuroda |
0:13a5d365ba16
|
71
|
#else
|
ykuroda |
0:13a5d365ba16
|
72
|
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
|
ykuroda |
0:13a5d365ba16
|
73
|
eigen_assert((reinterpret_cast<size_t>(array) & sizemask) == 0 \
|
ykuroda |
0:13a5d365ba16
|
74
|
&& "this assertion is explained here: " \
|
ykuroda |
0:13a5d365ba16
|
75
|
"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
|
ykuroda |
0:13a5d365ba16
|
76
|
" **** READ THIS WEB PAGE !!! ****");
|
ykuroda |
0:13a5d365ba16
|
77
|
#endif
|
ykuroda |
0:13a5d365ba16
|
78
|
|
ykuroda |
0:13a5d365ba16
|
79
|
template <typename T, int Size, int MatrixOrArrayOptions>
|
ykuroda |
0:13a5d365ba16
|
80
|
struct plain_array<T, Size, MatrixOrArrayOptions, 16>
|
ykuroda |
0:13a5d365ba16
|
81
|
{
|
ykuroda |
0:13a5d365ba16
|
82
|
EIGEN_USER_ALIGN16 T array[Size];
|
ykuroda |
0:13a5d365ba16
|
83
|
|
ykuroda |
0:13a5d365ba16
|
84
|
plain_array()
|
ykuroda |
0:13a5d365ba16
|
85
|
{
|
ykuroda |
0:13a5d365ba16
|
86
|
EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(0xf);
|
ykuroda |
0:13a5d365ba16
|
87
|
check_static_allocation_size<T,Size>();
|
ykuroda |
0:13a5d365ba16
|
88
|
}
|
ykuroda |
0:13a5d365ba16
|
89
|
|
ykuroda |
0:13a5d365ba16
|
90
|
plain_array(constructor_without_unaligned_array_assert)
|
ykuroda |
0:13a5d365ba16
|
91
|
{
|
ykuroda |
0:13a5d365ba16
|
92
|
check_static_allocation_size<T,Size>();
|
ykuroda |
0:13a5d365ba16
|
93
|
}
|
ykuroda |
0:13a5d365ba16
|
94
|
};
|
ykuroda |
0:13a5d365ba16
|
95
|
|
ykuroda |
0:13a5d365ba16
|
96
|
template <typename T, int MatrixOrArrayOptions, int Alignment>
|
ykuroda |
0:13a5d365ba16
|
97
|
struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
|
ykuroda |
0:13a5d365ba16
|
98
|
{
|
ykuroda |
0:13a5d365ba16
|
99
|
EIGEN_USER_ALIGN16 T array[1];
|
ykuroda |
0:13a5d365ba16
|
100
|
plain_array() {}
|
ykuroda |
0:13a5d365ba16
|
101
|
plain_array(constructor_without_unaligned_array_assert) {}
|
ykuroda |
0:13a5d365ba16
|
102
|
};
|
ykuroda |
0:13a5d365ba16
|
103
|
|
ykuroda |
0:13a5d365ba16
|
104
|
} // end namespace internal
|
ykuroda |
0:13a5d365ba16
|
105
|
|
ykuroda |
0:13a5d365ba16
|
106
|
/** \internal
|
ykuroda |
0:13a5d365ba16
|
107
|
*
|
ykuroda |
0:13a5d365ba16
|
108
|
* \class DenseStorage
|
ykuroda |
0:13a5d365ba16
|
109
|
* \ingroup Core_Module
|
ykuroda |
0:13a5d365ba16
|
110
|
*
|
ykuroda |
0:13a5d365ba16
|
111
|
* \brief Stores the data of a matrix
|
ykuroda |
0:13a5d365ba16
|
112
|
*
|
ykuroda |
0:13a5d365ba16
|
113
|
* This class stores the data of fixed-size, dynamic-size or mixed matrices
|
ykuroda |
0:13a5d365ba16
|
114
|
* in a way as compact as possible.
|
ykuroda |
0:13a5d365ba16
|
115
|
*
|
ykuroda |
0:13a5d365ba16
|
116
|
* \sa Matrix
|
ykuroda |
0:13a5d365ba16
|
117
|
*/
|
ykuroda |
0:13a5d365ba16
|
118
|
template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage;
|
ykuroda |
0:13a5d365ba16
|
119
|
|
ykuroda |
0:13a5d365ba16
|
120
|
// purely fixed-size matrix
|
ykuroda |
0:13a5d365ba16
|
121
|
template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage
|
ykuroda |
0:13a5d365ba16
|
122
|
{
|
ykuroda |
0:13a5d365ba16
|
123
|
internal::plain_array<T,Size,_Options> m_data;
|
ykuroda |
0:13a5d365ba16
|
124
|
public:
|
ykuroda |
0:13a5d365ba16
|
125
|
DenseStorage() {}
|
ykuroda |
0:13a5d365ba16
|
126
|
DenseStorage(internal::constructor_without_unaligned_array_assert)
|
ykuroda |
0:13a5d365ba16
|
127
|
: m_data(internal::constructor_without_unaligned_array_assert()) {}
|
ykuroda |
0:13a5d365ba16
|
128
|
DenseStorage(const DenseStorage& other) : m_data(other.m_data) {}
|
ykuroda |
0:13a5d365ba16
|
129
|
DenseStorage& operator=(const DenseStorage& other)
|
ykuroda |
0:13a5d365ba16
|
130
|
{
|
ykuroda |
0:13a5d365ba16
|
131
|
if (this != &other) m_data = other.m_data;
|
ykuroda |
0:13a5d365ba16
|
132
|
return *this;
|
ykuroda |
0:13a5d365ba16
|
133
|
}
|
ykuroda |
0:13a5d365ba16
|
134
|
DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
|
ykuroda |
0:13a5d365ba16
|
135
|
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); }
|
ykuroda |
0:13a5d365ba16
|
136
|
static DenseIndex rows(void) {return _Rows;}
|
ykuroda |
0:13a5d365ba16
|
137
|
static DenseIndex cols(void) {return _Cols;}
|
ykuroda |
0:13a5d365ba16
|
138
|
void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
|
ykuroda |
0:13a5d365ba16
|
139
|
void resize(DenseIndex,DenseIndex,DenseIndex) {}
|
ykuroda |
0:13a5d365ba16
|
140
|
const T *data() const { return m_data.array; }
|
ykuroda |
0:13a5d365ba16
|
141
|
T *data() { return m_data.array; }
|
ykuroda |
0:13a5d365ba16
|
142
|
};
|
ykuroda |
0:13a5d365ba16
|
143
|
|
ykuroda |
0:13a5d365ba16
|
144
|
// null matrix
|
ykuroda |
0:13a5d365ba16
|
145
|
template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options>
|
ykuroda |
0:13a5d365ba16
|
146
|
{
|
ykuroda |
0:13a5d365ba16
|
147
|
public:
|
ykuroda |
0:13a5d365ba16
|
148
|
DenseStorage() {}
|
ykuroda |
0:13a5d365ba16
|
149
|
DenseStorage(internal::constructor_without_unaligned_array_assert) {}
|
ykuroda |
0:13a5d365ba16
|
150
|
DenseStorage(const DenseStorage&) {}
|
ykuroda |
0:13a5d365ba16
|
151
|
DenseStorage& operator=(const DenseStorage&) { return *this; }
|
ykuroda |
0:13a5d365ba16
|
152
|
DenseStorage(DenseIndex,DenseIndex,DenseIndex) {}
|
ykuroda |
0:13a5d365ba16
|
153
|
void swap(DenseStorage& ) {}
|
ykuroda |
0:13a5d365ba16
|
154
|
static DenseIndex rows(void) {return _Rows;}
|
ykuroda |
0:13a5d365ba16
|
155
|
static DenseIndex cols(void) {return _Cols;}
|
ykuroda |
0:13a5d365ba16
|
156
|
void conservativeResize(DenseIndex,DenseIndex,DenseIndex) {}
|
ykuroda |
0:13a5d365ba16
|
157
|
void resize(DenseIndex,DenseIndex,DenseIndex) {}
|
ykuroda |
0:13a5d365ba16
|
158
|
const T *data() const { return 0; }
|
ykuroda |
0:13a5d365ba16
|
159
|
T *data() { return 0; }
|
ykuroda |
0:13a5d365ba16
|
160
|
};
|
ykuroda |
0:13a5d365ba16
|
161
|
|
ykuroda |
0:13a5d365ba16
|
162
|
// more specializations for null matrices; these are necessary to resolve ambiguities
|
ykuroda |
0:13a5d365ba16
|
163
|
template<typename T, int _Options> class DenseStorage<T, 0, Dynamic, Dynamic, _Options>
|
ykuroda |
0:13a5d365ba16
|
164
|
: public DenseStorage<T, 0, 0, 0, _Options> { };
|
ykuroda |
0:13a5d365ba16
|
165
|
|
ykuroda |
0:13a5d365ba16
|
166
|
template<typename T, int _Rows, int _Options> class DenseStorage<T, 0, _Rows, Dynamic, _Options>
|
ykuroda |
0:13a5d365ba16
|
167
|
: public DenseStorage<T, 0, 0, 0, _Options> { };
|
ykuroda |
0:13a5d365ba16
|
168
|
|
ykuroda |
0:13a5d365ba16
|
169
|
template<typename T, int _Cols, int _Options> class DenseStorage<T, 0, Dynamic, _Cols, _Options>
|
ykuroda |
0:13a5d365ba16
|
170
|
: public DenseStorage<T, 0, 0, 0, _Options> { };
|
ykuroda |
0:13a5d365ba16
|
171
|
|
ykuroda |
0:13a5d365ba16
|
172
|
// dynamic-size matrix with fixed-size storage
|
ykuroda |
0:13a5d365ba16
|
173
|
template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
|
ykuroda |
0:13a5d365ba16
|
174
|
{
|
ykuroda |
0:13a5d365ba16
|
175
|
internal::plain_array<T,Size,_Options> m_data;
|
ykuroda |
0:13a5d365ba16
|
176
|
DenseIndex m_rows;
|
ykuroda |
0:13a5d365ba16
|
177
|
DenseIndex m_cols;
|
ykuroda |
0:13a5d365ba16
|
178
|
public:
|
ykuroda |
0:13a5d365ba16
|
179
|
DenseStorage() : m_rows(0), m_cols(0) {}
|
ykuroda |
0:13a5d365ba16
|
180
|
DenseStorage(internal::constructor_without_unaligned_array_assert)
|
ykuroda |
0:13a5d365ba16
|
181
|
: m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
|
ykuroda |
0:13a5d365ba16
|
182
|
DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows), m_cols(other.m_cols) {}
|
ykuroda |
0:13a5d365ba16
|
183
|
DenseStorage& operator=(const DenseStorage& other)
|
ykuroda |
0:13a5d365ba16
|
184
|
{
|
ykuroda |
0:13a5d365ba16
|
185
|
if (this != &other)
|
ykuroda |
0:13a5d365ba16
|
186
|
{
|
ykuroda |
0:13a5d365ba16
|
187
|
m_data = other.m_data;
|
ykuroda |
0:13a5d365ba16
|
188
|
m_rows = other.m_rows;
|
ykuroda |
0:13a5d365ba16
|
189
|
m_cols = other.m_cols;
|
ykuroda |
0:13a5d365ba16
|
190
|
}
|
ykuroda |
0:13a5d365ba16
|
191
|
return *this;
|
ykuroda |
0:13a5d365ba16
|
192
|
}
|
ykuroda |
0:13a5d365ba16
|
193
|
DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) : m_rows(nbRows), m_cols(nbCols) {}
|
ykuroda |
0:13a5d365ba16
|
194
|
void swap(DenseStorage& other)
|
ykuroda |
0:13a5d365ba16
|
195
|
{ std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
|
ykuroda |
0:13a5d365ba16
|
196
|
DenseIndex rows() const {return m_rows;}
|
ykuroda |
0:13a5d365ba16
|
197
|
DenseIndex cols() const {return m_cols;}
|
ykuroda |
0:13a5d365ba16
|
198
|
void conservativeResize(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) { m_rows = nbRows; m_cols = nbCols; }
|
ykuroda |
0:13a5d365ba16
|
199
|
void resize(DenseIndex, DenseIndex nbRows, DenseIndex nbCols) { m_rows = nbRows; m_cols = nbCols; }
|
ykuroda |
0:13a5d365ba16
|
200
|
const T *data() const { return m_data.array; }
|
ykuroda |
0:13a5d365ba16
|
201
|
T *data() { return m_data.array; }
|
ykuroda |
0:13a5d365ba16
|
202
|
};
|
ykuroda |
0:13a5d365ba16
|
203
|
|
ykuroda |
0:13a5d365ba16
|
204
|
// dynamic-size matrix with fixed-size storage and fixed width
|
ykuroda |
0:13a5d365ba16
|
205
|
template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options>
|
ykuroda |
0:13a5d365ba16
|
206
|
{
|
ykuroda |
0:13a5d365ba16
|
207
|
internal::plain_array<T,Size,_Options> m_data;
|
ykuroda |
0:13a5d365ba16
|
208
|
DenseIndex m_rows;
|
ykuroda |
0:13a5d365ba16
|
209
|
public:
|
ykuroda |
0:13a5d365ba16
|
210
|
DenseStorage() : m_rows(0) {}
|
ykuroda |
0:13a5d365ba16
|
211
|
DenseStorage(internal::constructor_without_unaligned_array_assert)
|
ykuroda |
0:13a5d365ba16
|
212
|
: m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
|
ykuroda |
0:13a5d365ba16
|
213
|
DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_rows(other.m_rows) {}
|
ykuroda |
0:13a5d365ba16
|
214
|
DenseStorage& operator=(const DenseStorage& other)
|
ykuroda |
0:13a5d365ba16
|
215
|
{
|
ykuroda |
0:13a5d365ba16
|
216
|
if (this != &other)
|
ykuroda |
0:13a5d365ba16
|
217
|
{
|
ykuroda |
0:13a5d365ba16
|
218
|
m_data = other.m_data;
|
ykuroda |
0:13a5d365ba16
|
219
|
m_rows = other.m_rows;
|
ykuroda |
0:13a5d365ba16
|
220
|
}
|
ykuroda |
0:13a5d365ba16
|
221
|
return *this;
|
ykuroda |
0:13a5d365ba16
|
222
|
}
|
ykuroda |
0:13a5d365ba16
|
223
|
DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex) : m_rows(nbRows) {}
|
ykuroda |
0:13a5d365ba16
|
224
|
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
|
ykuroda |
0:13a5d365ba16
|
225
|
DenseIndex rows(void) const {return m_rows;}
|
ykuroda |
0:13a5d365ba16
|
226
|
DenseIndex cols(void) const {return _Cols;}
|
ykuroda |
0:13a5d365ba16
|
227
|
void conservativeResize(DenseIndex, DenseIndex nbRows, DenseIndex) { m_rows = nbRows; }
|
ykuroda |
0:13a5d365ba16
|
228
|
void resize(DenseIndex, DenseIndex nbRows, DenseIndex) { m_rows = nbRows; }
|
ykuroda |
0:13a5d365ba16
|
229
|
const T *data() const { return m_data.array; }
|
ykuroda |
0:13a5d365ba16
|
230
|
T *data() { return m_data.array; }
|
ykuroda |
0:13a5d365ba16
|
231
|
};
|
ykuroda |
0:13a5d365ba16
|
232
|
|
ykuroda |
0:13a5d365ba16
|
233
|
// dynamic-size matrix with fixed-size storage and fixed height
|
ykuroda |
0:13a5d365ba16
|
234
|
template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options>
|
ykuroda |
0:13a5d365ba16
|
235
|
{
|
ykuroda |
0:13a5d365ba16
|
236
|
internal::plain_array<T,Size,_Options> m_data;
|
ykuroda |
0:13a5d365ba16
|
237
|
DenseIndex m_cols;
|
ykuroda |
0:13a5d365ba16
|
238
|
public:
|
ykuroda |
0:13a5d365ba16
|
239
|
DenseStorage() : m_cols(0) {}
|
ykuroda |
0:13a5d365ba16
|
240
|
DenseStorage(internal::constructor_without_unaligned_array_assert)
|
ykuroda |
0:13a5d365ba16
|
241
|
: m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
|
ykuroda |
0:13a5d365ba16
|
242
|
DenseStorage(const DenseStorage& other) : m_data(other.m_data), m_cols(other.m_cols) {}
|
ykuroda |
0:13a5d365ba16
|
243
|
DenseStorage& operator=(const DenseStorage& other)
|
ykuroda |
0:13a5d365ba16
|
244
|
{
|
ykuroda |
0:13a5d365ba16
|
245
|
if (this != &other)
|
ykuroda |
0:13a5d365ba16
|
246
|
{
|
ykuroda |
0:13a5d365ba16
|
247
|
m_data = other.m_data;
|
ykuroda |
0:13a5d365ba16
|
248
|
m_cols = other.m_cols;
|
ykuroda |
0:13a5d365ba16
|
249
|
}
|
ykuroda |
0:13a5d365ba16
|
250
|
return *this;
|
ykuroda |
0:13a5d365ba16
|
251
|
}
|
ykuroda |
0:13a5d365ba16
|
252
|
DenseStorage(DenseIndex, DenseIndex, DenseIndex nbCols) : m_cols(nbCols) {}
|
ykuroda |
0:13a5d365ba16
|
253
|
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
|
ykuroda |
0:13a5d365ba16
|
254
|
DenseIndex rows(void) const {return _Rows;}
|
ykuroda |
0:13a5d365ba16
|
255
|
DenseIndex cols(void) const {return m_cols;}
|
ykuroda |
0:13a5d365ba16
|
256
|
void conservativeResize(DenseIndex, DenseIndex, DenseIndex nbCols) { m_cols = nbCols; }
|
ykuroda |
0:13a5d365ba16
|
257
|
void resize(DenseIndex, DenseIndex, DenseIndex nbCols) { m_cols = nbCols; }
|
ykuroda |
0:13a5d365ba16
|
258
|
const T *data() const { return m_data.array; }
|
ykuroda |
0:13a5d365ba16
|
259
|
T *data() { return m_data.array; }
|
ykuroda |
0:13a5d365ba16
|
260
|
};
|
ykuroda |
0:13a5d365ba16
|
261
|
|
ykuroda |
0:13a5d365ba16
|
262
|
// purely dynamic matrix.
|
ykuroda |
0:13a5d365ba16
|
263
|
template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
|
ykuroda |
0:13a5d365ba16
|
264
|
{
|
ykuroda |
0:13a5d365ba16
|
265
|
T *m_data;
|
ykuroda |
0:13a5d365ba16
|
266
|
DenseIndex m_rows;
|
ykuroda |
0:13a5d365ba16
|
267
|
DenseIndex m_cols;
|
ykuroda |
0:13a5d365ba16
|
268
|
public:
|
ykuroda |
0:13a5d365ba16
|
269
|
DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
|
ykuroda |
0:13a5d365ba16
|
270
|
DenseStorage(internal::constructor_without_unaligned_array_assert)
|
ykuroda |
0:13a5d365ba16
|
271
|
: m_data(0), m_rows(0), m_cols(0) {}
|
ykuroda |
0:13a5d365ba16
|
272
|
DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
|
ykuroda |
0:13a5d365ba16
|
273
|
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows), m_cols(nbCols)
|
ykuroda |
0:13a5d365ba16
|
274
|
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
ykuroda |
0:13a5d365ba16
|
275
|
#ifdef EIGEN_HAVE_RVALUE_REFERENCES
|
ykuroda |
0:13a5d365ba16
|
276
|
DenseStorage(DenseStorage&& other)
|
ykuroda |
0:13a5d365ba16
|
277
|
: m_data(std::move(other.m_data))
|
ykuroda |
0:13a5d365ba16
|
278
|
, m_rows(std::move(other.m_rows))
|
ykuroda |
0:13a5d365ba16
|
279
|
, m_cols(std::move(other.m_cols))
|
ykuroda |
0:13a5d365ba16
|
280
|
{
|
ykuroda |
0:13a5d365ba16
|
281
|
other.m_data = nullptr;
|
ykuroda |
0:13a5d365ba16
|
282
|
}
|
ykuroda |
0:13a5d365ba16
|
283
|
DenseStorage& operator=(DenseStorage&& other)
|
ykuroda |
0:13a5d365ba16
|
284
|
{
|
ykuroda |
0:13a5d365ba16
|
285
|
using std::swap;
|
ykuroda |
0:13a5d365ba16
|
286
|
swap(m_data, other.m_data);
|
ykuroda |
0:13a5d365ba16
|
287
|
swap(m_rows, other.m_rows);
|
ykuroda |
0:13a5d365ba16
|
288
|
swap(m_cols, other.m_cols);
|
ykuroda |
0:13a5d365ba16
|
289
|
return *this;
|
ykuroda |
0:13a5d365ba16
|
290
|
}
|
ykuroda |
0:13a5d365ba16
|
291
|
#endif
|
ykuroda |
0:13a5d365ba16
|
292
|
~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
|
ykuroda |
0:13a5d365ba16
|
293
|
void swap(DenseStorage& other)
|
ykuroda |
0:13a5d365ba16
|
294
|
{ std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
|
ykuroda |
0:13a5d365ba16
|
295
|
DenseIndex rows(void) const {return m_rows;}
|
ykuroda |
0:13a5d365ba16
|
296
|
DenseIndex cols(void) const {return m_cols;}
|
ykuroda |
0:13a5d365ba16
|
297
|
void conservativeResize(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
|
ykuroda |
0:13a5d365ba16
|
298
|
{
|
ykuroda |
0:13a5d365ba16
|
299
|
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
|
ykuroda |
0:13a5d365ba16
|
300
|
m_rows = nbRows;
|
ykuroda |
0:13a5d365ba16
|
301
|
m_cols = nbCols;
|
ykuroda |
0:13a5d365ba16
|
302
|
}
|
ykuroda |
0:13a5d365ba16
|
303
|
void resize(DenseIndex size, DenseIndex nbRows, DenseIndex nbCols)
|
ykuroda |
0:13a5d365ba16
|
304
|
{
|
ykuroda |
0:13a5d365ba16
|
305
|
if(size != m_rows*m_cols)
|
ykuroda |
0:13a5d365ba16
|
306
|
{
|
ykuroda |
0:13a5d365ba16
|
307
|
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
|
ykuroda |
0:13a5d365ba16
|
308
|
if (size)
|
ykuroda |
0:13a5d365ba16
|
309
|
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
ykuroda |
0:13a5d365ba16
|
310
|
else
|
ykuroda |
0:13a5d365ba16
|
311
|
m_data = 0;
|
ykuroda |
0:13a5d365ba16
|
312
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
ykuroda |
0:13a5d365ba16
|
313
|
}
|
ykuroda |
0:13a5d365ba16
|
314
|
m_rows = nbRows;
|
ykuroda |
0:13a5d365ba16
|
315
|
m_cols = nbCols;
|
ykuroda |
0:13a5d365ba16
|
316
|
}
|
ykuroda |
0:13a5d365ba16
|
317
|
const T *data() const { return m_data; }
|
ykuroda |
0:13a5d365ba16
|
318
|
T *data() { return m_data; }
|
ykuroda |
0:13a5d365ba16
|
319
|
private:
|
ykuroda |
0:13a5d365ba16
|
320
|
DenseStorage(const DenseStorage&);
|
ykuroda |
0:13a5d365ba16
|
321
|
DenseStorage& operator=(const DenseStorage&);
|
ykuroda |
0:13a5d365ba16
|
322
|
};
|
ykuroda |
0:13a5d365ba16
|
323
|
|
ykuroda |
0:13a5d365ba16
|
324
|
// matrix with dynamic width and fixed height (so that matrix has dynamic size).
|
ykuroda |
0:13a5d365ba16
|
325
|
template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
|
ykuroda |
0:13a5d365ba16
|
326
|
{
|
ykuroda |
0:13a5d365ba16
|
327
|
T *m_data;
|
ykuroda |
0:13a5d365ba16
|
328
|
DenseIndex m_cols;
|
ykuroda |
0:13a5d365ba16
|
329
|
public:
|
ykuroda |
0:13a5d365ba16
|
330
|
DenseStorage() : m_data(0), m_cols(0) {}
|
ykuroda |
0:13a5d365ba16
|
331
|
DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
|
ykuroda |
0:13a5d365ba16
|
332
|
DenseStorage(DenseIndex size, DenseIndex, DenseIndex nbCols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(nbCols)
|
ykuroda |
0:13a5d365ba16
|
333
|
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
ykuroda |
0:13a5d365ba16
|
334
|
#ifdef EIGEN_HAVE_RVALUE_REFERENCES
|
ykuroda |
0:13a5d365ba16
|
335
|
DenseStorage(DenseStorage&& other)
|
ykuroda |
0:13a5d365ba16
|
336
|
: m_data(std::move(other.m_data))
|
ykuroda |
0:13a5d365ba16
|
337
|
, m_cols(std::move(other.m_cols))
|
ykuroda |
0:13a5d365ba16
|
338
|
{
|
ykuroda |
0:13a5d365ba16
|
339
|
other.m_data = nullptr;
|
ykuroda |
0:13a5d365ba16
|
340
|
}
|
ykuroda |
0:13a5d365ba16
|
341
|
DenseStorage& operator=(DenseStorage&& other)
|
ykuroda |
0:13a5d365ba16
|
342
|
{
|
ykuroda |
0:13a5d365ba16
|
343
|
using std::swap;
|
ykuroda |
0:13a5d365ba16
|
344
|
swap(m_data, other.m_data);
|
ykuroda |
0:13a5d365ba16
|
345
|
swap(m_cols, other.m_cols);
|
ykuroda |
0:13a5d365ba16
|
346
|
return *this;
|
ykuroda |
0:13a5d365ba16
|
347
|
}
|
ykuroda |
0:13a5d365ba16
|
348
|
#endif
|
ykuroda |
0:13a5d365ba16
|
349
|
~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
|
ykuroda |
0:13a5d365ba16
|
350
|
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
|
ykuroda |
0:13a5d365ba16
|
351
|
static DenseIndex rows(void) {return _Rows;}
|
ykuroda |
0:13a5d365ba16
|
352
|
DenseIndex cols(void) const {return m_cols;}
|
ykuroda |
0:13a5d365ba16
|
353
|
void conservativeResize(DenseIndex size, DenseIndex, DenseIndex nbCols)
|
ykuroda |
0:13a5d365ba16
|
354
|
{
|
ykuroda |
0:13a5d365ba16
|
355
|
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
|
ykuroda |
0:13a5d365ba16
|
356
|
m_cols = nbCols;
|
ykuroda |
0:13a5d365ba16
|
357
|
}
|
ykuroda |
0:13a5d365ba16
|
358
|
EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex, DenseIndex nbCols)
|
ykuroda |
0:13a5d365ba16
|
359
|
{
|
ykuroda |
0:13a5d365ba16
|
360
|
if(size != _Rows*m_cols)
|
ykuroda |
0:13a5d365ba16
|
361
|
{
|
ykuroda |
0:13a5d365ba16
|
362
|
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
|
ykuroda |
0:13a5d365ba16
|
363
|
if (size)
|
ykuroda |
0:13a5d365ba16
|
364
|
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
ykuroda |
0:13a5d365ba16
|
365
|
else
|
ykuroda |
0:13a5d365ba16
|
366
|
m_data = 0;
|
ykuroda |
0:13a5d365ba16
|
367
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
ykuroda |
0:13a5d365ba16
|
368
|
}
|
ykuroda |
0:13a5d365ba16
|
369
|
m_cols = nbCols;
|
ykuroda |
0:13a5d365ba16
|
370
|
}
|
ykuroda |
0:13a5d365ba16
|
371
|
const T *data() const { return m_data; }
|
ykuroda |
0:13a5d365ba16
|
372
|
T *data() { return m_data; }
|
ykuroda |
0:13a5d365ba16
|
373
|
private:
|
ykuroda |
0:13a5d365ba16
|
374
|
DenseStorage(const DenseStorage&);
|
ykuroda |
0:13a5d365ba16
|
375
|
DenseStorage& operator=(const DenseStorage&);
|
ykuroda |
0:13a5d365ba16
|
376
|
};
|
ykuroda |
0:13a5d365ba16
|
377
|
|
ykuroda |
0:13a5d365ba16
|
378
|
// matrix with dynamic height and fixed width (so that matrix has dynamic size).
|
ykuroda |
0:13a5d365ba16
|
379
|
template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
|
ykuroda |
0:13a5d365ba16
|
380
|
{
|
ykuroda |
0:13a5d365ba16
|
381
|
T *m_data;
|
ykuroda |
0:13a5d365ba16
|
382
|
DenseIndex m_rows;
|
ykuroda |
0:13a5d365ba16
|
383
|
public:
|
ykuroda |
0:13a5d365ba16
|
384
|
DenseStorage() : m_data(0), m_rows(0) {}
|
ykuroda |
0:13a5d365ba16
|
385
|
DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
|
ykuroda |
0:13a5d365ba16
|
386
|
DenseStorage(DenseIndex size, DenseIndex nbRows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(nbRows)
|
ykuroda |
0:13a5d365ba16
|
387
|
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
ykuroda |
0:13a5d365ba16
|
388
|
#ifdef EIGEN_HAVE_RVALUE_REFERENCES
|
ykuroda |
0:13a5d365ba16
|
389
|
DenseStorage(DenseStorage&& other)
|
ykuroda |
0:13a5d365ba16
|
390
|
: m_data(std::move(other.m_data))
|
ykuroda |
0:13a5d365ba16
|
391
|
, m_rows(std::move(other.m_rows))
|
ykuroda |
0:13a5d365ba16
|
392
|
{
|
ykuroda |
0:13a5d365ba16
|
393
|
other.m_data = nullptr;
|
ykuroda |
0:13a5d365ba16
|
394
|
}
|
ykuroda |
0:13a5d365ba16
|
395
|
DenseStorage& operator=(DenseStorage&& other)
|
ykuroda |
0:13a5d365ba16
|
396
|
{
|
ykuroda |
0:13a5d365ba16
|
397
|
using std::swap;
|
ykuroda |
0:13a5d365ba16
|
398
|
swap(m_data, other.m_data);
|
ykuroda |
0:13a5d365ba16
|
399
|
swap(m_rows, other.m_rows);
|
ykuroda |
0:13a5d365ba16
|
400
|
return *this;
|
ykuroda |
0:13a5d365ba16
|
401
|
}
|
ykuroda |
0:13a5d365ba16
|
402
|
#endif
|
ykuroda |
0:13a5d365ba16
|
403
|
~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
|
ykuroda |
0:13a5d365ba16
|
404
|
void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
|
ykuroda |
0:13a5d365ba16
|
405
|
DenseIndex rows(void) const {return m_rows;}
|
ykuroda |
0:13a5d365ba16
|
406
|
static DenseIndex cols(void) {return _Cols;}
|
ykuroda |
0:13a5d365ba16
|
407
|
void conservativeResize(DenseIndex size, DenseIndex nbRows, DenseIndex)
|
ykuroda |
0:13a5d365ba16
|
408
|
{
|
ykuroda |
0:13a5d365ba16
|
409
|
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
|
ykuroda |
0:13a5d365ba16
|
410
|
m_rows = nbRows;
|
ykuroda |
0:13a5d365ba16
|
411
|
}
|
ykuroda |
0:13a5d365ba16
|
412
|
EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex nbRows, DenseIndex)
|
ykuroda |
0:13a5d365ba16
|
413
|
{
|
ykuroda |
0:13a5d365ba16
|
414
|
if(size != m_rows*_Cols)
|
ykuroda |
0:13a5d365ba16
|
415
|
{
|
ykuroda |
0:13a5d365ba16
|
416
|
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
|
ykuroda |
0:13a5d365ba16
|
417
|
if (size)
|
ykuroda |
0:13a5d365ba16
|
418
|
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
ykuroda |
0:13a5d365ba16
|
419
|
else
|
ykuroda |
0:13a5d365ba16
|
420
|
m_data = 0;
|
ykuroda |
0:13a5d365ba16
|
421
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
ykuroda |
0:13a5d365ba16
|
422
|
}
|
ykuroda |
0:13a5d365ba16
|
423
|
m_rows = nbRows;
|
ykuroda |
0:13a5d365ba16
|
424
|
}
|
ykuroda |
0:13a5d365ba16
|
425
|
const T *data() const { return m_data; }
|
ykuroda |
0:13a5d365ba16
|
426
|
T *data() { return m_data; }
|
ykuroda |
0:13a5d365ba16
|
427
|
private:
|
ykuroda |
0:13a5d365ba16
|
428
|
DenseStorage(const DenseStorage&);
|
ykuroda |
0:13a5d365ba16
|
429
|
DenseStorage& operator=(const DenseStorage&);
|
ykuroda |
0:13a5d365ba16
|
430
|
};
|
ykuroda |
0:13a5d365ba16
|
431
|
|
ykuroda |
0:13a5d365ba16
|
432
|
} // end namespace Eigen
|
ykuroda |
0:13a5d365ba16
|
433
|
|
ykuroda |
0:13a5d365ba16
|
434
|
#endif // EIGEN_MATRIX_H |