25 #ifndef EIGEN_SKYLINE_STORAGE_H
26 #define EIGEN_SKYLINE_STORAGE_H
36 template<
typename Scalar>
38 typedef typename NumTraits<Scalar>::Real RealScalar;
39 typedef SparseIndex Index;
51 m_upperProfileSize(0),
52 m_lowerProfileSize(0),
65 m_upperProfileSize(0),
66 m_lowerProfileSize(0),
72 resize(other.diagSize(), other.m_upperProfileSize, other.m_lowerProfileSize, other.upperSize(), other.lowerSize());
73 memcpy(m_diag, other.m_diag, m_diagSize * sizeof (Scalar));
74 memcpy(m_upper, other.m_upper, other.upperSize() *
sizeof (Scalar));
75 memcpy(m_lower, other.m_lower, other.lowerSize() *
sizeof (Scalar));
76 memcpy(m_upperProfile, other.m_upperProfile, m_upperProfileSize * sizeof (Index));
77 memcpy(m_lowerProfile, other.m_lowerProfile, m_lowerProfileSize * sizeof (Index));
82 std::swap(m_diag, other.m_diag);
83 std::swap(m_upper, other.m_upper);
84 std::swap(m_lower, other.m_lower);
85 std::swap(m_upperProfile, other.m_upperProfile);
86 std::swap(m_lowerProfile, other.m_lowerProfile);
87 std::swap(m_diagSize, other.m_diagSize);
88 std::swap(m_upperSize, other.m_upperSize);
89 std::swap(m_lowerSize, other.m_lowerSize);
90 std::swap(m_allocatedSize, other.m_allocatedSize);
96 if (m_upper != m_lower)
98 delete[] m_upperProfile;
99 delete[] m_lowerProfile;
102 void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) {
103 Index newAllocatedSize = size + upperSize + lowerSize;
104 if (newAllocatedSize > m_allocatedSize)
105 reallocate(size, upperProfileSize, lowerProfileSize, upperSize, lowerSize);
109 if (m_allocatedSize > m_diagSize + m_upperSize + m_lowerSize)
110 reallocate(m_diagSize, m_upperProfileSize, m_lowerProfileSize, m_upperSize, m_lowerSize);
113 void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize,
float reserveSizeFactor = 0) {
114 if (m_allocatedSize < diagSize + upperSize + lowerSize)
115 reallocate(diagSize, upperProfileSize, lowerProfileSize, upperSize + Index(reserveSizeFactor * upperSize), lowerSize + Index(reserveSizeFactor * lowerSize));
116 m_diagSize = diagSize;
117 m_upperSize = upperSize;
118 m_lowerSize = lowerSize;
119 m_upperProfileSize = upperProfileSize;
120 m_lowerProfileSize = lowerProfileSize;
123 inline Index diagSize()
const {
127 inline Index upperSize()
const {
131 inline Index lowerSize()
const {
135 inline Index upperProfileSize()
const {
136 return m_upperProfileSize;
139 inline Index lowerProfileSize()
const {
140 return m_lowerProfileSize;
143 inline Index allocatedSize()
const {
144 return m_allocatedSize;
147 inline void clear() {
151 inline Scalar& diag(Index i) {
155 inline const Scalar& diag(Index i)
const {
159 inline Scalar& upper(Index i) {
163 inline const Scalar& upper(Index i)
const {
167 inline Scalar& lower(Index i) {
171 inline const Scalar& lower(Index i)
const {
175 inline Index& upperProfile(Index i) {
176 return m_upperProfile[i];
179 inline const Index& upperProfile(Index i)
const {
180 return m_upperProfile[i];
183 inline Index& lowerProfile(Index i) {
184 return m_lowerProfile[i];
187 inline const Index& lowerProfile(Index i)
const {
188 return m_lowerProfile[i];
191 static SkylineStorage Map(Index* upperProfile, Index* lowerProfile, Scalar* diag, Scalar* upper, Scalar* lower, Index size, Index upperSize, Index lowerSize) {
193 res.m_upperProfile = upperProfile;
194 res.m_lowerProfile = lowerProfile;
198 res.m_allocatedSize = res.m_diagSize = size;
199 res.m_upperSize = upperSize;
200 res.m_lowerSize = lowerSize;
204 inline void reset() {
205 memset(m_diag, 0, m_diagSize *
sizeof (Scalar));
206 memset(m_upper, 0, m_upperSize *
sizeof (Scalar));
207 memset(m_lower, 0, m_lowerSize *
sizeof (Scalar));
208 memset(m_upperProfile, 0, m_diagSize *
sizeof (Index));
209 memset(m_lowerProfile, 0, m_diagSize *
sizeof (Index));
212 void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar>()) {
218 inline void reallocate(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) {
220 Scalar* diag =
new Scalar[diagSize];
221 Scalar* upper =
new Scalar[upperSize];
222 Scalar* lower =
new Scalar[lowerSize];
223 Index* upperProfile =
new Index[upperProfileSize];
224 Index* lowerProfile =
new Index[lowerProfileSize];
226 Index copyDiagSize = (std::min)(diagSize, m_diagSize);
227 Index copyUpperSize = (std::min)(upperSize, m_upperSize);
228 Index copyLowerSize = (std::min)(lowerSize, m_lowerSize);
229 Index copyUpperProfileSize = (std::min)(upperProfileSize, m_upperProfileSize);
230 Index copyLowerProfileSize = (std::min)(lowerProfileSize, m_lowerProfileSize);
233 memcpy(diag, m_diag, copyDiagSize *
sizeof (Scalar));
234 memcpy(upper, m_upper, copyUpperSize *
sizeof (Scalar));
235 memcpy(lower, m_lower, copyLowerSize *
sizeof (Scalar));
236 memcpy(upperProfile, m_upperProfile, copyUpperProfileSize *
sizeof (Index));
237 memcpy(lowerProfile, m_lowerProfile, copyLowerProfileSize *
sizeof (Index));
245 delete[] m_upperProfile;
246 delete[] m_lowerProfile;
250 m_upperProfile = upperProfile;
251 m_lowerProfile = lowerProfile;
252 m_allocatedSize = diagSize + upperSize + lowerSize;
253 m_upperSize = upperSize;
254 m_lowerSize = lowerSize;
261 Index* m_upperProfile;
262 Index* m_lowerProfile;
266 Index m_upperProfileSize;
267 Index m_lowerProfileSize;
268 Index m_allocatedSize;
274 #endif // EIGEN_COMPRESSED_STORAGE_H