10#ifndef EIGEN_SKYLINEMATRIX_H
11#define EIGEN_SKYLINEMATRIX_H
34template<
typename _Scalar,
int _Options>
50template<
typename _Scalar,
int _Options>
58 using Base::IsRowMajor;
131 return &
m_data.upperProfile(0);
135 return &
m_data.upperProfile(0);
139 return &
m_data.lowerProfile(0);
143 return &
m_data.lowerProfile(0);
154 return this->m_data.
diag(outer);
159 const Index minOuterIndex = inner -
m_data.upperProfile(inner);
160 if (outer >= minOuterIndex)
167 const Index minInnerIndex = outer -
m_data.lowerProfile(outer);
168 if (inner >= minInnerIndex)
177 const Index maxOuterIndex = inner +
m_data.upperProfile(inner);
178 if (outer <= maxOuterIndex)
185 const Index maxInnerIndex = outer +
m_data.lowerProfile(outer);
187 if (inner <= maxInnerIndex)
203 return this->m_data.
diag(outer);
208 const Index minOuterIndex = inner -
m_data.upperProfile(inner);
209 eigen_assert(outer >= minOuterIndex &&
"You tried to access a coeff that does not exist in the storage");
214 const Index minInnerIndex = outer -
m_data.lowerProfile(outer);
215 eigen_assert(inner >= minInnerIndex &&
"You tried to access a coeff that does not exist in the storage");
221 const Index maxOuterIndex = inner +
m_data.upperProfile(inner);
222 eigen_assert(outer <= maxOuterIndex &&
"You tried to access a coeff that does not exist in the storage");
227 const Index maxInnerIndex = outer +
m_data.lowerProfile(outer);
228 eigen_assert(inner <= maxInnerIndex &&
"You tried to access a coeff that does not exist in the storage");
237 return this->m_data.
diag(idx);
249 const Index minInnerIndex = outer -
m_data.lowerProfile(outer);
250 if (inner >= minInnerIndex)
256 const Index maxInnerIndex = outer +
m_data.lowerProfile(outer);
257 if (inner <= maxInnerIndex)
273 const Index minOuterIndex = inner -
m_data.upperProfile(inner);
274 if (outer >= minOuterIndex)
279 const Index maxOuterIndex = inner +
m_data.upperProfile(inner);
280 if (outer <= maxOuterIndex)
290 return this->m_data.
diag(idx);
302 const Index minInnerIndex = outer -
m_data.lowerProfile(outer);
303 eigen_assert(inner >= minInnerIndex &&
"You tried to access a coeff that does not exist in the storage");
306 const Index maxInnerIndex = outer +
m_data.lowerProfile(outer);
307 eigen_assert(inner <= maxInnerIndex &&
"You tried to access a coeff that does not exist in the storage");
321 const Index minInnerIndex = outer -
m_data.lowerProfile(outer);
322 return inner >= minInnerIndex;
324 const Index maxInnerIndex = outer +
m_data.lowerProfile(outer);
325 return inner <= maxInnerIndex;
338 const Index minOuterIndex = inner -
m_data.upperProfile(inner);
339 eigen_assert(outer >= minOuterIndex &&
"You tried to access a coeff that does not exist in the storage");
342 const Index maxOuterIndex = inner +
m_data.upperProfile(inner);
343 eigen_assert(outer <= maxOuterIndex &&
"You tried to access a coeff that does not exist in the storage");
357 const Index minOuterIndex = inner -
m_data.upperProfile(inner);
358 return outer >= minOuterIndex;
360 const Index maxOuterIndex = inner +
m_data.upperProfile(inner);
361 return outer <= maxOuterIndex;
369 class InnerUpperIterator;
370 class InnerLowerIterator;
372 class OuterUpperIterator;
373 class OuterLowerIterator;
389 m_data.reserve(reserveSize, reserveUpperSize, reserveLowerSize);
413 Index minOuterIndex = 0;
414 minOuterIndex = inner -
m_data.upperProfile(inner);
416 if (outer < minOuterIndex)
418 const Index previousProfile =
m_data.upperProfile(inner);
420 m_data.upperProfile(inner) = inner - outer;
423 const Index bandIncrement =
m_data.upperProfile(inner) - previousProfile;
429 for (
Index innerIdx = stop; innerIdx >= start; innerIdx--) {
430 m_data.upper(innerIdx + bandIncrement) =
m_data.upper(innerIdx);
433 for (
Index innerIdx =
cols(); innerIdx > inner; innerIdx--) {
438 memset(this->
_upperPtr() + start, 0, (bandIncrement - 1) *
sizeof (
Scalar));
448 const Index minInnerIndex = outer -
m_data.lowerProfile(outer);
449 if (inner < minInnerIndex)
451 const Index previousProfile =
m_data.lowerProfile(outer);
452 m_data.lowerProfile(outer) = outer - inner;
454 const Index bandIncrement =
m_data.lowerProfile(outer) - previousProfile;
460 for (
Index innerIdx = stop; innerIdx >= start; innerIdx--) {
461 m_data.lower(innerIdx + bandIncrement) =
m_data.lower(innerIdx);
464 for (
Index innerIdx =
rows(); innerIdx > outer; innerIdx--) {
469 memset(this->
_lowerPtr() + start, 0, (bandIncrement - 1) *
sizeof (
Scalar));
478 const Index maxOuterIndex = inner +
m_data.upperProfile(inner);
479 if (outer > maxOuterIndex)
481 const Index previousProfile =
m_data.upperProfile(inner);
482 m_data.upperProfile(inner) = outer - inner;
484 const Index bandIncrement =
m_data.upperProfile(inner) - previousProfile;
489 for (
Index innerIdx = stop; innerIdx >= start; innerIdx--) {
490 m_data.upper(innerIdx + bandIncrement) =
m_data.upper(innerIdx);
493 for (
Index innerIdx = inner + 1; innerIdx <
outerSize() + 1; innerIdx++) {
496 memset(this->
_upperPtr() + m_rowStartIndex[inner] + previousProfile + 1, 0, (bandIncrement - 1) *
sizeof (
Scalar));
505 const Index maxInnerIndex = outer +
m_data.lowerProfile(outer);
506 if (inner > maxInnerIndex)
508 const Index previousProfile =
m_data.lowerProfile(outer);
509 m_data.lowerProfile(outer) = inner - outer;
511 const Index bandIncrement =
m_data.lowerProfile(outer) - previousProfile;
516 for (
Index innerIdx = stop; innerIdx >= start; innerIdx--) {
517 m_data.lower(innerIdx + bandIncrement) =
m_data.lower(innerIdx);
520 for (
Index innerIdx = outer + 1; innerIdx <
outerSize() + 1; innerIdx++) {
523 memset(this->
_lowerPtr() + m_colStartIndex[outer] + previousProfile + 1, 0, (bandIncrement - 1) *
sizeof (
Scalar));
596 const Index k = (diagSize - 1) / 2;
604 const Index k = diagSize / 2;
640 template<
typename OtherDerived>
661 std::cout <<
"SkylineMatrix& operator=(const SkylineMatrix& other)\n";
673 template<
typename OtherDerived>
676 if (needToTranspose) {
688 std::cout <<
"upper elements : " << std::endl;
689 for (
Index i = 0;
i <
m.m_data.upperSize();
i++)
690 std::cout <<
m.m_data.upper(
i) <<
"\t";
691 std::cout << std::endl;
692 std::cout <<
"upper profile : " << std::endl;
693 for (
Index i = 0;
i <
m.m_data.upperProfileSize();
i++)
694 std::cout <<
m.m_data.upperProfile(
i) <<
"\t";
695 std::cout << std::endl;
696 std::cout <<
"lower startIdx : " << std::endl;
697 for (
Index i = 0;
i <
m.m_data.upperProfileSize();
i++)
698 std::cout << (
IsRowMajor ?
m.m_colStartIndex[
i] :
m.m_rowStartIndex[
i]) <<
"\t";
699 std::cout << std::endl;
702 std::cout <<
"lower elements : " << std::endl;
703 for (
Index i = 0;
i <
m.m_data.lowerSize();
i++)
704 std::cout <<
m.m_data.lower(
i) <<
"\t";
705 std::cout << std::endl;
706 std::cout <<
"lower profile : " << std::endl;
707 for (
Index i = 0;
i <
m.m_data.lowerProfileSize();
i++)
708 std::cout <<
m.m_data.lowerProfile(
i) <<
"\t";
709 std::cout << std::endl;
710 std::cout <<
"lower startIdx : " << std::endl;
711 for (
Index i = 0;
i <
m.m_data.lowerProfileSize();
i++)
712 std::cout << (
IsRowMajor ?
m.m_rowStartIndex[
i] :
m.m_colStartIndex[
i]) <<
"\t";
713 std::cout << std::endl;
715 for (
Index rowIdx = 0; rowIdx <
m.rows(); rowIdx++) {
716 for (
Index colIdx = 0; colIdx <
m.cols(); colIdx++) {
717 s <<
m.coeff(rowIdx, colIdx) <<
"\t";
734template<
typename Scalar,
int _Options>
739 : m_matrix(
mat), m_outer(outer),
756 return m_matrix.m_data.upper(m_id);
760 return const_cast<Scalar*
> (&(m_matrix.m_data.upper(m_id)));
764 return const_cast<Scalar&
> (m_matrix.m_data.upper(m_id));
768 return IsRowMajor ? m_outer - m_matrix.m_data.upperProfile(m_outer) + (m_id - m_start) :
769 m_outer + (m_id - m_start) + 1;
781 return m_matrix.m_data.upperProfile(m_outer);
784 inline operator bool()
const {
785 return (m_id < m_end) && (m_id >= m_start);
796template<
typename Scalar,
int _Options>
819 return m_matrix.m_data.lower(m_id);
823 return const_cast<Scalar*
> (&(m_matrix.m_data.lower(m_id)));
827 return const_cast<Scalar&
> (m_matrix.m_data.lower(m_id));
831 return IsRowMajor ? m_outer - m_matrix.m_data.lowerProfile(m_outer) + (m_id - m_start) :
832 m_outer + (m_id - m_start) + 1;
845 return m_matrix.m_data.lowerProfile(m_outer);
848 inline operator bool()
const {
849 return (m_id < m_end) && (m_id >= m_start);
Matrix3f m
Definition AngleAxis_mimic_euler.cpp:1
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_DONT_INLINE
Definition Macros.h:940
#define eigen_assert(x)
Definition Macros.h:1037
#define EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived)
Definition SkylineUtil.h:60
#define EIGEN_DBG_SKYLINE(X)
Definition SkylineUtil.h:18
#define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op)
Definition SkylineUtil.h:27
MatrixXf mat
Definition Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Base class of any skyline matrices or skyline expressions.
Definition SkylineMatrixBase.h:26
Derived & const_cast_derived() const
Definition SkylineMatrixBase.h:99
NumTraits< Scalar >::Real RealScalar
Definition SkylineMatrixBase.h:85
Derived & operator=(const Derived &other)
Definition SkylineMatrixBase.h:151
const Derived & derived() const
Definition SkylineMatrixBase.h:91
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition SkylineMatrixBase.h:116
internal::index< StorageKind >::type Index
Definition SkylineMatrixBase.h:31
internal::traits< SkylineMatrix< _Scalar, _Options > >::Scalar Scalar
Definition SkylineMatrixBase.h:29
@ Flags
Definition SkylineMatrixBase.h:65
@ IsRowMajor
Definition SkylineMatrixBase.h:75
bool isRValue() const
Definition SkylineMatrixBase.h:138
Definition SkylineMatrix.h:797
Scalar & valueRef()
Definition SkylineMatrix.h:826
const Index m_end
Definition SkylineMatrix.h:857
Index index() const
Definition SkylineMatrix.h:830
InnerLowerIterator(const SkylineMatrix &mat, Index outer)
Definition SkylineMatrix.h:800
InnerLowerIterator & operator++()
Definition SkylineMatrix.h:808
Index col() const
Definition SkylineMatrix.h:840
Index row() const
Definition SkylineMatrix.h:836
Scalar * valuePtr()
Definition SkylineMatrix.h:822
const Index m_outer
Definition SkylineMatrix.h:854
Scalar value() const
Definition SkylineMatrix.h:818
const Index m_start
Definition SkylineMatrix.h:856
Index m_id
Definition SkylineMatrix.h:855
const SkylineMatrix & m_matrix
Definition SkylineMatrix.h:853
size_t size() const
Definition SkylineMatrix.h:844
InnerLowerIterator & operator+=(Index shift)
Definition SkylineMatrix.h:813
Definition SkylineMatrix.h:735
const Index m_start
Definition SkylineMatrix.h:792
Index col() const
Definition SkylineMatrix.h:776
Index index() const
Definition SkylineMatrix.h:767
const Index m_end
Definition SkylineMatrix.h:793
const Index m_outer
Definition SkylineMatrix.h:790
const SkylineMatrix & m_matrix
Definition SkylineMatrix.h:789
Scalar * valuePtr()
Definition SkylineMatrix.h:759
Scalar & valueRef()
Definition SkylineMatrix.h:763
InnerUpperIterator & operator++()
Definition SkylineMatrix.h:745
InnerUpperIterator(const SkylineMatrix &mat, Index outer)
Definition SkylineMatrix.h:738
Index row() const
Definition SkylineMatrix.h:772
InnerUpperIterator & operator+=(Index shift)
Definition SkylineMatrix.h:750
Scalar value() const
Definition SkylineMatrix.h:755
size_t size() const
Definition SkylineMatrix.h:780
Index m_id
Definition SkylineMatrix.h:791
The main skyline matrix class.
Definition SkylineMatrix.h:52
const Scalar * _upperPtr() const
Definition SkylineMatrix.h:114
void resizeNonZeros(Index size)
Definition SkylineMatrix.h:626
const Scalar * _lowerPtr() const
Definition SkylineMatrix.h:122
Index outerSize() const
Definition SkylineMatrix.h:86
void finalize()
Definition SkylineMatrix.h:534
Index lowerNonZeros() const
Definition SkylineMatrix.h:94
const Scalar * _diagPtr() const
Definition SkylineMatrix.h:106
Scalar & coeffRefUpper(Index row, Index col)
Definition SkylineMatrix.h:329
SkylineMatrix & operator=(const SkylineMatrixBase< OtherDerived > &other)
Definition SkylineMatrix.h:674
Index * _upperProfilePtr()
Definition SkylineMatrix.h:134
bool coeffExistLower(Index row, Index col)
Definition SkylineMatrix.h:312
Index cols() const
Definition SkylineMatrix.h:78
Scalar coeffUpper(Index row, Index col) const
Definition SkylineMatrix.h:264
~SkylineMatrix()
Definition SkylineMatrix.h:725
Index * _lowerProfilePtr()
Definition SkylineMatrix.h:142
SkylineMatrix(size_t rows, size_t cols)
Definition SkylineMatrix.h:635
Scalar * _diagPtr()
Definition SkylineMatrix.h:110
Scalar & coeffRefDiag(Index idx)
Definition SkylineMatrix.h:287
Scalar coeffDiag(Index idx) const
Definition SkylineMatrix.h:234
const Index * _upperProfilePtr() const
Definition SkylineMatrix.h:130
SkylineStorage< Scalar > m_data
Definition SkylineMatrix.h:70
Index upperNonZeros() const
Definition SkylineMatrix.h:90
EIGEN_DONT_INLINE Scalar & insert(Index row, Index col)
Definition SkylineMatrix.h:400
Scalar & coeffRefLower(Index row, Index col)
Definition SkylineMatrix.h:293
SkylineMatrix(const SkylineMatrixBase< OtherDerived > &other)
Definition SkylineMatrix.h:641
void resize(size_t rows, size_t cols)
Definition SkylineMatrix.h:589
SkylineMatrix & operator=(const SkylineMatrix &other)
Definition SkylineMatrix.h:660
void squeeze()
Definition SkylineMatrix.h:577
bool coeffExistUpper(Index row, Index col)
Definition SkylineMatrix.h:348
void reserve(Index reserveSize, Index reserveUpperSize, Index reserveLowerSize)
Definition SkylineMatrix.h:388
Index lowerNonZeros(Index j) const
Definition SkylineMatrix.h:102
Scalar * _upperPtr()
Definition SkylineMatrix.h:118
Scalar * _lowerPtr()
Definition SkylineMatrix.h:126
Index * m_colStartIndex
Definition SkylineMatrix.h:68
void swap(SkylineMatrix &other)
Definition SkylineMatrix.h:651
SkylineMatrix()
Definition SkylineMatrix.h:630
Scalar & coeffRef(Index row, Index col)
Definition SkylineMatrix.h:195
Index m_innerSize
Definition SkylineMatrix.h:65
Scalar coeffLower(Index row, Index col) const
Definition SkylineMatrix.h:240
Index innerSize() const
Definition SkylineMatrix.h:82
const Index * _lowerProfilePtr() const
Definition SkylineMatrix.h:138
Index upperNonZeros(Index j) const
Definition SkylineMatrix.h:98
Index nonZeros() const
Definition SkylineMatrix.h:383
Index rows() const
Definition SkylineMatrix.h:74
SkylineMatrix(const SkylineMatrix &other)
Definition SkylineMatrix.h:646
Index * m_rowStartIndex
Definition SkylineMatrix.h:69
friend std::ostream & operator<<(std::ostream &s, const SkylineMatrix &m)
Definition SkylineMatrix.h:685
Scalar coeff(Index row, Index col) const
Definition SkylineMatrix.h:146
Index m_outerSize
Definition SkylineMatrix.h:64
void prune(Scalar reference, RealScalar epsilon=dummy_precision< RealScalar >())
Definition SkylineMatrix.h:582
void setZero()
Definition SkylineMatrix.h:376
Definition SkylineStorage.h:22
Scalar & upper(Index i)
Definition SkylineStorage.h:144
Scalar & diag(Index i)
Definition SkylineStorage.h:136
Scalar & lower(Index i)
Definition SkylineStorage.h:152
@ RowMajor
Definition Constants.h:321
const unsigned int RowMajorBit
Definition Constants.h:66
RealScalar s
Definition level1_cplx_impl.h:126
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
const unsigned int SkylineBit
Definition SkylineUtil.h:21
const int Dynamic
Definition Constants.h:22
Definition BandTriangularSolver.h:13
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233
Definition Constants.h:510
Sparse StorageKind
Definition SkylineMatrix.h:37
_Scalar Scalar
Definition SkylineMatrix.h:36
Definition ForwardDeclarations.h:17
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2