SkylineMatrix.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_SKYLINEMATRIX_H
11 #define EIGEN_SKYLINEMATRIX_H
12 
13 #include "SkylineStorage.h"
14 #include "SkylineMatrixBase.h"
15 
16 #include "./InternalHeaderCheck.h"
17 
18 namespace Eigen {
19 
35 namespace internal {
36 template<typename Scalar_, int Options_>
37 struct traits<SkylineMatrix<Scalar_, Options_> > {
38  typedef Scalar_ Scalar;
39  typedef Sparse StorageKind;
40 
41  enum {
42  RowsAtCompileTime = Dynamic,
43  ColsAtCompileTime = Dynamic,
44  MaxRowsAtCompileTime = Dynamic,
45  MaxColsAtCompileTime = Dynamic,
46  Flags = SkylineBit | Options_,
47  CoeffReadCost = NumTraits<Scalar>::ReadCost,
48  };
49 };
50 }
51 
52 template<typename Scalar_, int Options_>
54 : public SkylineMatrixBase<SkylineMatrix<Scalar_, Options_> > {
55 public:
59 
60  using Base::IsRowMajor;
61 
62 protected:
63 
65 
68 
69 public:
73 
74 public:
75 
76  inline Index rows() const {
78  }
79 
80  inline Index cols() const {
82  }
83 
84  inline Index innerSize() const {
85  return m_innerSize;
86  }
87 
88  inline Index outerSize() const {
89  return m_outerSize;
90  }
91 
92  inline Index upperNonZeros() const {
93  return m_data.upperSize();
94  }
95 
96  inline Index lowerNonZeros() const {
97  return m_data.lowerSize();
98  }
99 
100  inline Index upperNonZeros(Index j) const {
101  return m_colStartIndex[j + 1] - m_colStartIndex[j];
102  }
103 
104  inline Index lowerNonZeros(Index j) const {
105  return m_rowStartIndex[j + 1] - m_rowStartIndex[j];
106  }
107 
108  inline const Scalar* _diagPtr() const {
109  return &m_data.diag(0);
110  }
111 
112  inline Scalar* _diagPtr() {
113  return &m_data.diag(0);
114  }
115 
116  inline const Scalar* _upperPtr() const {
117  return &m_data.upper(0);
118  }
119 
120  inline Scalar* _upperPtr() {
121  return &m_data.upper(0);
122  }
123 
124  inline const Scalar* _lowerPtr() const {
125  return &m_data.lower(0);
126  }
127 
128  inline Scalar* _lowerPtr() {
129  return &m_data.lower(0);
130  }
131 
132  inline const Index* _upperProfilePtr() const {
133  return &m_data.upperProfile(0);
134  }
135 
137  return &m_data.upperProfile(0);
138  }
139 
140  inline const Index* _lowerProfilePtr() const {
141  return &m_data.lowerProfile(0);
142  }
143 
145  return &m_data.lowerProfile(0);
146  }
147 
148  inline Scalar coeff(Index row, Index col) const {
149  const Index outer = IsRowMajor ? row : col;
150  const Index inner = IsRowMajor ? col : row;
151 
152  eigen_assert(outer < outerSize());
153  eigen_assert(inner < innerSize());
154 
155  if (outer == inner)
156  return this->m_data.diag(outer);
157 
158  if (IsRowMajor) {
159  if (inner > outer) //upper matrix
160  {
161  const Index minOuterIndex = inner - m_data.upperProfile(inner);
162  if (outer >= minOuterIndex)
163  return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner)));
164  else
165  return Scalar(0);
166  }
167  if (inner < outer) //lower matrix
168  {
169  const Index minInnerIndex = outer - m_data.lowerProfile(outer);
170  if (inner >= minInnerIndex)
171  return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer)));
172  else
173  return Scalar(0);
174  }
175  return m_data.upper(m_colStartIndex[inner] + outer - inner);
176  } else {
177  if (outer > inner) //upper matrix
178  {
179  const Index maxOuterIndex = inner + m_data.upperProfile(inner);
180  if (outer <= maxOuterIndex)
181  return this->m_data.upper(m_colStartIndex[inner] + (outer - inner));
182  else
183  return Scalar(0);
184  }
185  if (outer < inner) //lower matrix
186  {
187  const Index maxInnerIndex = outer + m_data.lowerProfile(outer);
188 
189  if (inner <= maxInnerIndex)
190  return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer));
191  else
192  return Scalar(0);
193  }
194  }
195  }
196 
197  inline Scalar& coeffRef(Index row, Index col) {
198  const Index outer = IsRowMajor ? row : col;
199  const Index inner = IsRowMajor ? col : row;
200 
201  eigen_assert(outer < outerSize());
202  eigen_assert(inner < innerSize());
203 
204  if (outer == inner)
205  return this->m_data.diag(outer);
206 
207  if (IsRowMajor) {
208  if (col > row) //upper matrix
209  {
210  const Index minOuterIndex = inner - m_data.upperProfile(inner);
211  eigen_assert(outer >= minOuterIndex && "You tried to access a coeff that does not exist in the storage");
212  return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner)));
213  }
214  if (col < row) //lower matrix
215  {
216  const Index minInnerIndex = outer - m_data.lowerProfile(outer);
217  eigen_assert(inner >= minInnerIndex && "You tried to access a coeff that does not exist in the storage");
218  return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer)));
219  }
220  } else {
221  if (outer > inner) //upper matrix
222  {
223  const Index maxOuterIndex = inner + m_data.upperProfile(inner);
224  eigen_assert(outer <= maxOuterIndex && "You tried to access a coeff that does not exist in the storage");
225  return this->m_data.upper(m_colStartIndex[inner] + (outer - inner));
226  }
227  if (outer < inner) //lower matrix
228  {
229  const Index maxInnerIndex = outer + m_data.lowerProfile(outer);
230  eigen_assert(inner <= maxInnerIndex && "You tried to access a coeff that does not exist in the storage");
231  return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer));
232  }
233  }
234  }
235 
236  inline Scalar coeffDiag(Index idx) const {
237  eigen_assert(idx < outerSize());
238  eigen_assert(idx < innerSize());
239  return this->m_data.diag(idx);
240  }
241 
242  inline Scalar coeffLower(Index row, Index col) const {
243  const Index outer = IsRowMajor ? row : col;
244  const Index inner = IsRowMajor ? col : row;
245 
246  eigen_assert(outer < outerSize());
247  eigen_assert(inner < innerSize());
248  eigen_assert(inner != outer);
249 
250  if (IsRowMajor) {
251  const Index minInnerIndex = outer - m_data.lowerProfile(outer);
252  if (inner >= minInnerIndex)
253  return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer)));
254  else
255  return Scalar(0);
256 
257  } else {
258  const Index maxInnerIndex = outer + m_data.lowerProfile(outer);
259  if (inner <= maxInnerIndex)
260  return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer));
261  else
262  return Scalar(0);
263  }
264  }
265 
266  inline Scalar coeffUpper(Index row, Index col) const {
267  const Index outer = IsRowMajor ? row : col;
268  const Index inner = IsRowMajor ? col : row;
269 
270  eigen_assert(outer < outerSize());
271  eigen_assert(inner < innerSize());
272  eigen_assert(inner != outer);
273 
274  if (IsRowMajor) {
275  const Index minOuterIndex = inner - m_data.upperProfile(inner);
276  if (outer >= minOuterIndex)
277  return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner)));
278  else
279  return Scalar(0);
280  } else {
281  const Index maxOuterIndex = inner + m_data.upperProfile(inner);
282  if (outer <= maxOuterIndex)
283  return this->m_data.upper(m_colStartIndex[inner] + (outer - inner));
284  else
285  return Scalar(0);
286  }
287  }
288 
289  inline Scalar& coeffRefDiag(Index idx) {
290  eigen_assert(idx < outerSize());
291  eigen_assert(idx < innerSize());
292  return this->m_data.diag(idx);
293  }
294 
295  inline Scalar& coeffRefLower(Index row, Index col) {
296  const Index outer = IsRowMajor ? row : col;
297  const Index inner = IsRowMajor ? col : row;
298 
299  eigen_assert(outer < outerSize());
300  eigen_assert(inner < innerSize());
301  eigen_assert(inner != outer);
302 
303  if (IsRowMajor) {
304  const Index minInnerIndex = outer - m_data.lowerProfile(outer);
305  eigen_assert(inner >= minInnerIndex && "You tried to access a coeff that does not exist in the storage");
306  return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer)));
307  } else {
308  const Index maxInnerIndex = outer + m_data.lowerProfile(outer);
309  eigen_assert(inner <= maxInnerIndex && "You tried to access a coeff that does not exist in the storage");
310  return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer));
311  }
312  }
313 
314  inline bool coeffExistLower(Index row, Index col) {
315  const Index outer = IsRowMajor ? row : col;
316  const Index inner = IsRowMajor ? col : row;
317 
318  eigen_assert(outer < outerSize());
319  eigen_assert(inner < innerSize());
320  eigen_assert(inner != outer);
321 
322  if (IsRowMajor) {
323  const Index minInnerIndex = outer - m_data.lowerProfile(outer);
324  return inner >= minInnerIndex;
325  } else {
326  const Index maxInnerIndex = outer + m_data.lowerProfile(outer);
327  return inner <= maxInnerIndex;
328  }
329  }
330 
331  inline Scalar& coeffRefUpper(Index row, Index col) {
332  const Index outer = IsRowMajor ? row : col;
333  const Index inner = IsRowMajor ? col : row;
334 
335  eigen_assert(outer < outerSize());
336  eigen_assert(inner < innerSize());
337  eigen_assert(inner != outer);
338 
339  if (IsRowMajor) {
340  const Index minOuterIndex = inner - m_data.upperProfile(inner);
341  eigen_assert(outer >= minOuterIndex && "You tried to access a coeff that does not exist in the storage");
342  return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner)));
343  } else {
344  const Index maxOuterIndex = inner + m_data.upperProfile(inner);
345  eigen_assert(outer <= maxOuterIndex && "You tried to access a coeff that does not exist in the storage");
346  return this->m_data.upper(m_colStartIndex[inner] + (outer - inner));
347  }
348  }
349 
350  inline bool coeffExistUpper(Index row, Index col) {
351  const Index outer = IsRowMajor ? row : col;
352  const Index inner = IsRowMajor ? col : row;
353 
354  eigen_assert(outer < outerSize());
355  eigen_assert(inner < innerSize());
356  eigen_assert(inner != outer);
357 
358  if (IsRowMajor) {
359  const Index minOuterIndex = inner - m_data.upperProfile(inner);
360  return outer >= minOuterIndex;
361  } else {
362  const Index maxOuterIndex = inner + m_data.upperProfile(inner);
363  return outer <= maxOuterIndex;
364  }
365  }
366 
367 
368 protected:
369 
370 public:
371  class InnerUpperIterator;
372  class InnerLowerIterator;
373 
374  class OuterUpperIterator;
375  class OuterLowerIterator;
376 
378  inline void setZero() {
379  m_data.clear();
380  std::fill_n(m_colStartIndex, m_outerSize + 1, Index(0));
381  std::fill_n(m_rowStartIndex, m_outerSize + 1, Index(0));
382  }
383 
385  inline Index nonZeros() const {
386  return m_data.diagSize() + m_data.upperSize() + m_data.lowerSize();
387  }
388 
390  inline void reserve(Index reserveSize, Index reserveUpperSize, Index reserveLowerSize) {
391  m_data.reserve(reserveSize, reserveUpperSize, reserveLowerSize);
392  }
393 
403  const Index outer = IsRowMajor ? row : col;
404  const Index inner = IsRowMajor ? col : row;
405 
406  eigen_assert(outer < outerSize());
407  eigen_assert(inner < innerSize());
408 
409  if (outer == inner)
410  return m_data.diag(col);
411 
412  if (IsRowMajor) {
413  if (outer < inner) //upper matrix
414  {
415  Index minOuterIndex = 0;
416  minOuterIndex = inner - m_data.upperProfile(inner);
417 
418  if (outer < minOuterIndex) //The value does not yet exist
419  {
420  const Index previousProfile = m_data.upperProfile(inner);
421 
422  m_data.upperProfile(inner) = inner - outer;
423 
424 
425  const Index bandIncrement = m_data.upperProfile(inner) - previousProfile;
426  //shift data stored after this new one
427  const Index stop = m_colStartIndex[cols()];
428  const Index start = m_colStartIndex[inner];
429 
430 
431  for (Index innerIdx = stop; innerIdx >= start; innerIdx--) {
432  m_data.upper(innerIdx + bandIncrement) = m_data.upper(innerIdx);
433  }
434 
435  for (Index innerIdx = cols(); innerIdx > inner; innerIdx--) {
436  m_colStartIndex[innerIdx] += bandIncrement;
437  }
438 
439  //zeros new data
440  std::fill_n(this->_upperPtr() + start, bandIncrement - 1, Scalar(0));
441 
442  return m_data.upper(m_colStartIndex[inner]);
443  } else {
444  return m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner)));
445  }
446  }
447 
448  if (outer > inner) //lower matrix
449  {
450  const Index minInnerIndex = outer - m_data.lowerProfile(outer);
451  if (inner < minInnerIndex) //The value does not yet exist
452  {
453  const Index previousProfile = m_data.lowerProfile(outer);
454  m_data.lowerProfile(outer) = outer - inner;
455 
456  const Index bandIncrement = m_data.lowerProfile(outer) - previousProfile;
457  //shift data stored after this new one
458  const Index stop = m_rowStartIndex[rows()];
459  const Index start = m_rowStartIndex[outer];
460 
461 
462  for (Index innerIdx = stop; innerIdx >= start; innerIdx--) {
463  m_data.lower(innerIdx + bandIncrement) = m_data.lower(innerIdx);
464  }
465 
466  for (Index innerIdx = rows(); innerIdx > outer; innerIdx--) {
467  m_rowStartIndex[innerIdx] += bandIncrement;
468  }
469 
470  //zeros new data
471  std::fill_n(this->_lowerPtr() + start, bandIncrement - 1, Scalar(0));
472  return m_data.lower(m_rowStartIndex[outer]);
473  } else {
474  return m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer)));
475  }
476  }
477  } else {
478  if (outer > inner) //upper matrix
479  {
480  const Index maxOuterIndex = inner + m_data.upperProfile(inner);
481  if (outer > maxOuterIndex) //The value does not yet exist
482  {
483  const Index previousProfile = m_data.upperProfile(inner);
484  m_data.upperProfile(inner) = outer - inner;
485 
486  const Index bandIncrement = m_data.upperProfile(inner) - previousProfile;
487  //shift data stored after this new one
488  const Index stop = m_rowStartIndex[rows()];
489  const Index start = m_rowStartIndex[inner + 1];
490 
491  for (Index innerIdx = stop; innerIdx >= start; innerIdx--) {
492  m_data.upper(innerIdx + bandIncrement) = m_data.upper(innerIdx);
493  }
494 
495  for (Index innerIdx = inner + 1; innerIdx < outerSize() + 1; innerIdx++) {
496  m_rowStartIndex[innerIdx] += bandIncrement;
497  }
498  std::fill_n(this->_upperPtr() + m_rowStartIndex[inner] + previousProfile + 1, bandIncrement - 1, Scalar(0));
499  return m_data.upper(m_rowStartIndex[inner] + m_data.upperProfile(inner));
500  } else {
501  return m_data.upper(m_rowStartIndex[inner] + (outer - inner));
502  }
503  }
504 
505  if (outer < inner) //lower matrix
506  {
507  const Index maxInnerIndex = outer + m_data.lowerProfile(outer);
508  if (inner > maxInnerIndex) //The value does not yet exist
509  {
510  const Index previousProfile = m_data.lowerProfile(outer);
511  m_data.lowerProfile(outer) = inner - outer;
512 
513  const Index bandIncrement = m_data.lowerProfile(outer) - previousProfile;
514  //shift data stored after this new one
515  const Index stop = m_colStartIndex[cols()];
516  const Index start = m_colStartIndex[outer + 1];
517 
518  for (Index innerIdx = stop; innerIdx >= start; innerIdx--) {
519  m_data.lower(innerIdx + bandIncrement) = m_data.lower(innerIdx);
520  }
521 
522  for (Index innerIdx = outer + 1; innerIdx < outerSize() + 1; innerIdx++) {
523  m_colStartIndex[innerIdx] += bandIncrement;
524  }
525  std::fill_n(this->_lowerPtr() + m_colStartIndex[outer] + previousProfile + 1, bandIncrement - 1, Scalar(0));
526  return m_data.lower(m_colStartIndex[outer] + m_data.lowerProfile(outer));
527  } else {
528  return m_data.lower(m_colStartIndex[outer] + (inner - outer));
529  }
530  }
531  }
532  }
533 
536  inline void finalize() {
537  if (IsRowMajor) {
538  if (rows() > cols())
539  m_data.resize(cols(), cols(), rows(), m_colStartIndex[cols()] + 1, m_rowStartIndex[rows()] + 1);
540  else
541  m_data.resize(rows(), cols(), rows(), m_colStartIndex[cols()] + 1, m_rowStartIndex[rows()] + 1);
542 
543  // eigen_assert(rows() == cols() && "memory reorganisatrion only works with suare matrix");
544  //
545  // Scalar* newArray = new Scalar[m_colStartIndex[cols()] + 1 + m_rowStartIndex[rows()] + 1];
546  // Index dataIdx = 0;
547  // for (Index row = 0; row < rows(); row++) {
548  //
549  // const Index nbLowerElts = m_rowStartIndex[row + 1] - m_rowStartIndex[row];
550  // // std::cout << "nbLowerElts" << nbLowerElts << std::endl;
551  // memcpy(newArray + dataIdx, m_data.m_lower + m_rowStartIndex[row], nbLowerElts * sizeof (Scalar));
552  // m_rowStartIndex[row] = dataIdx;
553  // dataIdx += nbLowerElts;
554  //
555  // const Index nbUpperElts = m_colStartIndex[row + 1] - m_colStartIndex[row];
556  // memcpy(newArray + dataIdx, m_data.m_upper + m_colStartIndex[row], nbUpperElts * sizeof (Scalar));
557  // m_colStartIndex[row] = dataIdx;
558  // dataIdx += nbUpperElts;
559  //
560  //
561  // }
562  // //todo : don't access m_data profile directly : add an accessor from SkylineMatrix
563  // m_rowStartIndex[rows()] = m_rowStartIndex[rows()-1] + m_data.lowerProfile(rows()-1);
564  // m_colStartIndex[cols()] = m_colStartIndex[cols()-1] + m_data.upperProfile(cols()-1);
565  //
566  // delete[] m_data.m_lower;
567  // delete[] m_data.m_upper;
568  //
569  // m_data.m_lower = newArray;
570  // m_data.m_upper = newArray;
571  } else {
572  if (rows() > cols())
573  m_data.resize(cols(), rows(), cols(), m_rowStartIndex[cols()] + 1, m_colStartIndex[cols()] + 1);
574  else
575  m_data.resize(rows(), rows(), cols(), m_rowStartIndex[rows()] + 1, m_colStartIndex[rows()] + 1);
576  }
577  }
578 
579  inline void squeeze() {
580  finalize();
581  m_data.squeeze();
582  }
583 
584  void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar > ()) {
585  //TODO
586  }
587 
591  void resize(size_t rows, size_t cols) {
592  const Index diagSize = rows > cols ? cols : rows;
594 
595  eigen_assert(rows == cols && "Skyline matrix must be square matrix");
596 
597  if (diagSize % 2) { // diagSize is odd
598  const Index k = (diagSize - 1) / 2;
599 
600  m_data.resize(diagSize, IsRowMajor ? cols : rows, IsRowMajor ? rows : cols,
601  2 * k * k + k + 1,
602  2 * k * k + k + 1);
603 
604  } else // diagSize is even
605  {
606  const Index k = diagSize / 2;
607  m_data.resize(diagSize, IsRowMajor ? cols : rows, IsRowMajor ? rows : cols,
608  2 * k * k - k + 1,
609  2 * k * k - k + 1);
610  }
611 
613  delete[] m_colStartIndex;
614  delete[] m_rowStartIndex;
615  }
616  m_colStartIndex = new Index [cols + 1];
617  m_rowStartIndex = new Index [rows + 1];
618  m_outerSize = diagSize;
619 
620  m_data.reset();
621  m_data.clear();
622 
623  m_outerSize = diagSize;
624  std::fill_n(m_colStartIndex, cols + 1, Index(0));
625  std::fill_n(m_rowStartIndex, rows + 1, Index(0));
626  }
627 
629  m_data.resize(size);
630  }
631 
632  inline SkylineMatrix()
634  resize(0, 0);
635  }
636 
637  inline SkylineMatrix(size_t rows, size_t cols)
639  resize(rows, cols);
640  }
641 
642  template<typename OtherDerived>
645  *this = other.derived();
646  }
647 
648  inline SkylineMatrix(const SkylineMatrix & other)
649  : Base(), m_outerSize(0), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) {
650  *this = other.derived();
651  }
652 
653  inline void swap(SkylineMatrix & other) {
654  //EIGEN_DBG_SKYLINE(std::cout << "SkylineMatrix:: swap\n");
655  std::swap(m_colStartIndex, other.m_colStartIndex);
656  std::swap(m_rowStartIndex, other.m_rowStartIndex);
657  std::swap(m_innerSize, other.m_innerSize);
658  std::swap(m_outerSize, other.m_outerSize);
659  m_data.swap(other.m_data);
660  }
661 
662  inline SkylineMatrix & operator=(const SkylineMatrix & other) {
663  std::cout << "SkylineMatrix& operator=(const SkylineMatrix& other)\n";
664  if (other.isRValue()) {
665  swap(other.const_cast_derived());
666  } else {
667  resize(other.rows(), other.cols());
668  memcpy(m_colStartIndex, other.m_colStartIndex, (m_outerSize + 1) * sizeof (Index));
669  memcpy(m_rowStartIndex, other.m_rowStartIndex, (m_outerSize + 1) * sizeof (Index));
670  m_data = other.m_data;
671  }
672  return *this;
673  }
674 
675  template<typename OtherDerived>
677  const bool needToTranspose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
678  if (needToTranspose) {
679  // TODO
680  // return *this;
681  } else {
682  // there is no special optimization
684  }
685  }
686 
687  friend std::ostream & operator <<(std::ostream & s, const SkylineMatrix & m) {
688 
690  std::cout << "upper elements : " << std::endl;
691  for (Index i = 0; i < m.m_data.upperSize(); i++)
692  std::cout << m.m_data.upper(i) << "\t";
693  std::cout << std::endl;
694  std::cout << "upper profile : " << std::endl;
695  for (Index i = 0; i < m.m_data.upperProfileSize(); i++)
696  std::cout << m.m_data.upperProfile(i) << "\t";
697  std::cout << std::endl;
698  std::cout << "lower startIdx : " << std::endl;
699  for (Index i = 0; i < m.m_data.upperProfileSize(); i++)
700  std::cout << (IsRowMajor ? m.m_colStartIndex[i] : m.m_rowStartIndex[i]) << "\t";
701  std::cout << std::endl;
702 
703 
704  std::cout << "lower elements : " << std::endl;
705  for (Index i = 0; i < m.m_data.lowerSize(); i++)
706  std::cout << m.m_data.lower(i) << "\t";
707  std::cout << std::endl;
708  std::cout << "lower profile : " << std::endl;
709  for (Index i = 0; i < m.m_data.lowerProfileSize(); i++)
710  std::cout << m.m_data.lowerProfile(i) << "\t";
711  std::cout << std::endl;
712  std::cout << "lower startIdx : " << std::endl;
713  for (Index i = 0; i < m.m_data.lowerProfileSize(); i++)
714  std::cout << (IsRowMajor ? m.m_rowStartIndex[i] : m.m_colStartIndex[i]) << "\t";
715  std::cout << std::endl;
716  );
717  for (Index rowIdx = 0; rowIdx < m.rows(); rowIdx++) {
718  for (Index colIdx = 0; colIdx < m.cols(); colIdx++) {
719  s << m.coeff(rowIdx, colIdx) << "\t";
720  }
721  s << std::endl;
722  }
723  return s;
724  }
725 
727  inline ~SkylineMatrix() {
728  delete[] m_colStartIndex;
729  delete[] m_rowStartIndex;
730  }
731 
733  Scalar sum() const;
734 };
735 
736 template<typename Scalar, int Options_>
738 public:
739 
741  : m_matrix(mat), m_outer(outer),
742  m_id(Options_ == RowMajor ? mat.m_colStartIndex[outer] : mat.m_rowStartIndex[outer] + 1),
743  m_start(m_id),
744  m_end(Options_ == RowMajor ? mat.m_colStartIndex[outer + 1] : mat.m_rowStartIndex[outer + 1] + 1) {
745  }
746 
748  m_id++;
749  return *this;
750  }
751 
753  m_id += shift;
754  return *this;
755  }
756 
757  inline Scalar value() const {
758  return m_matrix.m_data.upper(m_id);
759  }
760 
761  inline Scalar* valuePtr() {
762  return const_cast<Scalar*> (&(m_matrix.m_data.upper(m_id)));
763  }
764 
765  inline Scalar& valueRef() {
766  return const_cast<Scalar&> (m_matrix.m_data.upper(m_id));
767  }
768 
769  inline Index index() const {
770  return IsRowMajor ? m_outer - m_matrix.m_data.upperProfile(m_outer) + (m_id - m_start) :
771  m_outer + (m_id - m_start) + 1;
772  }
773 
774  inline Index row() const {
775  return IsRowMajor ? index() : m_outer;
776  }
777 
778  inline Index col() const {
779  return IsRowMajor ? m_outer : index();
780  }
781 
782  inline size_t size() const {
783  return m_matrix.m_data.upperProfile(m_outer);
784  }
785 
786  inline operator bool() const {
787  return (m_id < m_end) && (m_id >= m_start);
788  }
789 
790 protected:
792  const Index m_outer;
794  const Index m_start;
795  const Index m_end;
796 };
797 
798 template<typename Scalar, int Options_>
800 public:
801 
803  : m_matrix(mat),
804  m_outer(outer),
805  m_id(Options_ == RowMajor ? mat.m_rowStartIndex[outer] : mat.m_colStartIndex[outer] + 1),
806  m_start(m_id),
807  m_end(Options_ == RowMajor ? mat.m_rowStartIndex[outer + 1] : mat.m_colStartIndex[outer + 1] + 1) {
808  }
809 
811  m_id++;
812  return *this;
813  }
814 
816  m_id += shift;
817  return *this;
818  }
819 
820  inline Scalar value() const {
821  return m_matrix.m_data.lower(m_id);
822  }
823 
824  inline Scalar* valuePtr() {
825  return const_cast<Scalar*> (&(m_matrix.m_data.lower(m_id)));
826  }
827 
828  inline Scalar& valueRef() {
829  return const_cast<Scalar&> (m_matrix.m_data.lower(m_id));
830  }
831 
832  inline Index index() const {
833  return IsRowMajor ? m_outer - m_matrix.m_data.lowerProfile(m_outer) + (m_id - m_start) :
834  m_outer + (m_id - m_start) + 1;
835  ;
836  }
837 
838  inline Index row() const {
839  return IsRowMajor ? m_outer : index();
840  }
841 
842  inline Index col() const {
843  return IsRowMajor ? index() : m_outer;
844  }
845 
846  inline size_t size() const {
847  return m_matrix.m_data.lowerProfile(m_outer);
848  }
849 
850  inline operator bool() const {
851  return (m_id < m_end) && (m_id >= m_start);
852  }
853 
854 protected:
856  const Index m_outer;
858  const Index m_start;
859  const Index m_end;
860 };
861 
862 } // end namespace Eigen
863 
864 #endif // EIGEN_SKYLINEMATRIX_H
Matrix3f m
int i
RowXpr row(Index i) const
ColXpr col(Index i) const
#define EIGEN_DONT_INLINE
#define eigen_assert(x)
for(int i=0;i< 24;++i) array[i]
#define EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived)
Definition: SkylineUtil.h:62
#define EIGEN_DBG_SKYLINE(X)
Definition: SkylineUtil.h:20
#define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op)
Definition: SkylineUtil.h:29
MatrixXf mat
Base class of any skyline matrices or skyline expressions.
Derived & operator=(const Derived &other)
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
internal::traits< SkylineMatrix< Scalar_, Options_ > >::Scalar Scalar
InnerLowerIterator(const SkylineMatrix &mat, Index outer)
InnerLowerIterator & operator+=(Index shift)
InnerUpperIterator(const SkylineMatrix &mat, Index outer)
InnerUpperIterator & operator+=(Index shift)
The main skyline matrix class.
Definition: SkylineMatrix.h:54
Index nonZeros() const
void resize(size_t rows, size_t cols)
Index outerSize() const
Definition: SkylineMatrix.h:88
Scalar coeffDiag(Index idx) const
void prune(Scalar reference, RealScalar epsilon=dummy_precision< RealScalar >())
Index cols() const
Definition: SkylineMatrix.h:80
SkylineMatrix(size_t rows, size_t cols)
SkylineMatrix(const SkylineMatrixBase< OtherDerived > &other)
bool coeffExistUpper(Index row, Index col)
friend std::ostream & operator<<(std::ostream &s, const SkylineMatrix &m)
SkylineMatrix< Scalar,(Flags &~RowMajorBit)|(IsRowMajor ? RowMajorBit :0) > TransposedSkylineMatrix
Definition: SkylineMatrix.h:64
Index rows() const
Definition: SkylineMatrix.h:76
Scalar & coeffRefLower(Index row, Index col)
Index innerSize() const
Definition: SkylineMatrix.h:84
const Index * _lowerProfilePtr() const
Scalar coeff(Index row, Index col) const
const Scalar * _lowerPtr() const
Scalar & coeffRefDiag(Index idx)
Scalar sum() const
Index * _upperProfilePtr()
Scalar coeffLower(Index row, Index col) const
Scalar coeffUpper(Index row, Index col) const
void resizeNonZeros(Index size)
SkylineStorage< Scalar > m_data
Definition: SkylineMatrix.h:72
Index lowerNonZeros() const
Definition: SkylineMatrix.h:96
SkylineMatrix & operator=(const SkylineMatrixBase< OtherDerived > &other)
void reserve(Index reserveSize, Index reserveUpperSize, Index reserveLowerSize)
Index upperNonZeros(Index j) const
bool coeffExistLower(Index row, Index col)
EIGEN_DONT_INLINE Scalar & insert(Index row, Index col)
SkylineMatrix & operator=(const SkylineMatrix &other)
Index lowerNonZeros(Index j) const
Index * _lowerProfilePtr()
const Scalar * _upperPtr() const
Scalar & coeffRefUpper(Index row, Index col)
Scalar & coeffRef(Index row, Index col)
void swap(SkylineMatrix &other)
Index upperNonZeros() const
Definition: SkylineMatrix.h:92
SkylineMatrix(const SkylineMatrix &other)
const Index * _upperProfilePtr() const
const Scalar * _diagPtr() const
Scalar & lower(Index i)
Scalar & upper(Index i)
Scalar & diag(Index i)
const unsigned int RowMajorBit
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
const unsigned int SkylineBit
Definition: SkylineUtil.h:23
const int Dynamic
Derived & derived()
Eigen::Index Index
Derived & const_cast_derived() const
std::ptrdiff_t j