10 #ifndef EIGEN_SKYLINEMATRIX_H 11 #define EIGEN_SKYLINEMATRIX_H 34 template<
typename _Scalar,
int _Options>
50 template<
typename _Scalar,
int _Options>
58 using Base::IsRowMajor;
75 return IsRowMajor ? m_outerSize : m_innerSize;
79 return IsRowMajor ? m_innerSize : m_outerSize;
99 return m_colStartIndex[j + 1] - m_colStartIndex[
j];
103 return m_rowStartIndex[j + 1] - m_rowStartIndex[
j];
107 return &m_data.
diag(0);
111 return &m_data.
diag(0);
115 return &m_data.
upper(0);
119 return &m_data.
upper(0);
123 return &m_data.
lower(0);
127 return &m_data.
lower(0);
154 return this->m_data.
diag(outer);
160 if (outer >= minOuterIndex)
161 return this->m_data.
upper(m_colStartIndex[inner] + outer - (inner - m_data.
upperProfile(inner)));
168 if (inner >= minInnerIndex)
169 return this->m_data.
lower(m_rowStartIndex[outer] + inner - (outer - m_data.
lowerProfile(outer)));
173 return m_data.
upper(m_colStartIndex[inner] + outer - inner);
178 if (outer <= maxOuterIndex)
179 return this->m_data.
upper(m_colStartIndex[inner] + (outer - inner));
187 if (inner <= maxInnerIndex)
188 return this->m_data.
lower(m_rowStartIndex[outer] + (inner - outer));
203 return this->m_data.
diag(outer);
209 eigen_assert(outer >= minOuterIndex &&
"You tried to access a coeff that does not exist in the storage");
210 return this->m_data.
upper(m_colStartIndex[inner] + outer - (inner - m_data.
upperProfile(inner)));
215 eigen_assert(inner >= minInnerIndex &&
"You tried to access a coeff that does not exist in the storage");
216 return this->m_data.
lower(m_rowStartIndex[outer] + inner - (outer - m_data.
lowerProfile(outer)));
222 eigen_assert(outer <= maxOuterIndex &&
"You tried to access a coeff that does not exist in the storage");
223 return this->m_data.
upper(m_colStartIndex[inner] + (outer - inner));
228 eigen_assert(inner <= maxInnerIndex &&
"You tried to access a coeff that does not exist in the storage");
229 return this->m_data.
lower(m_rowStartIndex[outer] + (inner - outer));
237 return this->m_data.
diag(idx);
250 if (inner >= minInnerIndex)
251 return this->m_data.
lower(m_rowStartIndex[outer] + inner - (outer - m_data.
lowerProfile(outer)));
257 if (inner <= maxInnerIndex)
258 return this->m_data.
lower(m_rowStartIndex[outer] + (inner - outer));
274 if (outer >= minOuterIndex)
275 return this->m_data.
upper(m_colStartIndex[inner] + outer - (inner - m_data.
upperProfile(inner)));
280 if (outer <= maxOuterIndex)
281 return this->m_data.
upper(m_colStartIndex[inner] + (outer - inner));
290 return this->m_data.
diag(idx);
303 eigen_assert(inner >= minInnerIndex &&
"You tried to access a coeff that does not exist in the storage");
304 return this->m_data.
lower(m_rowStartIndex[outer] + inner - (outer - m_data.
lowerProfile(outer)));
307 eigen_assert(inner <= maxInnerIndex &&
"You tried to access a coeff that does not exist in the storage");
308 return this->m_data.
lower(m_rowStartIndex[outer] + (inner - outer));
322 return inner >= minInnerIndex;
325 return inner <= maxInnerIndex;
339 eigen_assert(outer >= minOuterIndex &&
"You tried to access a coeff that does not exist in the storage");
340 return this->m_data.
upper(m_colStartIndex[inner] + outer - (inner - m_data.
upperProfile(inner)));
343 eigen_assert(outer <= maxOuterIndex &&
"You tried to access a coeff that does not exist in the storage");
344 return this->m_data.
upper(m_colStartIndex[inner] + (outer - inner));
358 return outer >= minOuterIndex;
361 return outer <= maxOuterIndex;
372 class OuterUpperIterator;
373 class OuterLowerIterator;
378 memset(m_colStartIndex, 0, (m_outerSize + 1) *
sizeof (
Index));
379 memset(m_rowStartIndex, 0, (m_outerSize + 1) *
sizeof (
Index));
389 m_data.
reserve(reserveSize, reserveUpperSize, reserveLowerSize);
408 return m_data.
diag(col);
413 Index minOuterIndex = 0;
416 if (outer < minOuterIndex)
425 const Index stop = m_colStartIndex[
cols()];
426 const Index start = m_colStartIndex[inner];
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--) {
434 m_colStartIndex[innerIdx] += bandIncrement;
438 memset(this->_upperPtr() + start, 0, (bandIncrement - 1) *
sizeof (
Scalar));
440 return m_data.
upper(m_colStartIndex[inner]);
442 return m_data.
upper(m_colStartIndex[inner] + outer - (inner - m_data.
upperProfile(inner)));
449 if (inner < minInnerIndex)
456 const Index stop = m_rowStartIndex[
rows()];
457 const Index start = m_rowStartIndex[outer];
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--) {
465 m_rowStartIndex[innerIdx] += bandIncrement;
469 memset(this->_lowerPtr() + start, 0, (bandIncrement - 1) *
sizeof (
Scalar));
470 return m_data.
lower(m_rowStartIndex[outer]);
472 return m_data.
lower(m_rowStartIndex[outer] + inner - (outer - m_data.
lowerProfile(outer)));
479 if (outer > maxOuterIndex)
486 const Index stop = m_rowStartIndex[
rows()];
487 const Index start = m_rowStartIndex[inner + 1];
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++) {
494 m_rowStartIndex[innerIdx] += bandIncrement;
496 memset(this->_upperPtr() + m_rowStartIndex[inner] + previousProfile + 1, 0, (bandIncrement - 1) *
sizeof (
Scalar));
499 return m_data.
upper(m_rowStartIndex[inner] + (outer - inner));
506 if (inner > maxInnerIndex)
513 const Index stop = m_colStartIndex[
cols()];
514 const Index start = m_colStartIndex[outer + 1];
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++) {
521 m_colStartIndex[innerIdx] += bandIncrement;
523 memset(this->_lowerPtr() + m_colStartIndex[outer] + previousProfile + 1, 0, (bandIncrement - 1) *
sizeof (
Scalar));
526 return m_data.
lower(m_colStartIndex[outer] + (inner - outer));
591 m_innerSize = IsRowMajor ?
cols :
rows;
593 eigen_assert(rows == cols &&
"Skyline matrix must be square matrix");
596 const Index k = (diagSize - 1) / 2;
598 m_data.
resize(diagSize, IsRowMajor ? cols : rows, IsRowMajor ? rows : cols,
604 const Index k = diagSize / 2;
605 m_data.
resize(diagSize, IsRowMajor ? cols : rows, IsRowMajor ? rows : cols,
610 if (m_colStartIndex && m_rowStartIndex) {
611 delete[] m_colStartIndex;
612 delete[] m_rowStartIndex;
614 m_colStartIndex =
new Index [cols + 1];
615 m_rowStartIndex =
new Index [rows + 1];
616 m_outerSize = diagSize;
621 m_outerSize = diagSize;
622 memset(m_colStartIndex, 0, (cols + 1) *
sizeof (
Index));
623 memset(m_rowStartIndex, 0, (rows + 1) *
sizeof (
Index));
631 : m_outerSize(-1), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) {
636 : m_outerSize(0), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) {
640 template<
typename OtherDerived>
642 : m_outerSize(0), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) {
647 :
Base(), m_outerSize(0), m_innerSize(0), m_colStartIndex(0), m_rowStartIndex(0) {
661 std::cout <<
"SkylineMatrix& operator=(const SkylineMatrix& other)\n";
673 template<
typename OtherDerived>
676 if (needToTranspose) {
688 std::cout <<
"upper elements : " << std::endl;
690 std::cout << m.
m_data.upper(
i) <<
"\t";
691 std::cout << std::endl;
692 std::cout <<
"upper profile : " << std::endl;
694 std::cout << m.
m_data.upperProfile(
i) <<
"\t";
695 std::cout << std::endl;
696 std::cout <<
"lower startIdx : " << std::endl;
699 std::cout << std::endl;
702 std::cout <<
"lower elements : " << std::endl;
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++)
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";
726 delete[] m_colStartIndex;
727 delete[] m_rowStartIndex;
734 template<
typename Scalar,
int _Options>
739 : m_matrix(mat), m_outer(outer),
740 m_id(_Options ==
RowMajor ? mat.m_colStartIndex[outer] : mat.m_rowStartIndex[outer] + 1),
742 m_end(_Options ==
RowMajor ? mat.m_colStartIndex[outer + 1] : mat.m_rowStartIndex[outer + 1] + 1) {
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;
773 return IsRowMajor ? index() : m_outer;
777 return IsRowMajor ? m_outer : index();
781 return m_matrix.m_data.upperProfile(m_outer);
784 inline operator bool()
const {
785 return (m_id < m_end) && (m_id >= m_start);
796 template<
typename Scalar,
int _Options>
803 m_id(_Options ==
RowMajor ? mat.m_rowStartIndex[outer] : mat.m_colStartIndex[outer] + 1),
805 m_end(_Options ==
RowMajor ? mat.m_rowStartIndex[outer + 1] : mat.m_colStartIndex[outer + 1] + 1) {
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;
837 return IsRowMajor ? m_outer : index();
841 return IsRowMajor ? index() : m_outer;
845 return m_matrix.m_data.lowerProfile(m_outer);
848 inline operator bool()
const {
849 return (m_id < m_end) && (m_id >= m_start);
862 #endif // EIGEN_SKYLINEMATRIX_H
Scalar coeffDiag(Index idx) const
InnerUpperIterator & operator++()
const Index * _lowerProfilePtr() const
SkylineMatrix(size_t rows, size_t cols)
Index upperNonZeros() const
Index lowerNonZeros(Index j) const
InnerUpperIterator & operator+=(Index shift)
Namespace containing all symbols from the Eigen library.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
internal::traits< SkylineMatrix< _Scalar, _Options > >::Scalar Scalar
void resize(size_t rows, size_t cols)
Scalar & coeffRefUpper(Index row, Index col)
Index * _lowerProfilePtr()
Eigen::Index Index
The interface type of indices.
const unsigned int RowMajorBit
InnerLowerIterator & operator++()
void prune(Scalar reference, RealScalar epsilon=dummy_precision< RealScalar >())
Derived & operator=(const Derived &other)
#define EIGEN_DONT_INLINE
bool coeffExistLower(Index row, Index col)
const Index * _upperProfilePtr() const
Index * _upperProfilePtr()
const Scalar * _lowerPtr() const
SkylineMatrix(const SkylineMatrix &other)
SkylineStorage< Scalar > m_data
void reserve(Index reserveSize, Index reserveUpperSize, Index reserveLowerSize)
EIGEN_DONT_INLINE Scalar & insert(Index row, Index col)
void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize)
SkylineMatrix< Scalar,(Flags &~RowMajorBit)|(IsRowMajor ? RowMajorBit :0) > TransposedSkylineMatrix
InnerLowerIterator & operator+=(Index shift)
SkylineMatrix & operator=(const SkylineMatrix &other)
const Scalar * _upperPtr() const
Scalar coeff(Index row, Index col) const
Index upperNonZeros(Index j) const
void swap(SkylineStorage &other)
Index lowerNonZeros() const
const SkylineMatrix & m_matrix
Scalar & coeffRefLower(Index row, Index col)
InnerLowerIterator(const SkylineMatrix &mat, Index outer)
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)
const Derived & derived() const
const SkylineMatrix & m_matrix
EIGEN_CONSTEXPR Index size(const T &x)
void resizeNonZeros(Index size)
const Scalar * _diagPtr() const
void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize, float reserveSizeFactor=0)
void swap(SkylineMatrix &other)
bool coeffExistUpper(Index row, Index col)
const unsigned int SkylineBit
Base class of any skyline matrices or skyline expressions.
#define EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived)
Scalar coeffLower(Index row, Index col) const
SkylineMatrix & operator=(const SkylineMatrixBase< OtherDerived > &other)
The main skyline matrix class.
Scalar coeffUpper(Index row, Index col) const
Scalar & coeffRef(Index row, Index col)
NumTraits< Scalar >::Real RealScalar
InnerUpperIterator(const SkylineMatrix &mat, Index outer)
Scalar & coeffRefDiag(Index idx)
std::ostream & operator<<(std::ostream &s, const Packet16c &v)
Derived & const_cast_derived() const
#define EIGEN_DBG_SKYLINE(X)
SkylineMatrix(const SkylineMatrixBase< OtherDerived > &other)
Index & upperProfile(Index i)
void swap(scoped_array< T > &a, scoped_array< T > &b)
#define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op)
Index & lowerProfile(Index i)