10 #ifndef EIGEN_SKYLINE_STORAGE_H
11 #define EIGEN_SKYLINE_STORAGE_H
13 #include "./InternalHeaderCheck.h"
23 template<
typename Scalar>
26 typedef SparseIndex Index;
38 m_upperProfileSize(0),
39 m_lowerProfileSize(0),
52 m_upperProfileSize(0),
53 m_lowerProfileSize(0),
59 resize(other.diagSize(), other.m_upperProfileSize, other.m_lowerProfileSize, other.upperSize(), other.lowerSize());
60 memcpy(m_diag, other.m_diag, m_diagSize * sizeof (Scalar));
61 memcpy(m_upper, other.m_upper, other.upperSize() * sizeof (Scalar));
62 memcpy(m_lower, other.m_lower, other.lowerSize() * sizeof (Scalar));
63 memcpy(m_upperProfile, other.m_upperProfile, m_upperProfileSize * sizeof (Index));
64 memcpy(m_lowerProfile, other.m_lowerProfile, m_lowerProfileSize * sizeof (Index));
69 std::swap(m_diag, other.m_diag);
70 std::swap(m_upper, other.m_upper);
71 std::swap(m_lower, other.m_lower);
72 std::swap(m_upperProfile, other.m_upperProfile);
73 std::swap(m_lowerProfile, other.m_lowerProfile);
74 std::swap(m_diagSize, other.m_diagSize);
75 std::swap(m_upperSize, other.m_upperSize);
76 std::swap(m_lowerSize, other.m_lowerSize);
77 std::swap(m_allocatedSize, other.m_allocatedSize);
83 if (m_upper != m_lower)
85 delete[] m_upperProfile;
86 delete[] m_lowerProfile;
89 void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) {
90 Index newAllocatedSize = size + upperSize + lowerSize;
91 if (newAllocatedSize > m_allocatedSize)
92 reallocate(size, upperProfileSize, lowerProfileSize, upperSize, lowerSize);
96 if (m_allocatedSize > m_diagSize + m_upperSize + m_lowerSize)
97 reallocate(m_diagSize, m_upperProfileSize, m_lowerProfileSize, m_upperSize, m_lowerSize);
100 void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize,
float reserveSizeFactor = 0) {
101 if (m_allocatedSize < diagSize + upperSize + lowerSize)
102 reallocate(diagSize, upperProfileSize, lowerProfileSize, upperSize + Index(reserveSizeFactor * upperSize), lowerSize + Index(reserveSizeFactor * lowerSize));
103 m_diagSize = diagSize;
104 m_upperSize = upperSize;
105 m_lowerSize = lowerSize;
106 m_upperProfileSize = upperProfileSize;
107 m_lowerProfileSize = lowerProfileSize;
110 inline Index diagSize()
const {
114 inline Index upperSize()
const {
118 inline Index lowerSize()
const {
122 inline Index upperProfileSize()
const {
123 return m_upperProfileSize;
126 inline Index lowerProfileSize()
const {
127 return m_lowerProfileSize;
130 inline Index allocatedSize()
const {
131 return m_allocatedSize;
134 inline void clear() {
138 inline Scalar& diag(Index i) {
142 inline const Scalar& diag(Index i)
const {
146 inline Scalar& upper(Index i) {
150 inline const Scalar& upper(Index i)
const {
154 inline Scalar& lower(Index i) {
158 inline const Scalar& lower(Index i)
const {
162 inline Index& upperProfile(Index i) {
163 return m_upperProfile[i];
166 inline const Index& upperProfile(Index i)
const {
167 return m_upperProfile[i];
170 inline Index& lowerProfile(Index i) {
171 return m_lowerProfile[i];
174 inline const Index& lowerProfile(Index i)
const {
175 return m_lowerProfile[i];
178 static SkylineStorage Map(Index* upperProfile, Index* lowerProfile, Scalar* diag, Scalar* upper, Scalar* lower, Index size, Index upperSize, Index lowerSize) {
180 res.m_upperProfile = upperProfile;
181 res.m_lowerProfile = lowerProfile;
185 res.m_allocatedSize = res.m_diagSize = size;
186 res.m_upperSize = upperSize;
187 res.m_lowerSize = lowerSize;
191 inline void reset() {
192 std::fill_n(m_diag, m_diagSize, Scalar(0));
193 std::fill_n(m_upper, m_upperSize, Scalar(0));
194 std::fill_n(m_lower, m_lowerSize, Scalar(0));
195 std::fill_n(m_upperProfile, m_diagSize, Index(0));
196 std::fill_n(m_lowerProfile, m_diagSize, Index(0));
199 void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar>()) {
205 inline void reallocate(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) {
207 Scalar* diag =
new Scalar[diagSize];
208 Scalar* upper =
new Scalar[upperSize];
209 Scalar* lower =
new Scalar[lowerSize];
210 Index* upperProfile =
new Index[upperProfileSize];
211 Index* lowerProfile =
new Index[lowerProfileSize];
213 Index copyDiagSize = (std::min)(diagSize, m_diagSize);
214 Index copyUpperSize = (std::min)(upperSize, m_upperSize);
215 Index copyLowerSize = (std::min)(lowerSize, m_lowerSize);
216 Index copyUpperProfileSize = (std::min)(upperProfileSize, m_upperProfileSize);
217 Index copyLowerProfileSize = (std::min)(lowerProfileSize, m_lowerProfileSize);
220 memcpy(diag, m_diag, copyDiagSize *
sizeof (Scalar));
221 memcpy(upper, m_upper, copyUpperSize *
sizeof (Scalar));
222 memcpy(lower, m_lower, copyLowerSize *
sizeof (Scalar));
223 memcpy(upperProfile, m_upperProfile, copyUpperProfileSize *
sizeof (Index));
224 memcpy(lowerProfile, m_lowerProfile, copyLowerProfileSize *
sizeof (Index));
232 delete[] m_upperProfile;
233 delete[] m_lowerProfile;
237 m_upperProfile = upperProfile;
238 m_lowerProfile = lowerProfile;
239 m_allocatedSize = diagSize + upperSize + lowerSize;
240 m_upperSize = upperSize;
241 m_lowerSize = lowerSize;
248 Index* m_upperProfile;
249 Index* m_lowerProfile;
253 Index m_upperProfileSize;
254 Index m_lowerProfileSize;
255 Index m_allocatedSize;
Definition: SkylineStorage.h:24
Namespace containing all symbols from the Eigen library.