File indexing completed on 2025-01-18 09:57:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_SKYLINE_STORAGE_H
0011 #define EIGEN_SKYLINE_STORAGE_H
0012
0013 namespace Eigen {
0014
0015
0016
0017
0018
0019
0020
0021 template<typename Scalar>
0022 class SkylineStorage {
0023 typedef typename NumTraits<Scalar>::Real RealScalar;
0024 typedef SparseIndex Index;
0025 public:
0026
0027 SkylineStorage()
0028 : m_diag(0),
0029 m_lower(0),
0030 m_upper(0),
0031 m_lowerProfile(0),
0032 m_upperProfile(0),
0033 m_diagSize(0),
0034 m_upperSize(0),
0035 m_lowerSize(0),
0036 m_upperProfileSize(0),
0037 m_lowerProfileSize(0),
0038 m_allocatedSize(0) {
0039 }
0040
0041 SkylineStorage(const SkylineStorage& other)
0042 : m_diag(0),
0043 m_lower(0),
0044 m_upper(0),
0045 m_lowerProfile(0),
0046 m_upperProfile(0),
0047 m_diagSize(0),
0048 m_upperSize(0),
0049 m_lowerSize(0),
0050 m_upperProfileSize(0),
0051 m_lowerProfileSize(0),
0052 m_allocatedSize(0) {
0053 *this = other;
0054 }
0055
0056 SkylineStorage & operator=(const SkylineStorage& other) {
0057 resize(other.diagSize(), other.m_upperProfileSize, other.m_lowerProfileSize, other.upperSize(), other.lowerSize());
0058 memcpy(m_diag, other.m_diag, m_diagSize * sizeof (Scalar));
0059 memcpy(m_upper, other.m_upper, other.upperSize() * sizeof (Scalar));
0060 memcpy(m_lower, other.m_lower, other.lowerSize() * sizeof (Scalar));
0061 memcpy(m_upperProfile, other.m_upperProfile, m_upperProfileSize * sizeof (Index));
0062 memcpy(m_lowerProfile, other.m_lowerProfile, m_lowerProfileSize * sizeof (Index));
0063 return *this;
0064 }
0065
0066 void swap(SkylineStorage& other) {
0067 std::swap(m_diag, other.m_diag);
0068 std::swap(m_upper, other.m_upper);
0069 std::swap(m_lower, other.m_lower);
0070 std::swap(m_upperProfile, other.m_upperProfile);
0071 std::swap(m_lowerProfile, other.m_lowerProfile);
0072 std::swap(m_diagSize, other.m_diagSize);
0073 std::swap(m_upperSize, other.m_upperSize);
0074 std::swap(m_lowerSize, other.m_lowerSize);
0075 std::swap(m_allocatedSize, other.m_allocatedSize);
0076 }
0077
0078 ~SkylineStorage() {
0079 delete[] m_diag;
0080 delete[] m_upper;
0081 if (m_upper != m_lower)
0082 delete[] m_lower;
0083 delete[] m_upperProfile;
0084 delete[] m_lowerProfile;
0085 }
0086
0087 void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) {
0088 Index newAllocatedSize = size + upperSize + lowerSize;
0089 if (newAllocatedSize > m_allocatedSize)
0090 reallocate(size, upperProfileSize, lowerProfileSize, upperSize, lowerSize);
0091 }
0092
0093 void squeeze() {
0094 if (m_allocatedSize > m_diagSize + m_upperSize + m_lowerSize)
0095 reallocate(m_diagSize, m_upperProfileSize, m_lowerProfileSize, m_upperSize, m_lowerSize);
0096 }
0097
0098 void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize, float reserveSizeFactor = 0) {
0099 if (m_allocatedSize < diagSize + upperSize + lowerSize)
0100 reallocate(diagSize, upperProfileSize, lowerProfileSize, upperSize + Index(reserveSizeFactor * upperSize), lowerSize + Index(reserveSizeFactor * lowerSize));
0101 m_diagSize = diagSize;
0102 m_upperSize = upperSize;
0103 m_lowerSize = lowerSize;
0104 m_upperProfileSize = upperProfileSize;
0105 m_lowerProfileSize = lowerProfileSize;
0106 }
0107
0108 inline Index diagSize() const {
0109 return m_diagSize;
0110 }
0111
0112 inline Index upperSize() const {
0113 return m_upperSize;
0114 }
0115
0116 inline Index lowerSize() const {
0117 return m_lowerSize;
0118 }
0119
0120 inline Index upperProfileSize() const {
0121 return m_upperProfileSize;
0122 }
0123
0124 inline Index lowerProfileSize() const {
0125 return m_lowerProfileSize;
0126 }
0127
0128 inline Index allocatedSize() const {
0129 return m_allocatedSize;
0130 }
0131
0132 inline void clear() {
0133 m_diagSize = 0;
0134 }
0135
0136 inline Scalar& diag(Index i) {
0137 return m_diag[i];
0138 }
0139
0140 inline const Scalar& diag(Index i) const {
0141 return m_diag[i];
0142 }
0143
0144 inline Scalar& upper(Index i) {
0145 return m_upper[i];
0146 }
0147
0148 inline const Scalar& upper(Index i) const {
0149 return m_upper[i];
0150 }
0151
0152 inline Scalar& lower(Index i) {
0153 return m_lower[i];
0154 }
0155
0156 inline const Scalar& lower(Index i) const {
0157 return m_lower[i];
0158 }
0159
0160 inline Index& upperProfile(Index i) {
0161 return m_upperProfile[i];
0162 }
0163
0164 inline const Index& upperProfile(Index i) const {
0165 return m_upperProfile[i];
0166 }
0167
0168 inline Index& lowerProfile(Index i) {
0169 return m_lowerProfile[i];
0170 }
0171
0172 inline const Index& lowerProfile(Index i) const {
0173 return m_lowerProfile[i];
0174 }
0175
0176 static SkylineStorage Map(Index* upperProfile, Index* lowerProfile, Scalar* diag, Scalar* upper, Scalar* lower, Index size, Index upperSize, Index lowerSize) {
0177 SkylineStorage res;
0178 res.m_upperProfile = upperProfile;
0179 res.m_lowerProfile = lowerProfile;
0180 res.m_diag = diag;
0181 res.m_upper = upper;
0182 res.m_lower = lower;
0183 res.m_allocatedSize = res.m_diagSize = size;
0184 res.m_upperSize = upperSize;
0185 res.m_lowerSize = lowerSize;
0186 return res;
0187 }
0188
0189 inline void reset() {
0190 memset(m_diag, 0, m_diagSize * sizeof (Scalar));
0191 memset(m_upper, 0, m_upperSize * sizeof (Scalar));
0192 memset(m_lower, 0, m_lowerSize * sizeof (Scalar));
0193 memset(m_upperProfile, 0, m_diagSize * sizeof (Index));
0194 memset(m_lowerProfile, 0, m_diagSize * sizeof (Index));
0195 }
0196
0197 void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar>()) {
0198
0199 }
0200
0201 protected:
0202
0203 inline void reallocate(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) {
0204
0205 Scalar* diag = new Scalar[diagSize];
0206 Scalar* upper = new Scalar[upperSize];
0207 Scalar* lower = new Scalar[lowerSize];
0208 Index* upperProfile = new Index[upperProfileSize];
0209 Index* lowerProfile = new Index[lowerProfileSize];
0210
0211 Index copyDiagSize = (std::min)(diagSize, m_diagSize);
0212 Index copyUpperSize = (std::min)(upperSize, m_upperSize);
0213 Index copyLowerSize = (std::min)(lowerSize, m_lowerSize);
0214 Index copyUpperProfileSize = (std::min)(upperProfileSize, m_upperProfileSize);
0215 Index copyLowerProfileSize = (std::min)(lowerProfileSize, m_lowerProfileSize);
0216
0217
0218 memcpy(diag, m_diag, copyDiagSize * sizeof (Scalar));
0219 memcpy(upper, m_upper, copyUpperSize * sizeof (Scalar));
0220 memcpy(lower, m_lower, copyLowerSize * sizeof (Scalar));
0221 memcpy(upperProfile, m_upperProfile, copyUpperProfileSize * sizeof (Index));
0222 memcpy(lowerProfile, m_lowerProfile, copyLowerProfileSize * sizeof (Index));
0223
0224
0225
0226
0227 delete[] m_diag;
0228 delete[] m_upper;
0229 delete[] m_lower;
0230 delete[] m_upperProfile;
0231 delete[] m_lowerProfile;
0232 m_diag = diag;
0233 m_upper = upper;
0234 m_lower = lower;
0235 m_upperProfile = upperProfile;
0236 m_lowerProfile = lowerProfile;
0237 m_allocatedSize = diagSize + upperSize + lowerSize;
0238 m_upperSize = upperSize;
0239 m_lowerSize = lowerSize;
0240 }
0241
0242 public:
0243 Scalar* m_diag;
0244 Scalar* m_upper;
0245 Scalar* m_lower;
0246 Index* m_upperProfile;
0247 Index* m_lowerProfile;
0248 Index m_diagSize;
0249 Index m_upperSize;
0250 Index m_lowerSize;
0251 Index m_upperProfileSize;
0252 Index m_lowerProfileSize;
0253 Index m_allocatedSize;
0254
0255 };
0256
0257 }
0258
0259 #endif