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);
147 const Index outer = IsRowMajor ? row :
col;
148 const Index inner = IsRowMajor ? col :
row;
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));
196 const Index outer = IsRowMajor ? row :
col;
197 const Index inner = IsRowMajor ? col :
row;
203 return this->m_data.
diag(outer);
209 eigen_assert(outer >= minOuterIndex &&
"you try to acces a coeff that do 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 try to acces a coeff that do 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 try to acces a coeff that do not exist in the storage");
223 return this->m_data.
upper(m_colStartIndex[inner] + (outer - inner));
228 eigen_assert(inner <= maxInnerIndex &&
"you try to acces a coeff that do not exist in the storage");
229 return this->m_data.
lower(m_rowStartIndex[outer] + (inner - outer));
237 return this->m_data.
diag(idx);
241 const Index outer = IsRowMajor ? row :
col;
242 const Index inner = IsRowMajor ? col :
row;
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));
265 const Index outer = IsRowMajor ? row :
col;
266 const Index inner = IsRowMajor ? col :
row;
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);
294 const Index outer = IsRowMajor ? row :
col;
295 const Index inner = IsRowMajor ? col :
row;
303 eigen_assert(inner >= minInnerIndex &&
"you try to acces a coeff that do 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 try to acces a coeff that do not exist in the storage");
308 return this->m_data.
lower(m_rowStartIndex[outer] + (inner - outer));
313 const Index outer = IsRowMajor ? row :
col;
314 const Index inner = IsRowMajor ? col :
row;
322 return inner >= minInnerIndex;
325 return inner <= maxInnerIndex;
330 const Index outer = IsRowMajor ? row :
col;
331 const Index inner = IsRowMajor ? col :
row;
339 eigen_assert(outer >= minOuterIndex &&
"you try to acces a coeff that do 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 try to acces a coeff that do not exist in the storage");
344 return this->m_data.
upper(m_colStartIndex[inner] + (outer - inner));
349 const Index outer = IsRowMajor ? row :
col;
350 const Index inner = IsRowMajor ? col :
row;
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);
401 const Index outer = IsRowMajor ? row :
col;
402 const Index inner = IsRowMajor ? col :
row;
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));
537 m_data.
resize(cols(), cols(), rows(), m_colStartIndex[cols()] + 1, m_rowStartIndex[rows()] + 1);
539 m_data.
resize(rows(), cols(), rows(), m_colStartIndex[cols()] + 1, m_rowStartIndex[rows()] + 1);
571 m_data.
resize(cols(), rows(), cols(), m_rowStartIndex[cols()] + 1, m_colStartIndex[cols()] + 1);
573 m_data.
resize(rows(), rows(), cols(), m_rowStartIndex[rows()] + 1, m_colStartIndex[rows()] + 1);
590 const Index diagSize = rows > cols ? cols : rows;
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;
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++)
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 coeff(Index row, Index col) const
InnerUpperIterator & operator++()
SkylineMatrix(size_t rows, size_t cols)
std::ostream & operator<<(std::ostream &s, const Packet16uc &v)
const Index * _lowerProfilePtr() const
InnerUpperIterator & operator+=(Index shift)
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
internal::traits< SkylineMatrix< _Scalar, _Options > >::Scalar Scalar
Scalar coeffLower(Index row, Index col) const
void resize(size_t rows, size_t cols)
Scalar & coeffRefUpper(Index row, Index col)
Index * _lowerProfilePtr()
const unsigned int RowMajorBit
Index lowerNonZeros() const
InnerLowerIterator & operator++()
const Derived & derived() const
Derived & const_cast_derived() const
void prune(Scalar reference, RealScalar epsilon=dummy_precision< RealScalar >())
Derived & operator=(const Derived &other)
#define EIGEN_DONT_INLINE
bool coeffExistLower(Index row, Index col)
Index * _upperProfilePtr()
SkylineMatrix(const SkylineMatrix &other)
SkylineStorage< Scalar > m_data
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
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)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Index lowerNonZeros(Index j) const
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). */.
void swap(SkylineStorage &other)
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
const Scalar * _lowerPtr() const
const SkylineMatrix & m_matrix
Scalar & coeffRefLower(Index row, Index col)
InnerLowerIterator(const SkylineMatrix &mat, Index outer)
const Scalar * _upperPtr() const
Index upperNonZeros(Index j) const
const SkylineMatrix & m_matrix
const Index * _upperProfilePtr() const
void resizeNonZeros(Index size)
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.
Index upperNonZeros() const
#define EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived)
SkylineMatrix & operator=(const SkylineMatrixBase< OtherDerived > &other)
const Scalar * _diagPtr() const
The main skyline matrix class.
Scalar & coeffRef(Index row, Index col)
NumTraits< Scalar >::Real RealScalar
InnerUpperIterator(const SkylineMatrix &mat, Index outer)
Scalar & coeffRefDiag(Index idx)
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
#define EIGEN_DBG_SKYLINE(X)
SkylineMatrix(const SkylineMatrixBase< OtherDerived > &other)
Index & upperProfile(Index i)
Scalar coeffUpper(Index row, Index col) const
Scalar coeffDiag(Index idx) const
void swap(scoped_array< T > &a, scoped_array< T > &b)
#define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op)
Index & lowerProfile(Index i)