diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-05-30 16:00:58 -0400 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-05-30 16:00:58 -0400 |
commit | aaaade4b3d66d67d2c08af3372c3965e7255b2e8 (patch) | |
tree | 76dfaefb014333b2f98c6db660454771655ea8b7 /unsupported/Eigen/src/Skyline | |
parent | faa3ff3be6a02b57c6cb05edc87375e54ab96606 (diff) |
the Index types change.
As discussed on the list (too long to explain here).
Diffstat (limited to 'unsupported/Eigen/src/Skyline')
-rw-r--r-- | unsupported/Eigen/src/Skyline/SkylineInplaceLU.h | 46 | ||||
-rw-r--r-- | unsupported/Eigen/src/Skyline/SkylineMatrix.h | 277 | ||||
-rw-r--r-- | unsupported/Eigen/src/Skyline/SkylineMatrixBase.h | 22 | ||||
-rw-r--r-- | unsupported/Eigen/src/Skyline/SkylineProduct.h | 44 | ||||
-rw-r--r-- | unsupported/Eigen/src/Skyline/SkylineStorage.h | 87 | ||||
-rw-r--r-- | unsupported/Eigen/src/Skyline/SkylineUtil.h | 22 |
6 files changed, 253 insertions, 245 deletions
diff --git a/unsupported/Eigen/src/Skyline/SkylineInplaceLU.h b/unsupported/Eigen/src/Skyline/SkylineInplaceLU.h index c8c5f7575..fa8f81908 100644 --- a/unsupported/Eigen/src/Skyline/SkylineInplaceLU.h +++ b/unsupported/Eigen/src/Skyline/SkylineInplaceLU.h @@ -38,6 +38,8 @@ template<typename MatrixType> class SkylineInplaceLU { protected: typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::Index Index; + typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; public: @@ -135,18 +137,18 @@ void SkylineInplaceLU<MatrixType>::compute() { ei_assert(rows == cols && "We do not (yet) support rectangular LU."); ei_assert(!m_lu.IsRowMajor && "LU decomposition does not work with rowMajor Storage"); - for (unsigned int row = 0; row < rows; row++) { + for (Index row = 0; row < rows; row++) { const double pivot = m_lu.coeffDiag(row); //Lower matrix Columns update - const unsigned int& col = row; + const Index& col = row; for (typename MatrixType::InnerLowerIterator lIt(m_lu, col); lIt; ++lIt) { lIt.valueRef() /= pivot; } //Upper matrix update -> contiguous memory access typename MatrixType::InnerLowerIterator lIt(m_lu, col); - for (unsigned int rrow = row + 1; rrow < m_lu.rows(); rrow++) { + for (Index rrow = row + 1; rrow < m_lu.rows(); rrow++) { typename MatrixType::InnerUpperIterator uItPivot(m_lu, row); typename MatrixType::InnerUpperIterator uIt(m_lu, rrow); const double coef = lIt.value(); @@ -165,12 +167,12 @@ void SkylineInplaceLU<MatrixType>::compute() { //Upper matrix update -> non contiguous memory access typename MatrixType::InnerLowerIterator lIt3(m_lu, col); - for (unsigned int rrow = row + 1; rrow < m_lu.rows(); rrow++) { + for (Index rrow = row + 1; rrow < m_lu.rows(); rrow++) { typename MatrixType::InnerUpperIterator uItPivot(m_lu, row); const double coef = lIt3.value(); //update lower part -> non contiguous memory access - for (unsigned int i = 0; i < rrow - row - 1; i++) { + for (Index i = 0; i < rrow - row - 1; i++) { m_lu.coeffRefLower(rrow, row + i + 1) -= uItPivot.value() * coef; ++uItPivot; } @@ -178,7 +180,7 @@ void SkylineInplaceLU<MatrixType>::compute() { } //update diag -> contiguous typename MatrixType::InnerLowerIterator lIt2(m_lu, col); - for (unsigned int rrow = row + 1; rrow < m_lu.rows(); rrow++) { + for (Index rrow = row + 1; rrow < m_lu.rows(); rrow++) { typename MatrixType::InnerUpperIterator uItPivot(m_lu, row); typename MatrixType::InnerUpperIterator uIt(m_lu, rrow); @@ -199,11 +201,11 @@ void SkylineInplaceLU<MatrixType>::computeRowMajor() { ei_assert(rows == cols && "We do not (yet) support rectangular LU."); ei_assert(m_lu.IsRowMajor && "You're trying to apply rowMajor decomposition on a ColMajor matrix !"); - for (unsigned int row = 0; row < rows; row++) { + for (Index row = 0; row < rows; row++) { typename MatrixType::InnerLowerIterator llIt(m_lu, row); - for (unsigned int col = llIt.col(); col < row; col++) { + for (Index col = llIt.col(); col < row; col++) { if (m_lu.coeffExistLower(row, col)) { const double diag = m_lu.coeffDiag(col); @@ -211,10 +213,10 @@ void SkylineInplaceLU<MatrixType>::computeRowMajor() { typename MatrixType::InnerUpperIterator uIt(m_lu, col); - const int offset = lIt.col() - uIt.row(); + const Index offset = lIt.col() - uIt.row(); - int stop = offset > 0 ? col - lIt.col() : col - uIt.row(); + Index stop = offset > 0 ? col - lIt.col() : col - uIt.row(); //#define VECTORIZE #ifdef VECTORIZE @@ -230,7 +232,7 @@ void SkylineInplaceLU<MatrixType>::computeRowMajor() { lIt += -offset; Scalar newCoeff = m_lu.coeffLower(row, col); - for (int k = 0; k < stop; ++k) { + for (Index k = 0; k < stop; ++k) { const Scalar tmp = newCoeff; newCoeff = tmp - lIt.value() * uIt.value(); ++lIt; @@ -243,15 +245,15 @@ void SkylineInplaceLU<MatrixType>::computeRowMajor() { } //Upper matrix update - const int col = row; + const Index col = row; typename MatrixType::InnerUpperIterator uuIt(m_lu, col); - for (unsigned int rrow = uuIt.row(); rrow < col; rrow++) { + for (Index rrow = uuIt.row(); rrow < col; rrow++) { typename MatrixType::InnerLowerIterator lIt(m_lu, rrow); typename MatrixType::InnerUpperIterator uIt(m_lu, col); - const int offset = lIt.col() - uIt.row(); + const Index offset = lIt.col() - uIt.row(); - int stop = offset > 0 ? rrow - lIt.col() : rrow - uIt.row(); + Index stop = offset > 0 ? rrow - lIt.col() : rrow - uIt.row(); #ifdef VECTORIZE Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop); @@ -264,7 +266,7 @@ void SkylineInplaceLU<MatrixType>::computeRowMajor() { else //Skip zero values of uIt lIt += -offset; Scalar newCoeff = m_lu.coeffUpper(rrow, col); - for (int k = 0; k < stop; ++k) { + for (Index k = 0; k < stop; ++k) { const Scalar tmp = newCoeff; newCoeff = tmp - lIt.value() * uIt.value(); @@ -280,10 +282,10 @@ void SkylineInplaceLU<MatrixType>::computeRowMajor() { typename MatrixType::InnerLowerIterator lIt(m_lu, row); typename MatrixType::InnerUpperIterator uIt(m_lu, row); - const int offset = lIt.col() - uIt.row(); + const Index offset = lIt.col() - uIt.row(); - int stop = offset > 0 ? lIt.size() : uIt.size(); + Index stop = offset > 0 ? lIt.size() : uIt.size(); #ifdef VECTORIZE Map<VectorXd > rowVal(lIt.valuePtr() + (offset > 0 ? 0 : -offset), stop); Map<VectorXd > colVal(uIt.valuePtr() + (offset > 0 ? offset : 0), stop); @@ -294,7 +296,7 @@ void SkylineInplaceLU<MatrixType>::computeRowMajor() { else //Skip zero values of uIt lIt += -offset; Scalar newCoeff = m_lu.coeffDiag(row); - for (unsigned int k = 0; k < stop; ++k) { + for (Index k = 0; k < stop; ++k) { const Scalar tmp = newCoeff; newCoeff = tmp - lIt.value() * uIt.value(); ++lIt; @@ -320,12 +322,12 @@ bool SkylineInplaceLU<MatrixType>::solve(const MatrixBase<BDerived> &b, MatrixBa const size_t cols = m_lu.cols(); - for (int row = 0; row < rows; row++) { + for (Index row = 0; row < rows; row++) { x->coeffRef(row) = b.coeff(row); Scalar newVal = x->coeff(row); typename MatrixType::InnerLowerIterator lIt(m_lu, row); - unsigned int col = lIt.col(); + Index col = lIt.col(); while (lIt.col() < row) { newVal -= x->coeff(col++) * lIt.value(); @@ -336,7 +338,7 @@ bool SkylineInplaceLU<MatrixType>::solve(const MatrixBase<BDerived> &b, MatrixBa } - for (int col = rows - 1; col > 0; col--) { + for (Index col = rows - 1; col > 0; col--) { x->coeffRef(col) = x->coeff(col) / m_lu.coeffDiag(col); const Scalar x_col = x->coeff(col); diff --git a/unsupported/Eigen/src/Skyline/SkylineMatrix.h b/unsupported/Eigen/src/Skyline/SkylineMatrix.h index 6dd4f1736..20fafafa8 100644 --- a/unsupported/Eigen/src/Skyline/SkylineMatrix.h +++ b/unsupported/Eigen/src/Skyline/SkylineMatrix.h @@ -46,6 +46,7 @@ template<typename _Scalar, int _Options> struct ei_traits<SkylineMatrix<_Scalar, _Options> > { typedef _Scalar Scalar; + typedef Sparse StorageKind; enum { RowsAtCompileTime = Dynamic, @@ -71,45 +72,45 @@ protected: typedef SkylineMatrix<Scalar, (Flags&~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0) > TransposedSkylineMatrix; - int m_outerSize; - int m_innerSize; + Index m_outerSize; + Index m_innerSize; public: - int* m_colStartIndex; - int* m_rowStartIndex; + Index* m_colStartIndex; + Index* m_rowStartIndex; SkylineStorage<Scalar> m_data; public: - inline int rows() const { + inline Index rows() const { return IsRowMajor ? m_outerSize : m_innerSize; } - inline int cols() const { + inline Index cols() const { return IsRowMajor ? m_innerSize : m_outerSize; } - inline int innerSize() const { + inline Index innerSize() const { return m_innerSize; } - inline int outerSize() const { + inline Index outerSize() const { return m_outerSize; } - inline int upperNonZeros() const { + inline Index upperNonZeros() const { return m_data.upperSize(); } - inline int lowerNonZeros() const { + inline Index lowerNonZeros() const { return m_data.lowerSize(); } - inline int upperNonZeros(int j) const { + inline Index upperNonZeros(Index j) const { return m_colStartIndex[j + 1] - m_colStartIndex[j]; } - inline int lowerNonZeros(int j) const { + inline Index lowerNonZeros(Index j) const { return m_rowStartIndex[j + 1] - m_rowStartIndex[j]; } @@ -137,25 +138,25 @@ public: return &m_data.lower(0); } - inline const int* _upperProfilePtr() const { + inline const Index* _upperProfilePtr() const { return &m_data.upperProfile(0); } - inline int* _upperProfilePtr() { + inline Index* _upperProfilePtr() { return &m_data.upperProfile(0); } - inline const int* _lowerProfilePtr() const { + inline const Index* _lowerProfilePtr() const { return &m_data.lowerProfile(0); } - inline int* _lowerProfilePtr() { + inline Index* _lowerProfilePtr() { return &m_data.lowerProfile(0); } - inline Scalar coeff(int row, int col) const { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + inline Scalar coeff(Index row, Index col) const { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); @@ -166,7 +167,7 @@ public: if (IsRowMajor) { if (inner > outer) //upper matrix { - const int minOuterIndex = inner - m_data.upperProfile(inner); + const Index minOuterIndex = inner - m_data.upperProfile(inner); if (outer >= minOuterIndex) return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); else @@ -174,7 +175,7 @@ public: } if (inner < outer) //lower matrix { - const int minInnerIndex = outer - m_data.lowerProfile(outer); + const Index minInnerIndex = outer - m_data.lowerProfile(outer); if (inner >= minInnerIndex) return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); else @@ -184,7 +185,7 @@ public: } else { if (outer > inner) //upper matrix { - const int maxOuterIndex = inner + m_data.upperProfile(inner); + const Index maxOuterIndex = inner + m_data.upperProfile(inner); if (outer <= maxOuterIndex) return this->m_data.upper(m_colStartIndex[inner] + (outer - inner)); else @@ -192,7 +193,7 @@ public: } if (outer < inner) //lower matrix { - const int maxInnerIndex = outer + m_data.lowerProfile(outer); + const Index maxInnerIndex = outer + m_data.lowerProfile(outer); if (inner <= maxInnerIndex) return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer)); @@ -202,9 +203,9 @@ public: } } - inline Scalar& coeffRef(int row, int col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + inline Scalar& coeffRef(Index row, Index col) { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); @@ -215,55 +216,55 @@ public: if (IsRowMajor) { if (col > row) //upper matrix { - const int minOuterIndex = inner - m_data.upperProfile(inner); + const Index minOuterIndex = inner - m_data.upperProfile(inner); ei_assert(outer >= minOuterIndex && "you try to acces a coeff that do not exist in the storage"); return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); } if (col < row) //lower matrix { - const int minInnerIndex = outer - m_data.lowerProfile(outer); + const Index minInnerIndex = outer - m_data.lowerProfile(outer); ei_assert(inner >= minInnerIndex && "you try to acces a coeff that do not exist in the storage"); return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); } } else { if (outer > inner) //upper matrix { - const int maxOuterIndex = inner + m_data.upperProfile(inner); + const Index maxOuterIndex = inner + m_data.upperProfile(inner); ei_assert(outer <= maxOuterIndex && "you try to acces a coeff that do not exist in the storage"); return this->m_data.upper(m_colStartIndex[inner] + (outer - inner)); } if (outer < inner) //lower matrix { - const int maxInnerIndex = outer + m_data.lowerProfile(outer); + const Index maxInnerIndex = outer + m_data.lowerProfile(outer); ei_assert(inner <= maxInnerIndex && "you try to acces a coeff that do not exist in the storage"); return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer)); } } } - inline Scalar coeffDiag(int idx) const { + inline Scalar coeffDiag(Index idx) const { ei_assert(idx < outerSize()); ei_assert(idx < innerSize()); return this->m_data.diag(idx); } - inline Scalar coeffLower(int row, int col) const { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + inline Scalar coeffLower(Index row, Index col) const { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); ei_assert(inner != outer); if (IsRowMajor) { - const int minInnerIndex = outer - m_data.lowerProfile(outer); + const Index minInnerIndex = outer - m_data.lowerProfile(outer); if (inner >= minInnerIndex) return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); else return Scalar(0); } else { - const int maxInnerIndex = outer + m_data.lowerProfile(outer); + const Index maxInnerIndex = outer + m_data.lowerProfile(outer); if (inner <= maxInnerIndex) return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer)); else @@ -271,22 +272,22 @@ public: } } - inline Scalar coeffUpper(int row, int col) const { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + inline Scalar coeffUpper(Index row, Index col) const { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); ei_assert(inner != outer); if (IsRowMajor) { - const int minOuterIndex = inner - m_data.upperProfile(inner); + const Index minOuterIndex = inner - m_data.upperProfile(inner); if (outer >= minOuterIndex) return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); else return Scalar(0); } else { - const int maxOuterIndex = inner + m_data.upperProfile(inner); + const Index maxOuterIndex = inner + m_data.upperProfile(inner); if (outer <= maxOuterIndex) return this->m_data.upper(m_colStartIndex[inner] + (outer - inner)); else @@ -294,80 +295,80 @@ public: } } - inline Scalar& coeffRefDiag(int idx) { + inline Scalar& coeffRefDiag(Index idx) { ei_assert(idx < outerSize()); ei_assert(idx < innerSize()); return this->m_data.diag(idx); } - inline Scalar& coeffRefLower(int row, int col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + inline Scalar& coeffRefLower(Index row, Index col) { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); ei_assert(inner != outer); if (IsRowMajor) { - const int minInnerIndex = outer - m_data.lowerProfile(outer); + const Index minInnerIndex = outer - m_data.lowerProfile(outer); ei_assert(inner >= minInnerIndex && "you try to acces a coeff that do not exist in the storage"); return this->m_data.lower(m_rowStartIndex[outer] + inner - (outer - m_data.lowerProfile(outer))); } else { - const int maxInnerIndex = outer + m_data.lowerProfile(outer); + const Index maxInnerIndex = outer + m_data.lowerProfile(outer); ei_assert(inner <= maxInnerIndex && "you try to acces a coeff that do not exist in the storage"); return this->m_data.lower(m_rowStartIndex[outer] + (inner - outer)); } } - inline bool coeffExistLower(int row, int col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + inline bool coeffExistLower(Index row, Index col) { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); ei_assert(inner != outer); if (IsRowMajor) { - const int minInnerIndex = outer - m_data.lowerProfile(outer); + const Index minInnerIndex = outer - m_data.lowerProfile(outer); return inner >= minInnerIndex; } else { - const int maxInnerIndex = outer + m_data.lowerProfile(outer); + const Index maxInnerIndex = outer + m_data.lowerProfile(outer); return inner <= maxInnerIndex; } } - inline Scalar& coeffRefUpper(int row, int col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + inline Scalar& coeffRefUpper(Index row, Index col) { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); ei_assert(inner != outer); if (IsRowMajor) { - const int minOuterIndex = inner - m_data.upperProfile(inner); + const Index minOuterIndex = inner - m_data.upperProfile(inner); ei_assert(outer >= minOuterIndex && "you try to acces a coeff that do not exist in the storage"); return this->m_data.upper(m_colStartIndex[inner] + outer - (inner - m_data.upperProfile(inner))); } else { - const int maxOuterIndex = inner + m_data.upperProfile(inner); + const Index maxOuterIndex = inner + m_data.upperProfile(inner); ei_assert(outer <= maxOuterIndex && "you try to acces a coeff that do not exist in the storage"); return this->m_data.upper(m_colStartIndex[inner] + (outer - inner)); } } - inline bool coeffExistUpper(int row, int col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + inline bool coeffExistUpper(Index row, Index col) { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); ei_assert(inner != outer); if (IsRowMajor) { - const int minOuterIndex = inner - m_data.upperProfile(inner); + const Index minOuterIndex = inner - m_data.upperProfile(inner); return outer >= minOuterIndex; } else { - const int maxOuterIndex = inner + m_data.upperProfile(inner); + const Index maxOuterIndex = inner + m_data.upperProfile(inner); return outer <= maxOuterIndex; } } @@ -385,17 +386,17 @@ public: /** Removes all non zeros */ inline void setZero() { m_data.clear(); - memset(m_colStartIndex, 0, (m_outerSize + 1) * sizeof (int)); - memset(m_rowStartIndex, 0, (m_outerSize + 1) * sizeof (int)); + memset(m_colStartIndex, 0, (m_outerSize + 1) * sizeof (Index)); + memset(m_rowStartIndex, 0, (m_outerSize + 1) * sizeof (Index)); } /** \returns the number of non zero coefficients */ - inline int nonZeros() const { + inline Index nonZeros() const { return m_data.diagSize() + m_data.upperSize() + m_data.lowerSize(); } /** Preallocates \a reserveSize non zeros */ - inline void reserve(int reserveSize, int reserveUpperSize, int reserveLowerSize) { + inline void reserve(Index reserveSize, Index reserveUpperSize, Index reserveLowerSize) { m_data.reserve(reserveSize, reserveUpperSize, reserveLowerSize); } @@ -407,9 +408,9 @@ public: * * After an insertion session, you should call the finalize() function. */ - EIGEN_DONT_INLINE Scalar & insert(int row, int col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + EIGEN_DONT_INLINE Scalar & insert(Index row, Index col) { + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; ei_assert(outer < outerSize()); ei_assert(inner < innerSize()); @@ -420,27 +421,27 @@ public: if (IsRowMajor) { if (outer < inner) //upper matrix { - int minOuterIndex = 0; + Index minOuterIndex = 0; minOuterIndex = inner - m_data.upperProfile(inner); if (outer < minOuterIndex) //The value does not yet exist { - const int previousProfile = m_data.upperProfile(inner); + const Index previousProfile = m_data.upperProfile(inner); m_data.upperProfile(inner) = inner - outer; - const int bandIncrement = m_data.upperProfile(inner) - previousProfile; + const Index bandIncrement = m_data.upperProfile(inner) - previousProfile; //shift data stored after this new one - const int stop = m_colStartIndex[cols()]; - const int start = m_colStartIndex[inner]; + const Index stop = m_colStartIndex[cols()]; + const Index start = m_colStartIndex[inner]; - for (int innerIdx = stop; innerIdx >= start; innerIdx--) { + for (Index innerIdx = stop; innerIdx >= start; innerIdx--) { m_data.upper(innerIdx + bandIncrement) = m_data.upper(innerIdx); } - for (int innerIdx = cols(); innerIdx > inner; innerIdx--) { + for (Index innerIdx = cols(); innerIdx > inner; innerIdx--) { m_colStartIndex[innerIdx] += bandIncrement; } @@ -455,23 +456,23 @@ public: if (outer > inner) //lower matrix { - const int minInnerIndex = outer - m_data.lowerProfile(outer); + const Index minInnerIndex = outer - m_data.lowerProfile(outer); if (inner < minInnerIndex) //The value does not yet exist { - const int previousProfile = m_data.lowerProfile(outer); + const Index previousProfile = m_data.lowerProfile(outer); m_data.lowerProfile(outer) = outer - inner; - const int bandIncrement = m_data.lowerProfile(outer) - previousProfile; + const Index bandIncrement = m_data.lowerProfile(outer) - previousProfile; //shift data stored after this new one - const int stop = m_rowStartIndex[rows()]; - const int start = m_rowStartIndex[outer]; + const Index stop = m_rowStartIndex[rows()]; + const Index start = m_rowStartIndex[outer]; - for (int innerIdx = stop; innerIdx >= start; innerIdx--) { + for (Index innerIdx = stop; innerIdx >= start; innerIdx--) { m_data.lower(innerIdx + bandIncrement) = m_data.lower(innerIdx); } - for (int innerIdx = rows(); innerIdx > outer; innerIdx--) { + for (Index innerIdx = rows(); innerIdx > outer; innerIdx--) { m_rowStartIndex[innerIdx] += bandIncrement; } @@ -485,22 +486,22 @@ public: } else { if (outer > inner) //upper matrix { - const int maxOuterIndex = inner + m_data.upperProfile(inner); + const Index maxOuterIndex = inner + m_data.upperProfile(inner); if (outer > maxOuterIndex) //The value does not yet exist { - const int previousProfile = m_data.upperProfile(inner); + const Index previousProfile = m_data.upperProfile(inner); m_data.upperProfile(inner) = outer - inner; - const int bandIncrement = m_data.upperProfile(inner) - previousProfile; + const Index bandIncrement = m_data.upperProfile(inner) - previousProfile; //shift data stored after this new one - const int stop = m_rowStartIndex[rows()]; - const int start = m_rowStartIndex[inner + 1]; + const Index stop = m_rowStartIndex[rows()]; + const Index start = m_rowStartIndex[inner + 1]; - for (int innerIdx = stop; innerIdx >= start; innerIdx--) { + for (Index innerIdx = stop; innerIdx >= start; innerIdx--) { m_data.upper(innerIdx + bandIncrement) = m_data.upper(innerIdx); } - for (int innerIdx = inner + 1; innerIdx < outerSize() + 1; innerIdx++) { + for (Index innerIdx = inner + 1; innerIdx < outerSize() + 1; innerIdx++) { m_rowStartIndex[innerIdx] += bandIncrement; } memset(this->_upperPtr() + m_rowStartIndex[inner] + previousProfile + 1, 0, (bandIncrement - 1) * sizeof (Scalar)); @@ -512,22 +513,22 @@ public: if (outer < inner) //lower matrix { - const int maxInnerIndex = outer + m_data.lowerProfile(outer); + const Index maxInnerIndex = outer + m_data.lowerProfile(outer); if (inner > maxInnerIndex) //The value does not yet exist { - const int previousProfile = m_data.lowerProfile(outer); + const Index previousProfile = m_data.lowerProfile(outer); m_data.lowerProfile(outer) = inner - outer; - const int bandIncrement = m_data.lowerProfile(outer) - previousProfile; + const Index bandIncrement = m_data.lowerProfile(outer) - previousProfile; //shift data stored after this new one - const int stop = m_colStartIndex[cols()]; - const int start = m_colStartIndex[outer + 1]; + const Index stop = m_colStartIndex[cols()]; + const Index start = m_colStartIndex[outer + 1]; - for (int innerIdx = stop; innerIdx >= start; innerIdx--) { + for (Index innerIdx = stop; innerIdx >= start; innerIdx--) { m_data.lower(innerIdx + bandIncrement) = m_data.lower(innerIdx); } - for (int innerIdx = outer + 1; innerIdx < outerSize() + 1; innerIdx++) { + for (Index innerIdx = outer + 1; innerIdx < outerSize() + 1; innerIdx++) { m_colStartIndex[innerIdx] += bandIncrement; } memset(this->_lowerPtr() + m_colStartIndex[outer] + previousProfile + 1, 0, (bandIncrement - 1) * sizeof (Scalar)); @@ -551,16 +552,16 @@ public: // ei_assert(rows() == cols() && "memory reorganisatrion only works with suare matrix"); // // Scalar* newArray = new Scalar[m_colStartIndex[cols()] + 1 + m_rowStartIndex[rows()] + 1]; - // unsigned int dataIdx = 0; - // for (unsigned int row = 0; row < rows(); row++) { + // Index dataIdx = 0; + // for (Index row = 0; row < rows(); row++) { // - // const unsigned int nbLowerElts = m_rowStartIndex[row + 1] - m_rowStartIndex[row]; + // const Index nbLowerElts = m_rowStartIndex[row + 1] - m_rowStartIndex[row]; // // std::cout << "nbLowerElts" << nbLowerElts << std::endl; // memcpy(newArray + dataIdx, m_data.m_lower + m_rowStartIndex[row], nbLowerElts * sizeof (Scalar)); // m_rowStartIndex[row] = dataIdx; // dataIdx += nbLowerElts; // - // const unsigned int nbUpperElts = m_colStartIndex[row + 1] - m_colStartIndex[row]; + // const Index nbUpperElts = m_colStartIndex[row + 1] - m_colStartIndex[row]; // memcpy(newArray + dataIdx, m_data.m_upper + m_colStartIndex[row], nbUpperElts * sizeof (Scalar)); // m_colStartIndex[row] = dataIdx; // dataIdx += nbUpperElts; @@ -594,16 +595,16 @@ public: } /** Resizes the matrix to a \a rows x \a cols matrix and initializes it to zero - * \sa resizeNonZeros(int), reserve(), setZero() + * \sa resizeNonZeros(Index), reserve(), setZero() */ void resize(size_t rows, size_t cols) { - const int diagSize = rows > cols ? cols : rows; + const Index diagSize = rows > cols ? cols : rows; m_innerSize = IsRowMajor ? cols : rows; ei_assert(rows == cols && "Skyline matrix must be square matrix"); if (diagSize % 2) { // diagSize is odd - const int k = (diagSize - 1) / 2; + const Index k = (diagSize - 1) / 2; m_data.resize(diagSize, IsRowMajor ? cols : rows, IsRowMajor ? rows : cols, 2 * k * k + k + 1, @@ -611,7 +612,7 @@ public: } else // diagSize is even { - const int k = diagSize / 2; + const Index k = diagSize / 2; m_data.resize(diagSize, IsRowMajor ? cols : rows, IsRowMajor ? rows : cols, 2 * k * k - k + 1, 2 * k * k - k + 1); @@ -621,19 +622,19 @@ public: delete[] m_colStartIndex; delete[] m_rowStartIndex; } - m_colStartIndex = new int [cols + 1]; - m_rowStartIndex = new int [rows + 1]; + m_colStartIndex = new Index [cols + 1]; + m_rowStartIndex = new Index [rows + 1]; m_outerSize = diagSize; m_data.reset(); m_data.clear(); m_outerSize = diagSize; - memset(m_colStartIndex, 0, (cols + 1) * sizeof (int)); - memset(m_rowStartIndex, 0, (rows + 1) * sizeof (int)); + memset(m_colStartIndex, 0, (cols + 1) * sizeof (Index)); + memset(m_rowStartIndex, 0, (rows + 1) * sizeof (Index)); } - void resizeNonZeros(int size) { + void resizeNonZeros(Index size) { m_data.resize(size); } @@ -673,8 +674,8 @@ public: swap(other.const_cast_derived()); } else { resize(other.rows(), other.cols()); - memcpy(m_colStartIndex, other.m_colStartIndex, (m_outerSize + 1) * sizeof (int)); - memcpy(m_rowStartIndex, other.m_rowStartIndex, (m_outerSize + 1) * sizeof (int)); + memcpy(m_colStartIndex, other.m_colStartIndex, (m_outerSize + 1) * sizeof (Index)); + memcpy(m_rowStartIndex, other.m_rowStartIndex, (m_outerSize + 1) * sizeof (Index)); m_data = other.m_data; } return *this; @@ -696,34 +697,34 @@ public: EIGEN_DBG_SKYLINE( std::cout << "upper elements : " << std::endl; - for (unsigned int i = 0; i < m.m_data.upperSize(); i++) + for (Index i = 0; i < m.m_data.upperSize(); i++) std::cout << m.m_data.upper(i) << "\t"; std::cout << std::endl; std::cout << "upper profile : " << std::endl; - for (unsigned int i = 0; i < m.m_data.upperProfileSize(); i++) + for (Index i = 0; i < m.m_data.upperProfileSize(); i++) std::cout << m.m_data.upperProfile(i) << "\t"; std::cout << std::endl; std::cout << "lower startIdx : " << std::endl; - for (unsigned int i = 0; i < m.m_data.upperProfileSize(); i++) + for (Index i = 0; i < m.m_data.upperProfileSize(); i++) std::cout << (IsRowMajor ? m.m_colStartIndex[i] : m.m_rowStartIndex[i]) << "\t"; std::cout << std::endl; std::cout << "lower elements : " << std::endl; - for (unsigned int i = 0; i < m.m_data.lowerSize(); i++) + for (Index i = 0; i < m.m_data.lowerSize(); i++) std::cout << m.m_data.lower(i) << "\t"; std::cout << std::endl; std::cout << "lower profile : " << std::endl; - for (unsigned int i = 0; i < m.m_data.lowerProfileSize(); i++) + for (Index i = 0; i < m.m_data.lowerProfileSize(); i++) std::cout << m.m_data.lowerProfile(i) << "\t"; std::cout << std::endl; std::cout << "lower startIdx : " << std::endl; - for (unsigned int i = 0; i < m.m_data.lowerProfileSize(); i++) + for (Index i = 0; i < m.m_data.lowerProfileSize(); i++) std::cout << (IsRowMajor ? m.m_rowStartIndex[i] : m.m_colStartIndex[i]) << "\t"; std::cout << std::endl; ); - for (unsigned int rowIdx = 0; rowIdx < m.rows(); rowIdx++) { - for (unsigned int colIdx = 0; colIdx < m.cols(); colIdx++) { + for (Index rowIdx = 0; rowIdx < m.rows(); rowIdx++) { + for (Index colIdx = 0; colIdx < m.cols(); colIdx++) { s << m.coeff(rowIdx, colIdx) << "\t"; } s << std::endl; @@ -745,7 +746,7 @@ template<typename Scalar, int _Options> class SkylineMatrix<Scalar, _Options>::InnerUpperIterator { public: - InnerUpperIterator(const SkylineMatrix& mat, int outer) + InnerUpperIterator(const SkylineMatrix& mat, Index outer) : m_matrix(mat), m_outer(outer), m_id(_Options == RowMajor ? mat.m_colStartIndex[outer] : mat.m_rowStartIndex[outer] + 1), m_start(m_id), @@ -757,7 +758,7 @@ public: return *this; } - inline InnerUpperIterator & operator+=(unsigned int shift) { + inline InnerUpperIterator & operator+=(Index shift) { m_id += shift; return *this; } @@ -774,16 +775,16 @@ public: return const_cast<Scalar&> (m_matrix.m_data.upper(m_id)); } - inline int index() const { + inline Index index() const { return IsRowMajor ? m_outer - m_matrix.m_data.upperProfile(m_outer) + (m_id - m_start) : m_outer + (m_id - m_start) + 1; } - inline int row() const { + inline Index row() const { return IsRowMajor ? index() : m_outer; } - inline int col() const { + inline Index col() const { return IsRowMajor ? m_outer : index(); } @@ -797,17 +798,17 @@ public: protected: const SkylineMatrix& m_matrix; - const int m_outer; - int m_id; - const int m_start; - const int m_end; + const Index m_outer; + Index m_id; + const Index m_start; + const Index m_end; }; template<typename Scalar, int _Options> class SkylineMatrix<Scalar, _Options>::InnerLowerIterator { public: - InnerLowerIterator(const SkylineMatrix& mat, int outer) + InnerLowerIterator(const SkylineMatrix& mat, Index outer) : m_matrix(mat), m_outer(outer), m_id(_Options == RowMajor ? mat.m_rowStartIndex[outer] : mat.m_colStartIndex[outer] + 1), @@ -820,7 +821,7 @@ public: return *this; } - inline InnerLowerIterator & operator+=(unsigned int shift) { + inline InnerLowerIterator & operator+=(Index shift) { m_id += shift; return *this; } @@ -837,17 +838,17 @@ public: return const_cast<Scalar&> (m_matrix.m_data.lower(m_id)); } - inline int index() const { + inline Index index() const { return IsRowMajor ? m_outer - m_matrix.m_data.lowerProfile(m_outer) + (m_id - m_start) : m_outer + (m_id - m_start) + 1; ; } - inline int row() const { + inline Index row() const { return IsRowMajor ? m_outer : index(); } - inline int col() const { + inline Index col() const { return IsRowMajor ? index() : m_outer; } @@ -861,10 +862,10 @@ public: protected: const SkylineMatrix& m_matrix; - const int m_outer; - int m_id; - const int m_start; - const int m_end; + const Index m_outer; + Index m_id; + const Index m_start; + const Index m_end; }; #endif // EIGEN_SkylineMatrix_H diff --git a/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h b/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h index ff20b830c..17349c187 100644 --- a/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h +++ b/unsupported/Eigen/src/Skyline/SkylineMatrixBase.h @@ -40,6 +40,8 @@ template<typename Derived> class SkylineMatrixBase : public EigenBase<Derived> { public: typedef typename ei_traits<Derived>::Scalar Scalar; + typedef typename ei_traits<Derived>::StorageKind StorageKind; + typedef typename ei_index<StorageKind>::type Index; enum { RowsAtCompileTime = ei_traits<Derived>::RowsAtCompileTime, @@ -113,36 +115,36 @@ public: #endif // not EIGEN_PARSED_BY_DOXYGEN /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ - inline int rows() const { + inline Index rows() const { return derived().rows(); } /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ - inline int cols() const { + inline Index cols() const { return derived().cols(); } /** \returns the number of coefficients, which is \a rows()*cols(). * \sa rows(), cols(), SizeAtCompileTime. */ - inline int size() const { + inline Index size() const { return rows() * cols(); } /** \returns the number of nonzero coefficients which is in practice the number * of stored coefficients. */ - inline int nonZeros() const { + inline Index nonZeros() const { return derived().nonZeros(); } /** \returns the size of the storage major dimension, * i.e., the number of columns for a columns major matrix, and the number of rows otherwise */ - int outerSize() const { + Index outerSize() const { return (int(Flags) & RowMajorBit) ? this->rows() : this->cols(); } /** \returns the size of the inner dimension according to the storage order, * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */ - int innerSize() const { + Index innerSize() const { return (int(Flags) & RowMajorBit) ? this->cols() : this->rows(); } @@ -167,8 +169,8 @@ public: template<typename OtherDerived> inline void assignGeneric(const OtherDerived& other) { derived().resize(other.rows(), other.cols()); - for (unsigned int row = 0; row < rows(); row++) - for (unsigned int col = 0; col < cols(); col++) { + for (Index row = 0; row < rows(); row++) + for (Index col = 0; col < cols(); col++) { if (other.coeff(row, col) != Scalar(0)) derived().insert(row, col) = other.coeff(row, col); } @@ -196,8 +198,8 @@ public: template<typename DenseDerived> void evalTo(MatrixBase<DenseDerived>& dst) const { dst.setZero(); - for (unsigned int i = 0; i < rows(); i++) - for (unsigned int j = 0; j < rows(); j++) + for (Index i = 0; i < rows(); i++) + for (Index j = 0; j < rows(); j++) dst(i, j) = derived().coeff(i, j); } diff --git a/unsupported/Eigen/src/Skyline/SkylineProduct.h b/unsupported/Eigen/src/Skyline/SkylineProduct.h index 9586576b5..e6484ad13 100644 --- a/unsupported/Eigen/src/Skyline/SkylineProduct.h +++ b/unsupported/Eigen/src/Skyline/SkylineProduct.h @@ -106,11 +106,11 @@ public: EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) } - EIGEN_STRONG_INLINE int rows() const { + EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); } - EIGEN_STRONG_INLINE int cols() const { + EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); } @@ -147,18 +147,18 @@ EIGEN_DONT_INLINE void ei_skyline_row_major_time_dense_product(const Lhs& lhs, c }; //Use matrix diagonal part <- Improvement : use inner iterator on dense matrix. - for (unsigned int col = 0; col < rhs.cols(); col++) { - for (unsigned int row = 0; row < lhs.rows(); row++) { + for (Index col = 0; col < rhs.cols(); col++) { + for (Index row = 0; row < lhs.rows(); row++) { dst(row, col) = lhs.coeffDiag(row) * rhs(row, col); } } //Use matrix lower triangular part - for (unsigned int row = 0; row < lhs.rows(); row++) { + for (Index row = 0; row < lhs.rows(); row++) { typename _Lhs::InnerLowerIterator lIt(lhs, row); - const int stop = lIt.col() + lIt.size(); - for (unsigned int col = 0; col < rhs.cols(); col++) { + const Index stop = lIt.col() + lIt.size(); + for (Index col = 0; col < rhs.cols(); col++) { - unsigned int k = lIt.col(); + Index k = lIt.col(); Scalar tmp = 0; while (k < stop) { tmp += @@ -173,14 +173,14 @@ EIGEN_DONT_INLINE void ei_skyline_row_major_time_dense_product(const Lhs& lhs, c } //Use matrix upper triangular part - for (unsigned int lhscol = 0; lhscol < lhs.cols(); lhscol++) { + for (Index lhscol = 0; lhscol < lhs.cols(); lhscol++) { typename _Lhs::InnerUpperIterator uIt(lhs, lhscol); - const int stop = uIt.size() + uIt.row(); - for (unsigned int rhscol = 0; rhscol < rhs.cols(); rhscol++) { + const Index stop = uIt.size() + uIt.row(); + for (Index rhscol = 0; rhscol < rhs.cols(); rhscol++) { const Scalar rhsCoeff = rhs.coeff(lhscol, rhscol); - unsigned int k = uIt.row(); + Index k = uIt.row(); while (k < stop) { dst(k++, rhscol) += uIt.value() * @@ -210,19 +210,19 @@ EIGEN_DONT_INLINE void ei_skyline_col_major_time_dense_product(const Lhs& lhs, c }; //Use matrix diagonal part <- Improvement : use inner iterator on dense matrix. - for (unsigned int col = 0; col < rhs.cols(); col++) { - for (unsigned int row = 0; row < lhs.rows(); row++) { + for (Index col = 0; col < rhs.cols(); col++) { + for (Index row = 0; row < lhs.rows(); row++) { dst(row, col) = lhs.coeffDiag(row) * rhs(row, col); } } //Use matrix upper triangular part - for (unsigned int row = 0; row < lhs.rows(); row++) { + for (Index row = 0; row < lhs.rows(); row++) { typename _Lhs::InnerUpperIterator uIt(lhs, row); - const int stop = uIt.col() + uIt.size(); - for (unsigned int col = 0; col < rhs.cols(); col++) { + const Index stop = uIt.col() + uIt.size(); + for (Index col = 0; col < rhs.cols(); col++) { - unsigned int k = uIt.col(); + Index k = uIt.col(); Scalar tmp = 0; while (k < stop) { tmp += @@ -238,13 +238,13 @@ EIGEN_DONT_INLINE void ei_skyline_col_major_time_dense_product(const Lhs& lhs, c } //Use matrix lower triangular part - for (unsigned int lhscol = 0; lhscol < lhs.cols(); lhscol++) { + for (Index lhscol = 0; lhscol < lhs.cols(); lhscol++) { typename _Lhs::InnerLowerIterator lIt(lhs, lhscol); - const int stop = lIt.size() + lIt.row(); - for (unsigned int rhscol = 0; rhscol < rhs.cols(); rhscol++) { + const Index stop = lIt.size() + lIt.row(); + for (Index rhscol = 0; rhscol < rhs.cols(); rhscol++) { const Scalar rhsCoeff = rhs.coeff(lhscol, rhscol); - unsigned int k = lIt.row(); + Index k = lIt.row(); while (k < stop) { dst(k++, rhscol) += lIt.value() * diff --git a/unsupported/Eigen/src/Skyline/SkylineStorage.h b/unsupported/Eigen/src/Skyline/SkylineStorage.h index 641508f75..13f3e0ced 100644 --- a/unsupported/Eigen/src/Skyline/SkylineStorage.h +++ b/unsupported/Eigen/src/Skyline/SkylineStorage.h @@ -34,6 +34,7 @@ template<typename Scalar> class SkylineStorage { typedef typename NumTraits<Scalar>::Real RealScalar; + typedef SparseIndex Index; public: SkylineStorage() @@ -70,8 +71,8 @@ public: memcpy(m_diag, other.m_diag, m_diagSize * sizeof (Scalar)); memcpy(m_upper, other.m_upper, other.upperSize() * sizeof (Scalar)); memcpy(m_lower, other.m_lower, other.lowerSize() * sizeof (Scalar)); - memcpy(m_upperProfile, other.m_upperProfile, m_upperProfileSize * sizeof (int)); - memcpy(m_lowerProfile, other.m_lowerProfile, m_lowerProfileSize * sizeof (int)); + memcpy(m_upperProfile, other.m_upperProfile, m_upperProfileSize * sizeof (Index)); + memcpy(m_lowerProfile, other.m_lowerProfile, m_lowerProfileSize * sizeof (Index)); return *this; } @@ -96,8 +97,8 @@ public: delete[] m_lowerProfile; } - void reserve(size_t size, size_t upperProfileSize, size_t lowerProfileSize, size_t upperSize, size_t lowerSize) { - int newAllocatedSize = size + upperSize + lowerSize; + void reserve(Index size, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) { + Index newAllocatedSize = size + upperSize + lowerSize; if (newAllocatedSize > m_allocatedSize) reallocate(size, upperProfileSize, lowerProfileSize, upperSize, lowerSize); } @@ -107,9 +108,9 @@ public: reallocate(m_diagSize, m_upperProfileSize, m_lowerProfileSize, m_upperSize, m_lowerSize); } - void resize(size_t diagSize, size_t upperProfileSize, size_t lowerProfileSize, size_t upperSize, size_t lowerSize, float reserveSizeFactor = 0) { + void resize(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize, float reserveSizeFactor = 0) { if (m_allocatedSize < diagSize + upperSize + lowerSize) - reallocate(diagSize, upperProfileSize, lowerProfileSize, upperSize + size_t(reserveSizeFactor * upperSize), lowerSize + size_t(reserveSizeFactor * lowerSize)); + reallocate(diagSize, upperProfileSize, lowerProfileSize, upperSize + Index(reserveSizeFactor * upperSize), lowerSize + Index(reserveSizeFactor * lowerSize)); m_diagSize = diagSize; m_upperSize = upperSize; m_lowerSize = lowerSize; @@ -117,27 +118,27 @@ public: m_lowerProfileSize = lowerProfileSize; } - inline size_t diagSize() const { + inline Index diagSize() const { return m_diagSize; } - inline size_t upperSize() const { + inline Index upperSize() const { return m_upperSize; } - inline size_t lowerSize() const { + inline Index lowerSize() const { return m_lowerSize; } - inline size_t upperProfileSize() const { + inline Index upperProfileSize() const { return m_upperProfileSize; } - inline size_t lowerProfileSize() const { + inline Index lowerProfileSize() const { return m_lowerProfileSize; } - inline size_t allocatedSize() const { + inline Index allocatedSize() const { return m_allocatedSize; } @@ -145,47 +146,47 @@ public: m_diagSize = 0; } - inline Scalar& diag(size_t i) { + inline Scalar& diag(Index i) { return m_diag[i]; } - inline const Scalar& diag(size_t i) const { + inline const Scalar& diag(Index i) const { return m_diag[i]; } - inline Scalar& upper(size_t i) { + inline Scalar& upper(Index i) { return m_upper[i]; } - inline const Scalar& upper(size_t i) const { + inline const Scalar& upper(Index i) const { return m_upper[i]; } - inline Scalar& lower(size_t i) { + inline Scalar& lower(Index i) { return m_lower[i]; } - inline const Scalar& lower(size_t i) const { + inline const Scalar& lower(Index i) const { return m_lower[i]; } - inline int& upperProfile(size_t i) { + inline Index& upperProfile(Index i) { return m_upperProfile[i]; } - inline const int& upperProfile(size_t i) const { + inline const Index& upperProfile(Index i) const { return m_upperProfile[i]; } - inline int& lowerProfile(size_t i) { + inline Index& lowerProfile(Index i) { return m_lowerProfile[i]; } - inline const int& lowerProfile(size_t i) const { + inline const Index& lowerProfile(Index i) const { return m_lowerProfile[i]; } - static SkylineStorage Map(int* upperProfile, int* lowerProfile, Scalar* diag, Scalar* upper, Scalar* lower, size_t size, size_t upperSize, size_t lowerSize) { + static SkylineStorage Map(Index* upperProfile, Index* lowerProfile, Scalar* diag, Scalar* upper, Scalar* lower, Index size, Index upperSize, Index lowerSize) { SkylineStorage res; res.m_upperProfile = upperProfile; res.m_lowerProfile = lowerProfile; @@ -202,8 +203,8 @@ public: memset(m_diag, 0, m_diagSize * sizeof (Scalar)); memset(m_upper, 0, m_upperSize * sizeof (Scalar)); memset(m_lower, 0, m_lowerSize * sizeof (Scalar)); - memset(m_upperProfile, 0, m_diagSize * sizeof (int)); - memset(m_lowerProfile, 0, m_diagSize * sizeof (int)); + memset(m_upperProfile, 0, m_diagSize * sizeof (Index)); + memset(m_lowerProfile, 0, m_diagSize * sizeof (Index)); } void prune(Scalar reference, RealScalar epsilon = dummy_precision<RealScalar>()) { @@ -212,26 +213,26 @@ public: protected: - inline void reallocate(size_t diagSize, size_t upperProfileSize, size_t lowerProfileSize, size_t upperSize, size_t lowerSize) { + inline void reallocate(Index diagSize, Index upperProfileSize, Index lowerProfileSize, Index upperSize, Index lowerSize) { Scalar* diag = new Scalar[diagSize]; Scalar* upper = new Scalar[upperSize]; Scalar* lower = new Scalar[lowerSize]; - int* upperProfile = new int[upperProfileSize]; - int* lowerProfile = new int[lowerProfileSize]; + Index* upperProfile = new Index[upperProfileSize]; + Index* lowerProfile = new Index[lowerProfileSize]; - size_t copyDiagSize = std::min(diagSize, m_diagSize); - size_t copyUpperSize = std::min(upperSize, m_upperSize); - size_t copyLowerSize = std::min(lowerSize, m_lowerSize); - size_t copyUpperProfileSize = std::min(upperProfileSize, m_upperProfileSize); - size_t copyLowerProfileSize = std::min(lowerProfileSize, m_lowerProfileSize); + Index copyDiagSize = std::min(diagSize, m_diagSize); + Index copyUpperSize = std::min(upperSize, m_upperSize); + Index copyLowerSize = std::min(lowerSize, m_lowerSize); + Index copyUpperProfileSize = std::min(upperProfileSize, m_upperProfileSize); + Index copyLowerProfileSize = std::min(lowerProfileSize, m_lowerProfileSize); // copy memcpy(diag, m_diag, copyDiagSize * sizeof (Scalar)); memcpy(upper, m_upper, copyUpperSize * sizeof (Scalar)); memcpy(lower, m_lower, copyLowerSize * sizeof (Scalar)); - memcpy(upperProfile, m_upperProfile, copyUpperProfileSize * sizeof (int)); - memcpy(lowerProfile, m_lowerProfile, copyLowerProfileSize * sizeof (int)); + memcpy(upperProfile, m_upperProfile, copyUpperProfileSize * sizeof (Index)); + memcpy(lowerProfile, m_lowerProfile, copyLowerProfileSize * sizeof (Index)); @@ -255,14 +256,14 @@ public: Scalar* m_diag; Scalar* m_upper; Scalar* m_lower; - int* m_upperProfile; - int* m_lowerProfile; - size_t m_diagSize; - size_t m_upperSize; - size_t m_lowerSize; - size_t m_upperProfileSize; - size_t m_lowerProfileSize; - size_t m_allocatedSize; + Index* m_upperProfile; + Index* m_lowerProfile; + Index m_diagSize; + Index m_upperSize; + Index m_lowerSize; + Index m_upperProfileSize; + Index m_lowerProfileSize; + Index m_allocatedSize; }; diff --git a/unsupported/Eigen/src/Skyline/SkylineUtil.h b/unsupported/Eigen/src/Skyline/SkylineUtil.h index 71563adfb..7781c33e7 100644 --- a/unsupported/Eigen/src/Skyline/SkylineUtil.h +++ b/unsupported/Eigen/src/Skyline/SkylineUtil.h @@ -56,20 +56,22 @@ EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \ } #define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ -EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \ -EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \ -EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \ -EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \ -EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) + EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \ + EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \ + EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \ + EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \ + EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) #define _EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \ -typedef BaseClass Base; \ -typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ -typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ -enum { Flags = Eigen::ei_traits<Derived>::Flags, }; + typedef BaseClass Base; \ + typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ + typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ + typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \ + typedef typename Eigen::ei_index<StorageKind>::type Index; \ + enum { Flags = Eigen::ei_traits<Derived>::Flags, }; #define EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived) \ -_EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SkylineMatrixBase<Derived>) + _EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SkylineMatrixBase<Derived>) template<typename Derived> class SkylineMatrixBase; template<typename _Scalar, int _Flags = 0> class SkylineMatrix; |