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 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
23 template<typename Scalar>
26  typedef SparseIndex Index;
27 public:
28 
30  : m_diag(0),
31  m_lower(0),
32  m_upper(0),
33  m_lowerProfile(0),
34  m_upperProfile(0),
35  m_diagSize(0),
36  m_upperSize(0),
37  m_lowerSize(0),
40  m_allocatedSize(0) {
41  }
42 
44  : m_diag(0),
45  m_lower(0),
46  m_upper(0),
47  m_lowerProfile(0),
48  m_upperProfile(0),
49  m_diagSize(0),
50  m_upperSize(0),
51  m_lowerSize(0),
54  m_allocatedSize(0) {
55  *this = other;
56  }
57 
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));
65  return *this;
66  }
67 
68  void swap(SkylineStorage& other) {
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);
78  }
79 
81  delete[] m_diag;
82  delete[] m_upper;
83  if (m_upper != m_lower)
84  delete[] m_lower;
85  delete[] m_upperProfile;
86  delete[] m_lowerProfile;
87  }
88 
90  Index newAllocatedSize = size + upperSize + lowerSize;
91  if (newAllocatedSize > m_allocatedSize)
93  }
94 
95  void squeeze() {
98  }
99 
102  reallocate(diagSize, upperProfileSize, lowerProfileSize, upperSize + Index(reserveSizeFactor * upperSize), lowerSize + Index(reserveSizeFactor * lowerSize));
108  }
109 
110  inline Index diagSize() const {
111  return m_diagSize;
112  }
113 
114  inline Index upperSize() const {
115  return m_upperSize;
116  }
117 
118  inline Index lowerSize() const {
119  return m_lowerSize;
120  }
121 
122  inline Index upperProfileSize() const {
123  return m_upperProfileSize;
124  }
125 
126  inline Index lowerProfileSize() const {
127  return m_lowerProfileSize;
128  }
129 
130  inline Index allocatedSize() const {
131  return m_allocatedSize;
132  }
133 
134  inline void clear() {
135  m_diagSize = 0;
136  }
137 
138  inline Scalar& diag(Index i) {
139  return m_diag[i];
140  }
141 
142  inline const Scalar& diag(Index i) const {
143  return m_diag[i];
144  }
145 
146  inline Scalar& upper(Index i) {
147  return m_upper[i];
148  }
149 
150  inline const Scalar& upper(Index i) const {
151  return m_upper[i];
152  }
153 
154  inline Scalar& lower(Index i) {
155  return m_lower[i];
156  }
157 
158  inline const Scalar& lower(Index i) const {
159  return m_lower[i];
160  }
161 
162  inline Index& upperProfile(Index i) {
163  return m_upperProfile[i];
164  }
165 
166  inline const Index& upperProfile(Index i) const {
167  return m_upperProfile[i];
168  }
169 
170  inline Index& lowerProfile(Index i) {
171  return m_lowerProfile[i];
172  }
173 
174  inline const Index& lowerProfile(Index i) const {
175  return m_lowerProfile[i];
176  }
177 
180  res.m_upperProfile = upperProfile;
181  res.m_lowerProfile = lowerProfile;
182  res.m_diag = diag;
183  res.m_upper = upper;
184  res.m_lower = lower;
185  res.m_allocatedSize = res.m_diagSize = size;
186  res.m_upperSize = upperSize;
187  res.m_lowerSize = lowerSize;
188  return res;
189  }
190 
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));
197  }
198 
199  void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar>()) {
200  //TODO
201  }
202 
203 protected:
204 
206 
207  Scalar* diag = new Scalar[diagSize];
208  Scalar* upper = new Scalar[upperSize];
209  Scalar* lower = new Scalar[lowerSize];
212 
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);
218 
219  // copy
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));
225 
226 
227 
228  // delete old stuff
229  delete[] m_diag;
230  delete[] m_upper;
231  delete[] m_lower;
232  delete[] m_upperProfile;
233  delete[] m_lowerProfile;
234  m_diag = diag;
235  m_upper = upper;
236  m_lower = lower;
242  }
243 
244 public:
245  Scalar* m_diag;
246  Scalar* m_upper;
247  Scalar* m_lower;
256 
257 };
258 
259 } // end namespace Eigen
260 
261 #endif // EIGEN_SKYLINE_STORAGE_H
int i
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Index allocatedSize() const
Index & upperProfile(Index i)
Index & lowerProfile(Index i)
const Scalar & upper(Index i) const
const Index & lowerProfile(Index i) const
void swap(SkylineStorage &other)
const Index & upperProfile(Index i) const
SkylineStorage(const SkylineStorage &other)
const Scalar & diag(Index i) const
void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize, float reserveSizeFactor=0)
void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize)
Index upperSize() const
SkylineStorage & operator=(const SkylineStorage &other)
Scalar & lower(Index i)
static SkylineStorage Map(Index *upperProfile, Index *lowerProfile, Scalar *diag, Scalar *upper, Scalar *lower, Index size, Index upperSize, Index lowerSize)
NumTraits< Scalar >::Real RealScalar
void prune(Scalar reference, RealScalar epsilon=dummy_precision< RealScalar >())
Index lowerSize() const
const Scalar & lower(Index i) const
Index lowerProfileSize() const
Index diagSize() const
void reallocate(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize)
Scalar & upper(Index i)
Index upperProfileSize() const
Scalar & diag(Index i)
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
CleanedUpDerType< DerType >::type() min(const AutoDiffScalar< DerType > &x, const T &y)
SparseMat::Index size