TR-mbed 1.0
Loading...
Searching...
No Matches
SkylineStorage.h
Go to the documentation of this file.
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2009 Guillaume Saupin <guillaume.saupin@cea.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_SKYLINE_STORAGE_H
11#define EIGEN_SKYLINE_STORAGE_H
12
13namespace Eigen {
14
21template<typename Scalar>
23 typedef typename NumTraits<Scalar>::Real RealScalar;
24 typedef SparseIndex Index;
25public:
26
28 : m_diag(0),
29 m_lower(0),
30 m_upper(0),
33 m_diagSize(0),
34 m_upperSize(0),
35 m_lowerSize(0),
39 }
40
42 : m_diag(0),
43 m_lower(0),
44 m_upper(0),
47 m_diagSize(0),
48 m_upperSize(0),
49 m_lowerSize(0),
53 *this = other;
54 }
55
57 resize(other.diagSize(), other.m_upperProfileSize, other.m_lowerProfileSize, other.upperSize(), other.lowerSize());
58 memcpy(m_diag, other.m_diag, m_diagSize * sizeof (Scalar));
59 memcpy(m_upper, other.m_upper, other.upperSize() * sizeof (Scalar));
60 memcpy(m_lower, other.m_lower, other.lowerSize() * sizeof (Scalar));
61 memcpy(m_upperProfile, other.m_upperProfile, m_upperProfileSize * sizeof (Index));
62 memcpy(m_lowerProfile, other.m_lowerProfile, m_lowerProfileSize * sizeof (Index));
63 return *this;
64 }
65
66 void swap(SkylineStorage& other) {
67 std::swap(m_diag, other.m_diag);
68 std::swap(m_upper, other.m_upper);
69 std::swap(m_lower, other.m_lower);
70 std::swap(m_upperProfile, other.m_upperProfile);
71 std::swap(m_lowerProfile, other.m_lowerProfile);
72 std::swap(m_diagSize, other.m_diagSize);
73 std::swap(m_upperSize, other.m_upperSize);
74 std::swap(m_lowerSize, other.m_lowerSize);
75 std::swap(m_allocatedSize, other.m_allocatedSize);
76 }
77
79 delete[] m_diag;
80 delete[] m_upper;
81 if (m_upper != m_lower)
82 delete[] m_lower;
83 delete[] m_upperProfile;
84 delete[] m_lowerProfile;
85 }
86
87 void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) {
88 Index newAllocatedSize = size + upperSize + lowerSize;
89 if (newAllocatedSize > m_allocatedSize)
91 }
92
97
98 void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize, float reserveSizeFactor = 0) {
100 reallocate(diagSize, upperProfileSize, lowerProfileSize, upperSize + Index(reserveSizeFactor * upperSize), lowerSize + Index(reserveSizeFactor * lowerSize));
106 }
107
108 inline Index diagSize() const {
109 return m_diagSize;
110 }
111
112 inline Index upperSize() const {
113 return m_upperSize;
114 }
115
116 inline Index lowerSize() const {
117 return m_lowerSize;
118 }
119
120 inline Index upperProfileSize() const {
121 return m_upperProfileSize;
122 }
123
124 inline Index lowerProfileSize() const {
125 return m_lowerProfileSize;
126 }
127
128 inline Index allocatedSize() const {
129 return m_allocatedSize;
130 }
131
132 inline void clear() {
133 m_diagSize = 0;
134 }
135
136 inline Scalar& diag(Index i) {
137 return m_diag[i];
138 }
139
140 inline const Scalar& diag(Index i) const {
141 return m_diag[i];
142 }
143
144 inline Scalar& upper(Index i) {
145 return m_upper[i];
146 }
147
148 inline const Scalar& upper(Index i) const {
149 return m_upper[i];
150 }
151
152 inline Scalar& lower(Index i) {
153 return m_lower[i];
154 }
155
156 inline const Scalar& lower(Index i) const {
157 return m_lower[i];
158 }
159
160 inline Index& upperProfile(Index i) {
161 return m_upperProfile[i];
162 }
163
164 inline const Index& upperProfile(Index i) const {
165 return m_upperProfile[i];
166 }
167
168 inline Index& lowerProfile(Index i) {
169 return m_lowerProfile[i];
170 }
171
172 inline const Index& lowerProfile(Index i) const {
173 return m_lowerProfile[i];
174 }
175
179 res.m_lowerProfile = lowerProfile;
180 res.m_diag = diag;
181 res.m_upper = upper;
182 res.m_lower = lower;
183 res.m_allocatedSize = res.m_diagSize = size;
184 res.m_upperSize = upperSize;
185 res.m_lowerSize = lowerSize;
186 return res;
187 }
188
189 inline void reset() {
190 memset(m_diag, 0, m_diagSize * sizeof (Scalar));
191 memset(m_upper, 0, m_upperSize * sizeof (Scalar));
192 memset(m_lower, 0, m_lowerSize * sizeof (Scalar));
193 memset(m_upperProfile, 0, m_diagSize * sizeof (Index));
194 memset(m_lowerProfile, 0, m_diagSize * sizeof (Index));
195 }
196
197 void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar>()) {
198 //TODO
199 }
200
201protected:
202
203 inline void reallocate(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) {
204
205 Scalar* diag = new Scalar[diagSize];
208 Index* upperProfile = new Index[upperProfileSize];
209 Index* lowerProfile = new Index[lowerProfileSize];
210
211 Index copyDiagSize = (std::min)(diagSize, m_diagSize);
212 Index copyUpperSize = (std::min)(upperSize, m_upperSize);
213 Index copyLowerSize = (std::min)(lowerSize, m_lowerSize);
214 Index copyUpperProfileSize = (std::min)(upperProfileSize, m_upperProfileSize);
215 Index copyLowerProfileSize = (std::min)(lowerProfileSize, m_lowerProfileSize);
216
217 // copy
218 memcpy(diag, m_diag, copyDiagSize * sizeof (Scalar));
219 memcpy(upper, m_upper, copyUpperSize * sizeof (Scalar));
220 memcpy(lower, m_lower, copyLowerSize * sizeof (Scalar));
221 memcpy(upperProfile, m_upperProfile, copyUpperProfileSize * sizeof (Index));
222 memcpy(lowerProfile, m_lowerProfile, copyLowerProfileSize * sizeof (Index));
223
224
225
226 // delete old stuff
227 delete[] m_diag;
228 delete[] m_upper;
229 delete[] m_lower;
230 delete[] m_upperProfile;
231 delete[] m_lowerProfile;
232 m_diag = diag;
233 m_upper = upper;
234 m_lower = lower;
240 }
241
242public:
254
255};
256
257} // end namespace Eigen
258
259#endif // EIGEN_SKYLINE_STORAGE_H
int i
Definition BiCGSTAB_step_by_step.cpp:9
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition PartialRedux_count.cpp:3
Scalar Scalar int size
Definition benchVecAdd.cpp:17
SCALAR Scalar
Definition bench_gemm.cpp:46
Definition SkylineStorage.h:22
Index allocatedSize() const
Definition SkylineStorage.h:128
Scalar * m_lower
Definition SkylineStorage.h:245
void clear()
Definition SkylineStorage.h:132
void reset()
Definition SkylineStorage.h:189
Index m_lowerSize
Definition SkylineStorage.h:250
Scalar & upper(Index i)
Definition SkylineStorage.h:144
void swap(SkylineStorage &other)
Definition SkylineStorage.h:66
Index m_upperSize
Definition SkylineStorage.h:249
Scalar * m_diag
Definition SkylineStorage.h:243
SkylineStorage(const SkylineStorage &other)
Definition SkylineStorage.h:41
void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize, float reserveSizeFactor=0)
Definition SkylineStorage.h:98
void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize)
Definition SkylineStorage.h:87
Scalar & diag(Index i)
Definition SkylineStorage.h:136
Index upperSize() const
Definition SkylineStorage.h:112
Scalar & lower(Index i)
Definition SkylineStorage.h:152
const Index & lowerProfile(Index i) const
Definition SkylineStorage.h:172
SkylineStorage & operator=(const SkylineStorage &other)
Definition SkylineStorage.h:56
Index & upperProfile(Index i)
Definition SkylineStorage.h:160
Index m_lowerProfileSize
Definition SkylineStorage.h:252
void squeeze()
Definition SkylineStorage.h:93
Index m_upperProfileSize
Definition SkylineStorage.h:251
Scalar * m_upper
Definition SkylineStorage.h:244
const Scalar & lower(Index i) const
Definition SkylineStorage.h:156
const Scalar & diag(Index i) const
Definition SkylineStorage.h:140
static SkylineStorage Map(Index *upperProfile, Index *lowerProfile, Scalar *diag, Scalar *upper, Scalar *lower, Index size, Index upperSize, Index lowerSize)
Definition SkylineStorage.h:176
void prune(Scalar reference, RealScalar epsilon=dummy_precision< RealScalar >())
Definition SkylineStorage.h:197
Index & lowerProfile(Index i)
Definition SkylineStorage.h:168
Index lowerSize() const
Definition SkylineStorage.h:116
Index m_diagSize
Definition SkylineStorage.h:248
const Scalar & upper(Index i) const
Definition SkylineStorage.h:148
~SkylineStorage()
Definition SkylineStorage.h:78
Index * m_upperProfile
Definition SkylineStorage.h:246
Index m_allocatedSize
Definition SkylineStorage.h:253
Index lowerProfileSize() const
Definition SkylineStorage.h:124
Index diagSize() const
Definition SkylineStorage.h:108
void reallocate(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize)
Definition SkylineStorage.h:203
Index * m_lowerProfile
Definition SkylineStorage.h:247
const Index & upperProfile(Index i) const
Definition SkylineStorage.h:164
SkylineStorage()
Definition SkylineStorage.h:27
Index upperProfileSize() const
Definition SkylineStorage.h:120
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85