diff options
author | 2010-05-30 16:00:58 -0400 | |
---|---|---|
committer | 2010-05-30 16:00:58 -0400 | |
commit | aaaade4b3d66d67d2c08af3372c3965e7255b2e8 (patch) | |
tree | 76dfaefb014333b2f98c6db660454771655ea8b7 /Eigen/src/Sparse | |
parent | faa3ff3be6a02b57c6cb05edc87375e54ab96606 (diff) |
the Index types change.
As discussed on the list (too long to explain here).
Diffstat (limited to 'Eigen/src/Sparse')
22 files changed, 545 insertions, 508 deletions
diff --git a/Eigen/src/Sparse/AmbiVector.h b/Eigen/src/Sparse/AmbiVector.h index 1ac28272b..7b18f8cc2 100644 --- a/Eigen/src/Sparse/AmbiVector.h +++ b/Eigen/src/Sparse/AmbiVector.h @@ -35,7 +35,8 @@ template<typename _Scalar> class AmbiVector public: typedef _Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar; - AmbiVector(int size) + typedef SparseIndex Index; + AmbiVector(Index size) : m_buffer(0), m_zero(0), m_size(0), m_allocatedSize(0), m_allocatedElements(0), m_mode(-1) { resize(size); @@ -44,40 +45,40 @@ template<typename _Scalar> class AmbiVector void init(double estimatedDensity); void init(int mode); - int nonZeros() const; + Index nonZeros() const; /** Specifies a sub-vector to work on */ - void setBounds(int start, int end) { m_start = start; m_end = end; } + void setBounds(Index start, Index end) { m_start = start; m_end = end; } void setZero(); void restart(); - Scalar& coeffRef(int i); - Scalar& coeff(int i); + Scalar& coeffRef(Index i); + Scalar& coeff(Index i); class Iterator; ~AmbiVector() { delete[] m_buffer; } - void resize(int size) + void resize(Index size) { if (m_allocatedSize < size) reallocate(size); m_size = size; } - int size() const { return m_size; } + Index size() const { return m_size; } protected: - void reallocate(int size) + void reallocate(Index size) { // if the size of the matrix is not too large, let's allocate a bit more than needed such // that we can handle dense vector even in sparse mode. delete[] m_buffer; if (size<1000) { - int allocSize = (size * sizeof(ListEl))/sizeof(Scalar); + Index allocSize = (size * sizeof(ListEl))/sizeof(Scalar); m_allocatedElements = (allocSize*sizeof(Scalar))/sizeof(ListEl); m_buffer = new Scalar[allocSize]; } @@ -93,9 +94,9 @@ template<typename _Scalar> class AmbiVector void reallocateSparse() { - int copyElements = m_allocatedElements; - m_allocatedElements = std::min(int(m_allocatedElements*1.5),m_size); - int allocSize = m_allocatedElements * sizeof(ListEl); + Index copyElements = m_allocatedElements; + m_allocatedElements = std::min(Index(m_allocatedElements*1.5),m_size); + Index allocSize = m_allocatedElements * sizeof(ListEl); allocSize = allocSize/sizeof(Scalar) + (allocSize%sizeof(Scalar)>0?1:0); Scalar* newBuffer = new Scalar[allocSize]; memcpy(newBuffer, m_buffer, copyElements * sizeof(ListEl)); @@ -107,30 +108,30 @@ template<typename _Scalar> class AmbiVector // element type of the linked list struct ListEl { - int next; - int index; + Index next; + Index index; Scalar value; }; // used to store data in both mode Scalar* m_buffer; Scalar m_zero; - int m_size; - int m_start; - int m_end; - int m_allocatedSize; - int m_allocatedElements; - int m_mode; + Index m_size; + Index m_start; + Index m_end; + Index m_allocatedSize; + Index m_allocatedElements; + Index m_mode; // linked list mode - int m_llStart; - int m_llCurrent; - int m_llSize; + Index m_llStart; + Index m_llCurrent; + Index m_llSize; }; /** \returns the number of non zeros in the current sub vector */ template<typename Scalar> -int AmbiVector<Scalar>::nonZeros() const +SparseIndex AmbiVector<Scalar>::nonZeros() const { if (m_mode==IsSparse) return m_llSize; @@ -175,7 +176,7 @@ void AmbiVector<Scalar>::setZero() { if (m_mode==IsDense) { - for (int i=m_start; i<m_end; ++i) + for (Index i=m_start; i<m_end; ++i) m_buffer[i] = Scalar(0); } else @@ -187,7 +188,7 @@ void AmbiVector<Scalar>::setZero() } template<typename Scalar> -Scalar& AmbiVector<Scalar>::coeffRef(int i) +Scalar& AmbiVector<Scalar>::coeffRef(Index i) { if (m_mode==IsDense) return m_buffer[i]; @@ -221,7 +222,7 @@ Scalar& AmbiVector<Scalar>::coeffRef(int i) } else { - int nextel = llElements[m_llCurrent].next; + Index nextel = llElements[m_llCurrent].next; ei_assert(i>=llElements[m_llCurrent].index && "you must call restart() before inserting an element with lower or equal index"); while (nextel >= 0 && llElements[nextel].index<=i) { @@ -256,7 +257,7 @@ Scalar& AmbiVector<Scalar>::coeffRef(int i) } template<typename Scalar> -Scalar& AmbiVector<Scalar>::coeff(int i) +Scalar& AmbiVector<Scalar>::coeff(Index i) { if (m_mode==IsDense) return m_buffer[i]; @@ -270,7 +271,7 @@ Scalar& AmbiVector<Scalar>::coeff(int i) } else { - int elid = m_llStart; + Index elid = m_llStart; while (elid >= 0 && llElements[elid].index<i) elid = llElements[elid].next; @@ -327,7 +328,7 @@ class AmbiVector<_Scalar>::Iterator } } - int index() const { return m_cachedIndex; } + Index index() const { return m_cachedIndex; } Scalar value() const { return m_cachedValue; } operator bool() const { return m_cachedIndex>=0; } @@ -365,9 +366,9 @@ class AmbiVector<_Scalar>::Iterator protected: const AmbiVector& m_vector; // the target vector - int m_currentEl; // the current element in sparse/linked-list mode + Index m_currentEl; // the current element in sparse/linked-list mode RealScalar m_epsilon; // epsilon used to prune zero coefficients - int m_cachedIndex; // current coordinate + Index m_cachedIndex; // current coordinate Scalar m_cachedValue; // current value bool m_isDense; // mode of the vector }; diff --git a/Eigen/src/Sparse/CholmodSupport.h b/Eigen/src/Sparse/CholmodSupport.h index cf407240f..82a09f35c 100644 --- a/Eigen/src/Sparse/CholmodSupport.h +++ b/Eigen/src/Sparse/CholmodSupport.h @@ -114,8 +114,8 @@ MappedSparseMatrix<Scalar,Flags>::MappedSparseMatrix(cholmod_sparse& cm) { m_innerSize = cm.nrow; m_outerSize = cm.ncol; - m_outerIndex = reinterpret_cast<int*>(cm.p); - m_innerIndices = reinterpret_cast<int*>(cm.i); + m_outerIndex = reinterpret_cast<Index*>(cm.p); + m_innerIndices = reinterpret_cast<Index*>(cm.i); m_values = reinterpret_cast<Scalar*>(cm.x); m_nnz = m_outerIndex[cm.ncol]; } @@ -220,7 +220,7 @@ template<typename MatrixType> template<typename Derived> bool SparseLLT<MatrixType,Cholmod>::solveInPlace(MatrixBase<Derived> &b) const { - const int size = m_cholmodFactor->n; + const Index size = m_cholmodFactor->n; ei_assert(size==b.rows()); // this uses Eigen's triangular sparse solver diff --git a/Eigen/src/Sparse/CompressedStorage.h b/Eigen/src/Sparse/CompressedStorage.h index 4fc1797d1..37d337639 100644 --- a/Eigen/src/Sparse/CompressedStorage.h +++ b/Eigen/src/Sparse/CompressedStorage.h @@ -32,6 +32,7 @@ template<typename Scalar> class CompressedStorage { typedef typename NumTraits<Scalar>::Real RealScalar; + typedef SparseIndex Index; public: CompressedStorage() : m_values(0), m_indices(0), m_size(0), m_allocatedSize(0) @@ -53,7 +54,7 @@ class CompressedStorage { resize(other.size()); memcpy(m_values, other.m_values, m_size * sizeof(Scalar)); - memcpy(m_indices, other.m_indices, m_size * sizeof(int)); + memcpy(m_indices, other.m_indices, m_size * sizeof(Index)); return *this; } @@ -91,9 +92,9 @@ class CompressedStorage m_size = size; } - void append(const Scalar& v, int i) + void append(const Scalar& v, Index i) { - int id = static_cast<int>(m_size); + Index id = static_cast<Index>(m_size); resize(m_size+1, 1); m_values[id] = v; m_indices[id] = i; @@ -106,10 +107,10 @@ class CompressedStorage inline Scalar& value(size_t i) { return m_values[i]; } inline const Scalar& value(size_t i) const { return m_values[i]; } - inline int& index(size_t i) { return m_indices[i]; } - inline const int& index(size_t i) const { return m_indices[i]; } + inline Index& index(size_t i) { return m_indices[i]; } + inline const Index& index(size_t i) const { return m_indices[i]; } - static CompressedStorage Map(int* indices, Scalar* values, size_t size) + static CompressedStorage Map(Index* indices, Scalar* values, size_t size) { CompressedStorage res; res.m_indices = indices; @@ -119,13 +120,13 @@ class CompressedStorage } /** \returns the largest \c k such that for all \c j in [0,k) index[\c j]\<\a key */ - inline int searchLowerIndex(int key) const + inline Index searchLowerIndex(Index key) const { return searchLowerIndex(0, m_size, key); } /** \returns the largest \c k in [start,end) such that for all \c j in [start,k) index[\c j]\<\a key */ - inline int searchLowerIndex(size_t start, size_t end, int key) const + inline Index searchLowerIndex(size_t start, size_t end, Index key) const { while(end>start) { @@ -135,12 +136,12 @@ class CompressedStorage else end = mid; } - return static_cast<int>(start); + return static_cast<Index>(start); } /** \returns the stored value at index \a key * If the value does not exist, then the value \a defaultValue is returned without any insertion. */ - inline Scalar at(int key, Scalar defaultValue = Scalar(0)) const + inline Scalar at(Index key, Scalar defaultValue = Scalar(0)) const { if (m_size==0) return defaultValue; @@ -153,7 +154,7 @@ class CompressedStorage } /** Like at(), but the search is performed in the range [start,end) */ - inline Scalar atInRange(size_t start, size_t end, int key, Scalar defaultValue = Scalar(0)) const + inline Scalar atInRange(size_t start, size_t end, Index key, Scalar defaultValue = Scalar(0)) const { if (start>=end) return Scalar(0); @@ -168,7 +169,7 @@ class CompressedStorage /** \returns a reference to the value at index \a key * If the value does not exist, then the value \a defaultValue is inserted * such that the keys are sorted. */ - inline Scalar& atWithInsertion(int key, Scalar defaultValue = Scalar(0)) + inline Scalar& atWithInsertion(Index key, Scalar defaultValue = Scalar(0)) { size_t id = searchLowerIndex(0,m_size,key); if (id>=m_size || m_indices[id]!=key) @@ -206,11 +207,11 @@ class CompressedStorage inline void reallocate(size_t size) { Scalar* newValues = new Scalar[size]; - int* newIndices = new int[size]; + Index* newIndices = new Index[size]; size_t copySize = std::min(size, m_size); // copy memcpy(newValues, m_values, copySize * sizeof(Scalar)); - memcpy(newIndices, m_indices, copySize * sizeof(int)); + memcpy(newIndices, m_indices, copySize * sizeof(Index)); // delete old stuff delete[] m_values; delete[] m_indices; @@ -221,7 +222,7 @@ class CompressedStorage protected: Scalar* m_values; - int* m_indices; + Index* m_indices; size_t m_size; size_t m_allocatedSize; diff --git a/Eigen/src/Sparse/CoreIterators.h b/Eigen/src/Sparse/CoreIterators.h index 69780456d..7ae847ddc 100644 --- a/Eigen/src/Sparse/CoreIterators.h +++ b/Eigen/src/Sparse/CoreIterators.h @@ -38,9 +38,11 @@ template<typename Derived> class DenseBase<Derived>::InnerIterator { typedef typename Derived::Scalar Scalar; + typedef typename Derived::Index Index; + enum { IsRowMajor = (Derived::Flags&RowMajorBit)==RowMajorBit }; public: - EIGEN_STRONG_INLINE InnerIterator(const Derived& expr, int outer) + EIGEN_STRONG_INLINE InnerIterator(const Derived& expr, Index outer) : m_expression(expr), m_inner(0), m_outer(outer), m_end(expr.rows()) {} @@ -52,17 +54,17 @@ template<typename Derived> class DenseBase<Derived>::InnerIterator EIGEN_STRONG_INLINE InnerIterator& operator++() { m_inner++; return *this; } - EIGEN_STRONG_INLINE int index() const { return m_inner; } - inline int row() const { return IsRowMajor ? m_outer : index(); } - inline int col() const { return IsRowMajor ? index() : m_outer; } + EIGEN_STRONG_INLINE Index index() const { return m_inner; } + inline Index row() const { return IsRowMajor ? m_outer : index(); } + inline Index col() const { return IsRowMajor ? index() : m_outer; } EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; } protected: const Derived& m_expression; - int m_inner; - const int m_outer; - const int m_end; + Index m_inner; + const Index m_outer; + const Index m_end; }; #endif // EIGEN_COREITERATORS_H diff --git a/Eigen/src/Sparse/DynamicSparseMatrix.h b/Eigen/src/Sparse/DynamicSparseMatrix.h index fd7c7fbd7..fea707f15 100644 --- a/Eigen/src/Sparse/DynamicSparseMatrix.h +++ b/Eigen/src/Sparse/DynamicSparseMatrix.h @@ -75,16 +75,16 @@ class DynamicSparseMatrix typedef DynamicSparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> TransposedSparseMatrix; - int m_innerSize; + Index m_innerSize; std::vector<CompressedStorage<Scalar> > m_data; public: - inline int rows() const { return IsRowMajor ? outerSize() : m_innerSize; } - inline int cols() const { return IsRowMajor ? m_innerSize : outerSize(); } - inline int innerSize() const { return m_innerSize; } - inline int outerSize() const { return static_cast<int>(m_data.size()); } - inline int innerNonZeros(int j) const { return m_data[j].size(); } + inline Index rows() const { return IsRowMajor ? outerSize() : m_innerSize; } + inline Index cols() const { return IsRowMajor ? m_innerSize : outerSize(); } + inline Index innerSize() const { return m_innerSize; } + inline Index outerSize() const { return static_cast<Index>(m_data.size()); } + inline Index innerNonZeros(Index j) const { return m_data[j].size(); } std::vector<CompressedStorage<Scalar> >& _data() { return m_data; } const std::vector<CompressedStorage<Scalar> >& _data() const { return m_data; } @@ -92,21 +92,21 @@ class DynamicSparseMatrix /** \returns the coefficient value at given position \a row, \a col * This operation involes a log(rho*outer_size) binary search. */ - inline Scalar coeff(int row, int col) const + inline Scalar coeff(Index row, Index col) const { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; return m_data[outer].at(inner); } /** \returns a reference to the coefficient value at given position \a row, \a col * This operation involes a log(rho*outer_size) binary search. If the coefficient does not - * exist yet, then a sorted insertion into a sequential buffer is performed. + * exist yet, then a sorted insertion Indexo a sequential buffer is performed. */ - inline Scalar& coeffRef(int row, int col) + inline Scalar& coeffRef(Index row, Index col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; return m_data[outer].atWithInsertion(inner); } @@ -114,44 +114,44 @@ class DynamicSparseMatrix void setZero() { - for (int j=0; j<outerSize(); ++j) + for (Index j=0; j<outerSize(); ++j) m_data[j].clear(); } /** \returns the number of non zero coefficients */ - int nonZeros() const + Index nonZeros() const { - int res = 0; - for (int j=0; j<outerSize(); ++j) - res += static_cast<int>(m_data[j].size()); + Index res = 0; + for (Index j=0; j<outerSize(); ++j) + res += static_cast<Index>(m_data[j].size()); return res; } /** \deprecated * Set the matrix to zero and reserve the memory for \a reserveSize nonzero coefficients. */ - EIGEN_DEPRECATED void startFill(int reserveSize = 1000) + EIGEN_DEPRECATED void startFill(Index reserveSize = 1000) { setZero(); reserve(reserveSize); } - void reserve(int reserveSize = 1000) + void reserve(Index reserveSize = 1000) { if (outerSize()>0) { - int reserveSizePerVector = std::max(reserveSize/outerSize(),4); - for (int j=0; j<outerSize(); ++j) + Index reserveSizePerVector = std::max(reserveSize/outerSize(),Index(4)); + for (Index j=0; j<outerSize(); ++j) { m_data[j].reserve(reserveSizePerVector); } } } - inline void startVec(int /*outer*/) {} + inline void startVec(Index /*outer*/) {} - inline Scalar& insertBack(int outer, int inner) + inline Scalar& insertBack(Index outer, Index inner) { - ei_assert(outer<int(m_data.size()) && inner<m_innerSize && "out of range"); + ei_assert(outer<Index(m_data.size()) && inner<m_innerSize && "out of range"); ei_assert(((m_data[outer].size()==0) || (m_data[outer].index(m_data[outer].size()-1)<inner)) && "wrong sorted insertion"); m_data[outer].append(0, inner); @@ -167,10 +167,10 @@ class DynamicSparseMatrix * * \see fillrand(), coeffRef() */ - EIGEN_DEPRECATED Scalar& fill(int row, int col) + EIGEN_DEPRECATED Scalar& fill(Index row, Index col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; return insertBack(outer,inner); } @@ -179,18 +179,18 @@ class DynamicSparseMatrix * Compared to the generic coeffRef(), the unique limitation is that we assume * the coefficient does not exist yet. */ - EIGEN_DEPRECATED Scalar& fillrand(int row, int col) + EIGEN_DEPRECATED Scalar& fillrand(Index row, Index col) { return insert(row,col); } - inline Scalar& insert(int row, int col) + inline Scalar& insert(Index row, Index col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; - int startId = 0; - int id = static_cast<int>(m_data[outer].size()) - 1; + Index startId = 0; + Index id = static_cast<Index>(m_data[outer].size()) - 1; m_data[outer].resize(id+2,1); while ( (id >= startId) && (m_data[outer].index(id) > inner) ) @@ -212,27 +212,27 @@ class DynamicSparseMatrix void prune(Scalar reference, RealScalar epsilon = NumTraits<RealScalar>::dummy_precision()) { - for (int j=0; j<outerSize(); ++j) + for (Index j=0; j<outerSize(); ++j) m_data[j].prune(reference,epsilon); } /** Resize the matrix without preserving the data (the matrix is set to zero) */ - void resize(int rows, int cols) + void resize(Index rows, Index cols) { - const int outerSize = IsRowMajor ? rows : cols; + const Index outerSize = IsRowMajor ? rows : cols; m_innerSize = IsRowMajor ? cols : rows; setZero(); - if (int(m_data.size()) != outerSize) + if (Index(m_data.size()) != outerSize) { m_data.resize(outerSize); } } - void resizeAndKeepData(int rows, int cols) + void resizeAndKeepData(Index rows, Index cols) { - const int outerSize = IsRowMajor ? rows : cols; - const int innerSize = IsRowMajor ? cols : rows; + const Index outerSize = IsRowMajor ? rows : cols; + const Index innerSize = IsRowMajor ? cols : rows; if (m_innerSize>innerSize) { // remove all coefficients with innerCoord>=innerSize @@ -252,7 +252,7 @@ class DynamicSparseMatrix ei_assert(innerSize()==0 && outerSize()==0); } - inline DynamicSparseMatrix(int rows, int cols) + inline DynamicSparseMatrix(Index rows, Index cols) : m_innerSize(0) { resize(rows, cols); @@ -308,15 +308,15 @@ class DynamicSparseMatrix<Scalar,_Flags>::InnerIterator : public SparseVector<Sc { typedef typename SparseVector<Scalar,_Flags>::InnerIterator Base; public: - InnerIterator(const DynamicSparseMatrix& mat, int outer) + InnerIterator(const DynamicSparseMatrix& mat, Index outer) : Base(mat.m_data[outer]), m_outer(outer) {} - inline int row() const { return IsRowMajor ? m_outer : Base::index(); } - inline int col() const { return IsRowMajor ? Base::index() : m_outer; } + inline Index row() const { return IsRowMajor ? m_outer : Base::index(); } + inline Index col() const { return IsRowMajor ? Base::index() : m_outer; } protected: - const int m_outer; + const Index m_outer; }; #endif // EIGEN_DYNAMIC_SPARSEMATRIX_H diff --git a/Eigen/src/Sparse/MappedSparseMatrix.h b/Eigen/src/Sparse/MappedSparseMatrix.h index 43ac6b308..07233ac67 100644 --- a/Eigen/src/Sparse/MappedSparseMatrix.h +++ b/Eigen/src/Sparse/MappedSparseMatrix.h @@ -48,40 +48,40 @@ class MappedSparseMatrix protected: enum { IsRowMajor = Base::IsRowMajor }; - int m_outerSize; - int m_innerSize; - int m_nnz; - int* m_outerIndex; - int* m_innerIndices; + Index m_outerSize; + Index m_innerSize; + Index m_nnz; + Index* m_outerIndex; + Index* m_innerIndices; Scalar* m_values; public: - inline int rows() const { return IsRowMajor ? m_outerSize : m_innerSize; } - inline int cols() const { return IsRowMajor ? m_innerSize : m_outerSize; } - inline int innerSize() const { return m_innerSize; } - inline int outerSize() const { return m_outerSize; } - inline int innerNonZeros(int j) const { return m_outerIndex[j+1]-m_outerIndex[j]; } + inline Index rows() const { return IsRowMajor ? m_outerSize : m_innerSize; } + inline Index cols() const { return IsRowMajor ? m_innerSize : m_outerSize; } + inline Index innerSize() const { return m_innerSize; } + inline Index outerSize() const { return m_outerSize; } + inline Index innerNonZeros(Index j) const { return m_outerIndex[j+1]-m_outerIndex[j]; } //---------------------------------------- // direct access interface inline const Scalar* _valuePtr() const { return m_values; } inline Scalar* _valuePtr() { return m_values; } - inline const int* _innerIndexPtr() const { return m_innerIndices; } - inline int* _innerIndexPtr() { return m_innerIndices; } + inline const Index* _innerIndexPtr() const { return m_innerIndices; } + inline Index* _innerIndexPtr() { return m_innerIndices; } - inline const int* _outerIndexPtr() const { return m_outerIndex; } - inline int* _outerIndexPtr() { return m_outerIndex; } + inline const Index* _outerIndexPtr() const { return m_outerIndex; } + inline Index* _outerIndexPtr() { return m_outerIndex; } //---------------------------------------- - inline Scalar coeff(int row, int col) const + inline Scalar coeff(Index row, Index col) const { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; - int start = m_outerIndex[outer]; - int end = m_outerIndex[outer+1]; + Index start = m_outerIndex[outer]; + Index end = m_outerIndex[outer+1]; if (start==end) return Scalar(0); else if (end>0 && inner==m_innerIndices[end-1]) @@ -89,22 +89,22 @@ class MappedSparseMatrix // ^^ optimization: let's first check if it is the last coefficient // (very common in high level algorithms) - const int* r = std::lower_bound(&m_innerIndices[start],&m_innerIndices[end-1],inner); - const int id = r-&m_innerIndices[0]; + const Index* r = std::lower_bound(&m_innerIndices[start],&m_innerIndices[end-1],inner); + const Index id = r-&m_innerIndices[0]; return ((*r==inner) && (id<end)) ? m_values[id] : Scalar(0); } - inline Scalar& coeffRef(int row, int col) + inline Scalar& coeffRef(Index row, Index col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; - int start = m_outerIndex[outer]; - int end = m_outerIndex[outer+1]; + Index start = m_outerIndex[outer]; + Index end = m_outerIndex[outer+1]; ei_assert(end>=start && "you probably called coeffRef on a non finalized matrix"); ei_assert(end>start && "coeffRef cannot be called on a zero coefficient"); - int* r = std::lower_bound(&m_innerIndices[start],&m_innerIndices[end],inner); - const int id = r-&m_innerIndices[0]; + Index* r = std::lower_bound(&m_innerIndices[start],&m_innerIndices[end],inner); + const Index id = r-&m_innerIndices[0]; ei_assert((*r==inner) && (id<end) && "coeffRef cannot be called on a zero coefficient"); return m_values[id]; } @@ -112,9 +112,9 @@ class MappedSparseMatrix class InnerIterator; /** \returns the number of non zero coefficients */ - inline int nonZeros() const { return m_nnz; } + inline Index nonZeros() const { return m_nnz; } - inline MappedSparseMatrix(int rows, int cols, int nnz, int* outerIndexPtr, int* innerIndexPtr, Scalar* valuePtr) + inline MappedSparseMatrix(Index rows, Index cols, Index nnz, Index* outerIndexPtr, Index* innerIndexPtr, Scalar* valuePtr) : m_outerSize(IsRowMajor?rows:cols), m_innerSize(IsRowMajor?cols:rows), m_nnz(nnz), m_outerIndex(outerIndexPtr), m_innerIndices(innerIndexPtr), m_values(valuePtr) {} @@ -139,7 +139,7 @@ template<typename Scalar, int _Flags> class MappedSparseMatrix<Scalar,_Flags>::InnerIterator { public: - InnerIterator(const MappedSparseMatrix& mat, int outer) + InnerIterator(const MappedSparseMatrix& mat, Index outer) : m_matrix(mat), m_outer(outer), m_id(mat._outerIndexPtr()[outer]), @@ -148,7 +148,7 @@ class MappedSparseMatrix<Scalar,_Flags>::InnerIterator {} template<unsigned int Added, unsigned int Removed> - InnerIterator(const Flagged<MappedSparseMatrix,Added,Removed>& mat, int outer) + InnerIterator(const Flagged<MappedSparseMatrix,Added,Removed>& mat, Index outer) : m_matrix(mat._expression()), m_id(m_matrix._outerIndexPtr()[outer]), m_start(m_id), m_end(m_matrix._outerIndexPtr()[outer+1]) {} @@ -158,18 +158,18 @@ class MappedSparseMatrix<Scalar,_Flags>::InnerIterator inline Scalar value() const { return m_matrix._valuePtr()[m_id]; } inline Scalar& valueRef() { return const_cast<Scalar&>(m_matrix._valuePtr()[m_id]); } - inline int index() const { return m_matrix._innerIndexPtr()[m_id]; } - inline int row() const { return IsRowMajor ? m_outer : index(); } - inline int col() const { return IsRowMajor ? index() : m_outer; } + inline Index index() const { return m_matrix._innerIndexPtr()[m_id]; } + inline Index row() const { return IsRowMajor ? m_outer : index(); } + inline Index col() const { return IsRowMajor ? index() : m_outer; } inline operator bool() const { return (m_id < m_end) && (m_id>=m_start); } protected: const MappedSparseMatrix& 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_MAPPED_SPARSEMATRIX_H diff --git a/Eigen/src/Sparse/RandomSetter.h b/Eigen/src/Sparse/RandomSetter.h index 76f24cf0e..abe98815f 100644 --- a/Eigen/src/Sparse/RandomSetter.h +++ b/Eigen/src/Sparse/RandomSetter.h @@ -166,7 +166,9 @@ template<typename SparseMatrixType, ,int OuterPacketBits = 6> class RandomSetter { - typedef typename ei_traits<SparseMatrixType>::Scalar Scalar; + typedef typename SparseMatrixType::Scalar Scalar; + typedef typename SparseMatrixType::Index Index; + struct ScalarWrapper { ScalarWrapper() : value(0) {} @@ -194,14 +196,14 @@ class RandomSetter inline RandomSetter(SparseMatrixType& target) : mp_target(&target) { - const int outerSize = SwapStorage ? target.innerSize() : target.outerSize(); - const int innerSize = SwapStorage ? target.outerSize() : target.innerSize(); + const Index outerSize = SwapStorage ? target.innerSize() : target.outerSize(); + const Index innerSize = SwapStorage ? target.outerSize() : target.innerSize(); m_outerPackets = outerSize >> OuterPacketBits; if (outerSize&OuterPacketMask) m_outerPackets += 1; m_hashmaps = new HashMapType[m_outerPackets]; // compute number of bits needed to store inner indices - int aux = innerSize - 1; + Index aux = innerSize - 1; m_keyBitsOffset = 0; while (aux) { @@ -209,11 +211,11 @@ class RandomSetter aux = aux >> 1; } KeyType ik = (1<<(OuterPacketBits+m_keyBitsOffset)); - for (int k=0; k<m_outerPackets; ++k) + for (Index k=0; k<m_outerPackets; ++k) MapTraits<ScalarWrapper>::setInvalidKey(m_hashmaps[k],ik); // insert current coeffs - for (int j=0; j<mp_target->outerSize(); ++j) + for (Index j=0; j<mp_target->outerSize(); ++j) for (typename SparseMatrixType::InnerIterator it(*mp_target,j); it; ++it) (*this)(TargetRowMajor?j:it.index(), TargetRowMajor?it.index():j) = it.value(); } @@ -226,18 +228,18 @@ class RandomSetter { mp_target->setZero(); mp_target->reserve(nonZeros()); - int prevOuter = -1; - for (int k=0; k<m_outerPackets; ++k) + Index prevOuter = -1; + for (Index k=0; k<m_outerPackets; ++k) { - const int outerOffset = (1<<OuterPacketBits) * k; + const Index outerOffset = (1<<OuterPacketBits) * k; typename HashMapType::iterator end = m_hashmaps[k].end(); for (typename HashMapType::iterator it = m_hashmaps[k].begin(); it!=end; ++it) { - const int outer = (it->first >> m_keyBitsOffset) + outerOffset; - const int inner = it->first & keyBitsMask; + const Index outer = (it->first >> m_keyBitsOffset) + outerOffset; + const Index inner = it->first & keyBitsMask; if (prevOuter!=outer) { - for (int j=prevOuter+1;j<=outer;++j) + for (Index j=prevOuter+1;j<=outer;++j) mp_target->startVec(j); prevOuter = outer; } @@ -251,20 +253,20 @@ class RandomSetter VectorXi positions(mp_target->outerSize()); positions.setZero(); // pass 1 - for (int k=0; k<m_outerPackets; ++k) + for (Index k=0; k<m_outerPackets; ++k) { typename HashMapType::iterator end = m_hashmaps[k].end(); for (typename HashMapType::iterator it = m_hashmaps[k].begin(); it!=end; ++it) { - const int outer = it->first & keyBitsMask; + const Index outer = it->first & keyBitsMask; ++positions[outer]; } } // prefix sum - int count = 0; - for (int j=0; j<mp_target->outerSize(); ++j) + Index count = 0; + for (Index j=0; j<mp_target->outerSize(); ++j) { - int tmp = positions[j]; + Index tmp = positions[j]; mp_target->_outerIndexPtr()[j] = count; positions[j] = count; count += tmp; @@ -272,20 +274,20 @@ class RandomSetter mp_target->_outerIndexPtr()[mp_target->outerSize()] = count; mp_target->resizeNonZeros(count); // pass 2 - for (int k=0; k<m_outerPackets; ++k) + for (Index k=0; k<m_outerPackets; ++k) { - const int outerOffset = (1<<OuterPacketBits) * k; + const Index outerOffset = (1<<OuterPacketBits) * k; typename HashMapType::iterator end = m_hashmaps[k].end(); for (typename HashMapType::iterator it = m_hashmaps[k].begin(); it!=end; ++it) { - const int inner = (it->first >> m_keyBitsOffset) + outerOffset; - const int outer = it->first & keyBitsMask; + const Index inner = (it->first >> m_keyBitsOffset) + outerOffset; + const Index outer = it->first & keyBitsMask; // sorted insertion // Note that we have to deal with at most 2^OuterPacketBits unsorted coefficients, // moreover those 2^OuterPacketBits coeffs are likely to be sparse, an so only a // small fraction of them have to be sorted, whence the following simple procedure: - int posStart = mp_target->_outerIndexPtr()[outer]; - int i = (positions[outer]++) - 1; + Index posStart = mp_target->_outerIndexPtr()[outer]; + Index i = (positions[outer]++) - 1; while ( (i >= posStart) && (mp_target->_innerIndexPtr()[i] > inner) ) { mp_target->_valuePtr()[i+1] = mp_target->_valuePtr()[i]; @@ -301,14 +303,14 @@ class RandomSetter } /** \returns a reference to the coefficient at given coordinates \a row, \a col */ - Scalar& operator() (int row, int col) + Scalar& operator() (Index row, Index col) { ei_assert(((!IsUpper) || (row<=col)) && "Invalid access to an upper triangular matrix"); ei_assert(((!IsLower) || (col<=row)) && "Invalid access to an upper triangular matrix"); - const int outer = SetterRowMajor ? row : col; - const int inner = SetterRowMajor ? col : row; - const int outerMajor = outer >> OuterPacketBits; // index of the packet/map - const int outerMinor = outer & OuterPacketMask; // index of the inner vector in the packet + const Index outer = SetterRowMajor ? row : col; + const Index inner = SetterRowMajor ? col : row; + const Index outerMajor = outer >> OuterPacketBits; // index of the packet/map + const Index outerMinor = outer & OuterPacketMask; // index of the inner vector in the packet const KeyType key = (KeyType(outerMinor)<<m_keyBitsOffset) | inner; return m_hashmaps[outerMajor][key].value; } @@ -318,11 +320,11 @@ class RandomSetter * \note According to the underlying map/hash_map implementation, * this function might be quite expensive. */ - int nonZeros() const + Index nonZeros() const { - int nz = 0; - for (int k=0; k<m_outerPackets; ++k) - nz += static_cast<int>(m_hashmaps[k].size()); + Index nz = 0; + for (Index k=0; k<m_outerPackets; ++k) + nz += static_cast<Index>(m_hashmaps[k].size()); return nz; } @@ -331,7 +333,7 @@ class RandomSetter HashMapType* m_hashmaps; SparseMatrixType* mp_target; - int m_outerPackets; + Index m_outerPackets; unsigned char m_keyBitsOffset; }; diff --git a/Eigen/src/Sparse/SparseBlock.h b/Eigen/src/Sparse/SparseBlock.h index bdbc46025..bf8b5adc7 100644 --- a/Eigen/src/Sparse/SparseBlock.h +++ b/Eigen/src/Sparse/SparseBlock.h @@ -54,22 +54,22 @@ class SparseInnerVectorSet : ei_no_assignment_operator, class InnerIterator: public MatrixType::InnerIterator { public: - inline InnerIterator(const SparseInnerVectorSet& xpr, int outer) + inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer) : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) {} - inline int row() const { return IsRowMajor ? m_outer : this->index(); } - inline int col() const { return IsRowMajor ? this->index() : m_outer; } + inline Index row() const { return IsRowMajor ? m_outer : this->index(); } + inline Index col() const { return IsRowMajor ? this->index() : m_outer; } protected: - int m_outer; + Index m_outer; }; - inline SparseInnerVectorSet(const MatrixType& matrix, int outerStart, int outerSize) + inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize) : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize) { ei_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) ); } - inline SparseInnerVectorSet(const MatrixType& matrix, int outer) + inline SparseInnerVectorSet(const MatrixType& matrix, Index outer) : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size) { ei_assert(Size!=Dynamic); @@ -88,15 +88,14 @@ class SparseInnerVectorSet : ei_no_assignment_operator, // return *this; // } - EIGEN_STRONG_INLINE int rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - EIGEN_STRONG_INLINE int cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } + EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } + EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } protected: const typename MatrixType::Nested m_matrix; - int m_outerStart; - const ei_int_if_dynamic<Size> m_outerSize; - + Index m_outerStart; + const ei_variable_if_dynamic<Index, Size> m_outerSize; }; /*************************************************************************** @@ -116,22 +115,22 @@ class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options>, Size> class InnerIterator: public MatrixType::InnerIterator { public: - inline InnerIterator(const SparseInnerVectorSet& xpr, int outer) + inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer) : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) {} - inline int row() const { return IsRowMajor ? m_outer : this->index(); } - inline int col() const { return IsRowMajor ? this->index() : m_outer; } + inline Index row() const { return IsRowMajor ? m_outer : this->index(); } + inline Index col() const { return IsRowMajor ? this->index() : m_outer; } protected: - int m_outer; + Index m_outer; }; - inline SparseInnerVectorSet(const MatrixType& matrix, int outerStart, int outerSize) + inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize) : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize) { ei_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) ); } - inline SparseInnerVectorSet(const MatrixType& matrix, int outer) + inline SparseInnerVectorSet(const MatrixType& matrix, Index outer) : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size) { ei_assert(Size!=Dynamic); @@ -150,7 +149,7 @@ class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options>, Size> else { // evaluate/copy vector per vector - for (int j=0; j<m_outerSize.value(); ++j) + for (Index j=0; j<m_outerSize.value(); ++j) { SparseVector<Scalar,IsRowMajor ? RowMajorBit : 0> aux(other.innerVector(j)); m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data()); @@ -164,10 +163,10 @@ class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options>, Size> return operator=<SparseInnerVectorSet>(other); } - int nonZeros() const + Index nonZeros() const { - int count = 0; - for (int j=0; j<m_outerSize; ++j) + Index count = 0; + for (Index j=0; j<m_outerSize; ++j) count += m_matrix._data()[m_outerStart+j].size(); return count; } @@ -185,14 +184,14 @@ class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options>, Size> // return *this; // } - EIGEN_STRONG_INLINE int rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - EIGEN_STRONG_INLINE int cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } + EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } + EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } protected: const typename MatrixType::Nested m_matrix; - int m_outerStart; - const ei_int_if_dynamic<Size> m_outerSize; + Index m_outerStart; + const ei_variable_if_dynamic<Index, Size> m_outerSize; }; @@ -214,22 +213,22 @@ class SparseInnerVectorSet<SparseMatrix<_Scalar, _Options>, Size> class InnerIterator: public MatrixType::InnerIterator { public: - inline InnerIterator(const SparseInnerVectorSet& xpr, int outer) + inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer) : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) {} - inline int row() const { return IsRowMajor ? m_outer : this->index(); } - inline int col() const { return IsRowMajor ? this->index() : m_outer; } + inline Index row() const { return IsRowMajor ? m_outer : this->index(); } + inline Index col() const { return IsRowMajor ? this->index() : m_outer; } protected: - int m_outer; + Index m_outer; }; - inline SparseInnerVectorSet(const MatrixType& matrix, int outerStart, int outerSize) + inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize) : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize) { ei_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) ); } - inline SparseInnerVectorSet(const MatrixType& matrix, int outer) + inline SparseInnerVectorSet(const MatrixType& matrix, Index outer) : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size) { ei_assert(Size==1); @@ -248,7 +247,7 @@ class SparseInnerVectorSet<SparseMatrix<_Scalar, _Options>, Size> else { // evaluate/copy vector per vector - for (int j=0; j<m_outerSize.value(); ++j) + for (Index j=0; j<m_outerSize.value(); ++j) { SparseVector<Scalar,IsRowMajor ? RowMajorBit : 0> aux(other.innerVector(j)); m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data()); @@ -267,17 +266,17 @@ class SparseInnerVectorSet<SparseMatrix<_Scalar, _Options>, Size> inline Scalar* _valuePtr() { return m_matrix.const_cast_derived()._valuePtr() + m_matrix._outerIndexPtr()[m_outerStart]; } - inline const int* _innerIndexPtr() const + inline const Index* _innerIndexPtr() const { return m_matrix._innerIndexPtr() + m_matrix._outerIndexPtr()[m_outerStart]; } - inline int* _innerIndexPtr() + inline Index* _innerIndexPtr() { return m_matrix.const_cast_derived()._innerIndexPtr() + m_matrix._outerIndexPtr()[m_outerStart]; } - inline const int* _outerIndexPtr() const + inline const Index* _outerIndexPtr() const { return m_matrix._outerIndexPtr() + m_outerStart; } - inline int* _outerIndexPtr() + inline Index* _outerIndexPtr() { return m_matrix.const_cast_derived()._outerIndexPtr() + m_outerStart; } - int nonZeros() const + Index nonZeros() const { return size_t(m_matrix._outerIndexPtr()[m_outerStart+m_outerSize.value()]) - size_t(m_matrix._outerIndexPtr()[m_outerStart]); } @@ -295,14 +294,14 @@ class SparseInnerVectorSet<SparseMatrix<_Scalar, _Options>, Size> // return *this; // } - EIGEN_STRONG_INLINE int rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - EIGEN_STRONG_INLINE int cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } + EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } + EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } protected: const typename MatrixType::Nested m_matrix; - int m_outerStart; - const ei_int_if_dynamic<Size> m_outerSize; + Index m_outerStart; + const ei_variable_if_dynamic<Index, Size> m_outerSize; }; @@ -310,7 +309,7 @@ class SparseInnerVectorSet<SparseMatrix<_Scalar, _Options>, Size> /** \returns the i-th row of the matrix \c *this. For row-major matrix only. */ template<typename Derived> -SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::row(int i) +SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::row(Index i) { EIGEN_STATIC_ASSERT(IsRowMajor,THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES); return innerVector(i); @@ -319,7 +318,7 @@ SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::row(int i) /** \returns the i-th row of the matrix \c *this. For row-major matrix only. * (read-only version) */ template<typename Derived> -const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::row(int i) const +const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::row(Index i) const { EIGEN_STATIC_ASSERT(IsRowMajor,THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES); return innerVector(i); @@ -327,7 +326,7 @@ const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::row(int i) cons /** \returns the i-th column of the matrix \c *this. For column-major matrix only. */ template<typename Derived> -SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::col(int i) +SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::col(Index i) { EIGEN_STATIC_ASSERT(!IsRowMajor,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); return innerVector(i); @@ -336,7 +335,7 @@ SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::col(int i) /** \returns the i-th column of the matrix \c *this. For column-major matrix only. * (read-only version) */ template<typename Derived> -const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::col(int i) const +const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::col(Index i) const { EIGEN_STATIC_ASSERT(!IsRowMajor,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); return innerVector(i); @@ -346,21 +345,21 @@ const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::col(int i) cons * is col-major (resp. row-major). */ template<typename Derived> -SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::innerVector(int outer) +SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::innerVector(Index outer) { return SparseInnerVectorSet<Derived,1>(derived(), outer); } /** \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this * is col-major (resp. row-major). Read-only. */ template<typename Derived> -const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::innerVector(int outer) const +const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::innerVector(Index outer) const { return SparseInnerVectorSet<Derived,1>(derived(), outer); } //---------- /** \returns the i-th row of the matrix \c *this. For row-major matrix only. */ template<typename Derived> -SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subrows(int start, int size) +SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subrows(Index start, Index size) { EIGEN_STATIC_ASSERT(IsRowMajor,THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES); return innerVectors(start, size); @@ -369,7 +368,7 @@ SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subrows(int sta /** \returns the i-th row of the matrix \c *this. For row-major matrix only. * (read-only version) */ template<typename Derived> -const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subrows(int start, int size) const +const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subrows(Index start, Index size) const { EIGEN_STATIC_ASSERT(IsRowMajor,THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES); return innerVectors(start, size); @@ -377,7 +376,7 @@ const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subrows(i /** \returns the i-th column of the matrix \c *this. For column-major matrix only. */ template<typename Derived> -SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subcols(int start, int size) +SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subcols(Index start, Index size) { EIGEN_STATIC_ASSERT(!IsRowMajor,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); return innerVectors(start, size); @@ -386,7 +385,7 @@ SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subcols(int sta /** \returns the i-th column of the matrix \c *this. For column-major matrix only. * (read-only version) */ template<typename Derived> -const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subcols(int start, int size) const +const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subcols(Index start, Index size) const { EIGEN_STATIC_ASSERT(!IsRowMajor,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); return innerVectors(start, size); @@ -396,14 +395,14 @@ const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subcols(i * is col-major (resp. row-major). */ template<typename Derived> -SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::innerVectors(int outerStart, int outerSize) +SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::innerVectors(Index outerStart, Index outerSize) { return SparseInnerVectorSet<Derived,Dynamic>(derived(), outerStart, outerSize); } /** \returns the \a outer -th column (resp. row) of the matrix \c *this if \c *this * is col-major (resp. row-major). Read-only. */ template<typename Derived> -const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::innerVectors(int outerStart, int outerSize) const +const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::innerVectors(Index outerStart, Index outerSize) const { return SparseInnerVectorSet<Derived,Dynamic>(derived(), outerStart, outerSize); } #endif // EIGEN_SPARSE_BLOCK_H diff --git a/Eigen/src/Sparse/SparseCwiseBinaryOp.h b/Eigen/src/Sparse/SparseCwiseBinaryOp.h index 91fbcb172..90878feda 100644 --- a/Eigen/src/Sparse/SparseCwiseBinaryOp.h +++ b/Eigen/src/Sparse/SparseCwiseBinaryOp.h @@ -68,10 +68,11 @@ class CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator : public ei_sparse_cwise_binary_op_inner_iterator_selector<BinaryOp,Lhs,Rhs,typename CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator> { public: + typedef typename Lhs::Index Index; typedef ei_sparse_cwise_binary_op_inner_iterator_selector< BinaryOp,Lhs,Rhs, InnerIterator> Base; - EIGEN_STRONG_INLINE InnerIterator(const CwiseBinaryOpImpl& binOp, int outer) + EIGEN_STRONG_INLINE InnerIterator(const CwiseBinaryOpImpl& binOp, Index outer) : Base(binOp.derived(),outer) {} }; @@ -95,9 +96,11 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Deri typedef typename ei_traits<CwiseBinaryXpr>::_RhsNested _RhsNested; typedef typename _LhsNested::InnerIterator LhsIterator; typedef typename _RhsNested::InnerIterator RhsIterator; + typedef typename Lhs::Index Index; + public: - EIGEN_STRONG_INLINE ei_sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, int outer) + EIGEN_STRONG_INLINE ei_sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer) : m_lhsIter(xpr.lhs(),outer), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor()) { this->operator++(); @@ -134,9 +137,9 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Deri EIGEN_STRONG_INLINE Scalar value() const { return m_value; } - EIGEN_STRONG_INLINE int index() const { return m_id; } - EIGEN_STRONG_INLINE int row() const { return Lhs::IsRowMajor ? m_lhsIter.row() : index(); } - EIGEN_STRONG_INLINE int col() const { return Lhs::IsRowMajor ? index() : m_lhsIter.col(); } + EIGEN_STRONG_INLINE Index index() const { return m_id; } + EIGEN_STRONG_INLINE Index row() const { return Lhs::IsRowMajor ? m_lhsIter.row() : index(); } + EIGEN_STRONG_INLINE Index col() const { return Lhs::IsRowMajor ? index() : m_lhsIter.col(); } EIGEN_STRONG_INLINE operator bool() const { return m_id>=0; } @@ -145,7 +148,7 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Deri RhsIterator m_rhsIter; const BinaryOp& m_functor; Scalar m_value; - int m_id; + Index m_id; }; // sparse - sparse (product) @@ -159,9 +162,10 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, typedef typename _LhsNested::InnerIterator LhsIterator; typedef typename ei_traits<CwiseBinaryXpr>::_RhsNested _RhsNested; typedef typename _RhsNested::InnerIterator RhsIterator; + typedef typename Lhs::Index Index; public: - EIGEN_STRONG_INLINE ei_sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, int outer) + EIGEN_STRONG_INLINE ei_sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer) : m_lhsIter(xpr.lhs(),outer), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor()) { while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index())) @@ -189,9 +193,9 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_lhsIter.value(), m_rhsIter.value()); } - EIGEN_STRONG_INLINE int index() const { return m_lhsIter.index(); } - EIGEN_STRONG_INLINE int row() const { return m_lhsIter.row(); } - EIGEN_STRONG_INLINE int col() const { return m_lhsIter.col(); } + EIGEN_STRONG_INLINE Index index() const { return m_lhsIter.index(); } + EIGEN_STRONG_INLINE Index row() const { return m_lhsIter.row(); } + EIGEN_STRONG_INLINE Index col() const { return m_lhsIter.col(); } EIGEN_STRONG_INLINE operator bool() const { return (m_lhsIter && m_rhsIter); } @@ -211,10 +215,11 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, typedef typename ei_traits<CwiseBinaryXpr>::_LhsNested _LhsNested; typedef typename ei_traits<CwiseBinaryXpr>::RhsNested RhsNested; typedef typename _LhsNested::InnerIterator LhsIterator; + typedef typename Lhs::Index Index; enum { IsRowMajor = (int(Lhs::Flags)&RowMajorBit)==RowMajorBit }; public: - EIGEN_STRONG_INLINE ei_sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, int outer) + EIGEN_STRONG_INLINE ei_sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer) : m_rhs(xpr.rhs()), m_lhsIter(xpr.lhs(),outer), m_functor(xpr.functor()), m_outer(outer) {} @@ -228,9 +233,9 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, { return m_functor(m_lhsIter.value(), m_rhs.coeff(IsRowMajor?m_outer:m_lhsIter.index(),IsRowMajor?m_lhsIter.index():m_outer)); } - EIGEN_STRONG_INLINE int index() const { return m_lhsIter.index(); } - EIGEN_STRONG_INLINE int row() const { return m_lhsIter.row(); } - EIGEN_STRONG_INLINE int col() const { return m_lhsIter.col(); } + EIGEN_STRONG_INLINE Index index() const { return m_lhsIter.index(); } + EIGEN_STRONG_INLINE Index row() const { return m_lhsIter.row(); } + EIGEN_STRONG_INLINE Index col() const { return m_lhsIter.col(); } EIGEN_STRONG_INLINE operator bool() const { return m_lhsIter; } @@ -238,7 +243,7 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, const RhsNested m_rhs; LhsIterator m_lhsIter; const BinaryFunc m_functor; - const int m_outer; + const Index m_outer; }; // sparse - dense (product) @@ -250,10 +255,12 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, typedef typename CwiseBinaryXpr::Scalar Scalar; typedef typename ei_traits<CwiseBinaryXpr>::_RhsNested _RhsNested; typedef typename _RhsNested::InnerIterator RhsIterator; + typedef typename Lhs::Index Index; + enum { IsRowMajor = (int(Rhs::Flags)&RowMajorBit)==RowMajorBit }; public: - EIGEN_STRONG_INLINE ei_sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, int outer) + EIGEN_STRONG_INLINE ei_sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer) : m_xpr(xpr), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor()), m_outer(outer) {} @@ -266,9 +273,9 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_xpr.lhs().coeff(IsRowMajor?m_outer:m_rhsIter.index(),IsRowMajor?m_rhsIter.index():m_outer), m_rhsIter.value()); } - EIGEN_STRONG_INLINE int index() const { return m_rhsIter.index(); } - EIGEN_STRONG_INLINE int row() const { return m_rhsIter.row(); } - EIGEN_STRONG_INLINE int col() const { return m_rhsIter.col(); } + EIGEN_STRONG_INLINE Index index() const { return m_rhsIter.index(); } + EIGEN_STRONG_INLINE Index row() const { return m_rhsIter.row(); } + EIGEN_STRONG_INLINE Index col() const { return m_rhsIter.col(); } EIGEN_STRONG_INLINE operator bool() const { return m_rhsIter; } @@ -276,7 +283,7 @@ class ei_sparse_cwise_binary_op_inner_iterator_selector<ei_scalar_product_op<T>, const CwiseBinaryXpr& m_xpr; RhsIterator m_rhsIter; const BinaryFunc& m_functor; - const int m_outer; + const Index m_outer; }; diff --git a/Eigen/src/Sparse/SparseCwiseUnaryOp.h b/Eigen/src/Sparse/SparseCwiseUnaryOp.h index f3f8c82c5..5e12da464 100644 --- a/Eigen/src/Sparse/SparseCwiseUnaryOp.h +++ b/Eigen/src/Sparse/SparseCwiseUnaryOp.h @@ -57,9 +57,10 @@ class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::InnerIterator typedef typename CwiseUnaryOpImpl::Scalar Scalar; typedef typename ei_traits<Derived>::_XprTypeNested _MatrixTypeNested; typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator; + typedef typename MatrixType::Index Index; public: - EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl& unaryOp, int outer) + EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl& unaryOp, Index outer) : m_iter(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor()) {} @@ -68,9 +69,9 @@ class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::InnerIterator EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_iter.value()); } - EIGEN_STRONG_INLINE int index() const { return m_iter.index(); } - EIGEN_STRONG_INLINE int row() const { return m_iter.row(); } - EIGEN_STRONG_INLINE int col() const { return m_iter.col(); } + EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); } + EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); } + EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); } EIGEN_STRONG_INLINE operator bool() const { return m_iter; } @@ -98,9 +99,10 @@ class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator typedef typename CwiseUnaryViewImpl::Scalar Scalar; typedef typename ei_traits<Derived>::_MatrixTypeNested _MatrixTypeNested; typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator; + typedef typename MatrixType::Index Index; public: - EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryView, int outer) + EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryView, Index outer) : m_iter(unaryView.derived().nestedExpression(),outer), m_functor(unaryView.derived().functor()) {} @@ -110,9 +112,9 @@ class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_iter.value()); } EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(m_iter.valueRef()); } - EIGEN_STRONG_INLINE int index() const { return m_iter.index(); } - EIGEN_STRONG_INLINE int row() const { return m_iter.row(); } - EIGEN_STRONG_INLINE int col() const { return m_iter.col(); } + EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); } + EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); } + EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); } EIGEN_STRONG_INLINE operator bool() const { return m_iter; } @@ -125,7 +127,7 @@ template<typename Derived> EIGEN_STRONG_INLINE Derived& SparseMatrixBase<Derived>::operator*=(const Scalar& other) { - for (int j=0; j<outerSize(); ++j) + for (Index j=0; j<outerSize(); ++j) for (typename Derived::InnerIterator i(derived(),j); i; ++i) i.valueRef() *= other; return derived(); @@ -135,7 +137,7 @@ template<typename Derived> EIGEN_STRONG_INLINE Derived& SparseMatrixBase<Derived>::operator/=(const Scalar& other) { - for (int j=0; j<outerSize(); ++j) + for (Index j=0; j<outerSize(); ++j) for (typename Derived::InnerIterator i(derived(),j); i; ++i) i.valueRef() /= other; return derived(); diff --git a/Eigen/src/Sparse/SparseDiagonalProduct.h b/Eigen/src/Sparse/SparseDiagonalProduct.h index d0d051796..70b35bc23 100644 --- a/Eigen/src/Sparse/SparseDiagonalProduct.h +++ b/Eigen/src/Sparse/SparseDiagonalProduct.h @@ -93,8 +93,8 @@ class SparseDiagonalProduct ei_assert(lhs.cols() == rhs.rows() && "invalid sparse matrix * diagonal matrix product"); } - EIGEN_STRONG_INLINE int rows() const { return m_lhs.rows(); } - EIGEN_STRONG_INLINE int cols() const { return m_rhs.cols(); } + EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); } + EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); } EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; } EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; } @@ -111,9 +111,10 @@ class ei_sparse_diagonal_product_inner_iterator_selector : public CwiseUnaryOp<ei_scalar_multiple_op<typename Lhs::Scalar>,Rhs>::InnerIterator { typedef typename CwiseUnaryOp<ei_scalar_multiple_op<typename Lhs::Scalar>,Rhs>::InnerIterator Base; + typedef typename Lhs::Index Index; public: inline ei_sparse_diagonal_product_inner_iterator_selector( - const SparseDiagonalProductType& expr, int outer) + const SparseDiagonalProductType& expr, Index outer) : Base(expr.rhs()*(expr.lhs().diagonal().coeff(outer)), outer) {} }; @@ -130,9 +131,10 @@ class ei_sparse_diagonal_product_inner_iterator_selector ei_scalar_product_op<typename Lhs::Scalar>, SparseInnerVectorSet<Rhs,1>, typename Lhs::DiagonalVectorType>::InnerIterator Base; + typedef typename Lhs::Index Index; public: inline ei_sparse_diagonal_product_inner_iterator_selector( - const SparseDiagonalProductType& expr, int outer) + const SparseDiagonalProductType& expr, Index outer) : Base(expr.rhs().innerVector(outer) .cwiseProduct(expr.lhs().diagonal()), 0) {} }; @@ -143,9 +145,10 @@ class ei_sparse_diagonal_product_inner_iterator_selector : public CwiseUnaryOp<ei_scalar_multiple_op<typename Rhs::Scalar>,Lhs>::InnerIterator { typedef typename CwiseUnaryOp<ei_scalar_multiple_op<typename Rhs::Scalar>,Lhs>::InnerIterator Base; + typedef typename Lhs::Index Index; public: inline ei_sparse_diagonal_product_inner_iterator_selector( - const SparseDiagonalProductType& expr, int outer) + const SparseDiagonalProductType& expr, Index outer) : Base(expr.lhs()*expr.rhs().diagonal().coeff(outer), outer) {} }; @@ -162,9 +165,10 @@ class ei_sparse_diagonal_product_inner_iterator_selector ei_scalar_product_op<typename Rhs::Scalar>, SparseInnerVectorSet<Lhs,1>, Transpose<typename Rhs::DiagonalVectorType> >::InnerIterator Base; + typedef typename Lhs::Index Index; public: inline ei_sparse_diagonal_product_inner_iterator_selector( - const SparseDiagonalProductType& expr, int outer) + const SparseDiagonalProductType& expr, Index outer) : Base(expr.lhs().innerVector(outer) .cwiseProduct(expr.rhs().diagonal().transpose()), 0) {} }; diff --git a/Eigen/src/Sparse/SparseLDLT.h b/Eigen/src/Sparse/SparseLDLT.h index 28797a6c4..b6a51c6a6 100644 --- a/Eigen/src/Sparse/SparseLDLT.h +++ b/Eigen/src/Sparse/SparseLDLT.h @@ -78,6 +78,7 @@ class SparseLDLT { protected: typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::Index Index; typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; typedef SparseMatrix<Scalar> CholMatrixType; typedef Matrix<Scalar,MatrixType::ColsAtCompileTime,1> VectorType; @@ -188,36 +189,36 @@ template<typename MatrixType, int Backend> void SparseLDLT<MatrixType,Backend>::_symbolic(const MatrixType& a) { assert(a.rows()==a.cols()); - const int size = a.rows(); + const Index size = a.rows(); m_matrix.resize(size, size); m_parent.resize(size); m_nonZerosPerCol.resize(size); - int * tags = ei_aligned_stack_new(int, size); + Index * tags = ei_aligned_stack_new(Index, size); - const int* Ap = a._outerIndexPtr(); - const int* Ai = a._innerIndexPtr(); - int* Lp = m_matrix._outerIndexPtr(); - const int* P = 0; - int* Pinv = 0; + const Index* Ap = a._outerIndexPtr(); + const Index* Ai = a._innerIndexPtr(); + Index* Lp = m_matrix._outerIndexPtr(); + const Index* P = 0; + Index* Pinv = 0; if (P) { /* If P is present then compute Pinv, the inverse of P */ - for (int k = 0; k < size; ++k) + for (Index k = 0; k < size; ++k) Pinv[P[k]] = k; } - for (int k = 0; k < size; ++k) + for (Index k = 0; k < size; ++k) { /* L(k,:) pattern: all nodes reachable in etree from nz in A(0:k-1,k) */ m_parent[k] = -1; /* parent of k is not yet known */ tags[k] = k; /* mark node k as visited */ m_nonZerosPerCol[k] = 0; /* count of nonzeros in column k of L */ - int kk = P ? P[k] : k; /* kth original, or permuted, column */ - int p2 = Ap[kk+1]; - for (int p = Ap[kk]; p < p2; ++p) + Index kk = P ? P[k] : k; /* kth original, or permuted, column */ + Index p2 = Ap[kk+1]; + for (Index p = Ap[kk]; p < p2; ++p) { /* A (i,k) is nonzero (original or permuted A) */ - int i = Pinv ? Pinv[Ai[p]] : Ai[p]; + Index i = Pinv ? Pinv[Ai[p]] : Ai[p]; if (i < k) { /* follow path from i to root of etree, stop at flagged node */ @@ -234,53 +235,53 @@ void SparseLDLT<MatrixType,Backend>::_symbolic(const MatrixType& a) } /* construct Lp index array from m_nonZerosPerCol column counts */ Lp[0] = 0; - for (int k = 0; k < size; ++k) + for (Index k = 0; k < size; ++k) Lp[k+1] = Lp[k] + m_nonZerosPerCol[k]; m_matrix.resizeNonZeros(Lp[size]); - ei_aligned_stack_delete(int, tags, size); + ei_aligned_stack_delete(Index, tags, size); } template<typename MatrixType, int Backend> bool SparseLDLT<MatrixType,Backend>::_numeric(const MatrixType& a) { assert(a.rows()==a.cols()); - const int size = a.rows(); + const Index size = a.rows(); assert(m_parent.size()==size); assert(m_nonZerosPerCol.size()==size); - const int* Ap = a._outerIndexPtr(); - const int* Ai = a._innerIndexPtr(); + const Index* Ap = a._outerIndexPtr(); + const Index* Ai = a._innerIndexPtr(); const Scalar* Ax = a._valuePtr(); - const int* Lp = m_matrix._outerIndexPtr(); - int* Li = m_matrix._innerIndexPtr(); + const Index* Lp = m_matrix._outerIndexPtr(); + Index* Li = m_matrix._innerIndexPtr(); Scalar* Lx = m_matrix._valuePtr(); m_diag.resize(size); Scalar * y = ei_aligned_stack_new(Scalar, size); - int * pattern = ei_aligned_stack_new(int, size); - int * tags = ei_aligned_stack_new(int, size); + Index * pattern = ei_aligned_stack_new(Index, size); + Index * tags = ei_aligned_stack_new(Index, size); - const int* P = 0; - const int* Pinv = 0; + const Index* P = 0; + const Index* Pinv = 0; bool ok = true; - for (int k = 0; k < size; ++k) + for (Index k = 0; k < size; ++k) { /* compute nonzero pattern of kth row of L, in topological order */ y[k] = 0.0; /* Y(0:k) is now all zero */ - int top = size; /* stack for pattern is empty */ + Index top = size; /* stack for pattern is empty */ tags[k] = k; /* mark node k as visited */ m_nonZerosPerCol[k] = 0; /* count of nonzeros in column k of L */ - int kk = (P) ? (P[k]) : (k); /* kth original, or permuted, column */ - int p2 = Ap[kk+1]; - for (int p = Ap[kk]; p < p2; ++p) + Index kk = (P) ? (P[k]) : (k); /* kth original, or permuted, column */ + Index p2 = Ap[kk+1]; + for (Index p = Ap[kk]; p < p2; ++p) { - int i = Pinv ? Pinv[Ai[p]] : Ai[p]; /* get A(i,k) */ + Index i = Pinv ? Pinv[Ai[p]] : Ai[p]; /* get A(i,k) */ if (i <= k) { y[i] += Ax[p]; /* scatter A(i,k) into Y (sum duplicates) */ - int len; + Index len; for (len = 0; tags[i] != k; i = m_parent[i]) { pattern[len++] = i; /* L(k,i) is nonzero */ @@ -295,11 +296,11 @@ bool SparseLDLT<MatrixType,Backend>::_numeric(const MatrixType& a) y[k] = 0.0; for (; top < size; ++top) { - int i = pattern[top]; /* pattern[top:n-1] is pattern of L(:,k) */ + Index i = pattern[top]; /* pattern[top:n-1] is pattern of L(:,k) */ Scalar yi = y[i]; /* get and clear Y(i) */ y[i] = 0.0; - int p2 = Lp[i] + m_nonZerosPerCol[i]; - int p; + Index p2 = Lp[i] + m_nonZerosPerCol[i]; + Index p; for (p = Lp[i]; p < p2; ++p) y[Li[p]] -= Lx[p] * yi; Scalar l_ki = yi / m_diag[i]; /* the nonzero entry L(k,i) */ @@ -316,8 +317,8 @@ bool SparseLDLT<MatrixType,Backend>::_numeric(const MatrixType& a) } ei_aligned_stack_delete(Scalar, y, size); - ei_aligned_stack_delete(int, pattern, size); - ei_aligned_stack_delete(int, tags, size); + ei_aligned_stack_delete(Index, pattern, size); + ei_aligned_stack_delete(Index, tags, size); return ok; /* success, diagonal of D is all nonzero */ } @@ -327,7 +328,7 @@ template<typename MatrixType, int Backend> template<typename Derived> bool SparseLDLT<MatrixType, Backend>::solveInPlace(MatrixBase<Derived> &b) const { - const int size = m_matrix.rows(); + const Index size = m_matrix.rows(); ei_assert(size==b.rows()); if (!m_succeeded) return false; diff --git a/Eigen/src/Sparse/SparseLLT.h b/Eigen/src/Sparse/SparseLLT.h index a1c10ba13..37c6c3f9a 100644 --- a/Eigen/src/Sparse/SparseLLT.h +++ b/Eigen/src/Sparse/SparseLLT.h @@ -40,6 +40,7 @@ class SparseLLT { protected: typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::Index Index; typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; typedef SparseMatrix<Scalar> CholMatrixType; @@ -127,7 +128,7 @@ template<typename MatrixType, int Backend> void SparseLLT<MatrixType,Backend>::compute(const MatrixType& a) { assert(a.rows()==a.cols()); - const int size = a.rows(); + const Index size = a.rows(); m_matrix.resize(size, size); // allocate a temporary vector for accumulations @@ -137,7 +138,7 @@ void SparseLLT<MatrixType,Backend>::compute(const MatrixType& a) // TODO estimate the number of non zeros m_matrix.setZero(); m_matrix.reserve(a.nonZeros()*2); - for (int j = 0; j < size; ++j) + for (Index j = 0; j < size; ++j) { Scalar x = ei_real(a.coeff(j,j)); @@ -154,7 +155,7 @@ void SparseLLT<MatrixType,Backend>::compute(const MatrixType& a) for (; it; ++it) tempVector.coeffRef(it.index()) = it.value(); } - for (int k=0; k<j+1; ++k) + for (Index k=0; k<j+1; ++k) { typename CholMatrixType::InnerIterator it(m_matrix, k); while (it && it.index()<j) @@ -190,7 +191,7 @@ template<typename MatrixType, int Backend> template<typename Derived> bool SparseLLT<MatrixType, Backend>::solveInPlace(MatrixBase<Derived> &b) const { - const int size = m_matrix.rows(); + const Index size = m_matrix.rows(); ei_assert(size==b.rows()); m_matrix.template triangularView<Lower>().solveInPlace(b); diff --git a/Eigen/src/Sparse/SparseMatrix.h b/Eigen/src/Sparse/SparseMatrix.h index 06cc7a949..fd41d7302 100644 --- a/Eigen/src/Sparse/SparseMatrix.h +++ b/Eigen/src/Sparse/SparseMatrix.h @@ -77,46 +77,46 @@ class SparseMatrix typedef SparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> TransposedSparseMatrix; - int m_outerSize; - int m_innerSize; - int* m_outerIndex; + Index m_outerSize; + Index m_innerSize; + Index* m_outerIndex; CompressedStorage<Scalar> m_data; public: - inline int rows() const { return IsRowMajor ? m_outerSize : m_innerSize; } - inline int cols() const { return IsRowMajor ? m_innerSize : m_outerSize; } + inline Index rows() const { return IsRowMajor ? m_outerSize : m_innerSize; } + inline Index cols() const { return IsRowMajor ? m_innerSize : m_outerSize; } - inline int innerSize() const { return m_innerSize; } - inline int outerSize() const { return m_outerSize; } - inline int innerNonZeros(int j) const { return m_outerIndex[j+1]-m_outerIndex[j]; } + inline Index innerSize() const { return m_innerSize; } + inline Index outerSize() const { return m_outerSize; } + inline Index innerNonZeros(Index j) const { return m_outerIndex[j+1]-m_outerIndex[j]; } inline const Scalar* _valuePtr() const { return &m_data.value(0); } inline Scalar* _valuePtr() { return &m_data.value(0); } - inline const int* _innerIndexPtr() const { return &m_data.index(0); } - inline int* _innerIndexPtr() { return &m_data.index(0); } + inline const Index* _innerIndexPtr() const { return &m_data.index(0); } + inline Index* _innerIndexPtr() { return &m_data.index(0); } - inline const int* _outerIndexPtr() const { return m_outerIndex; } - inline int* _outerIndexPtr() { return m_outerIndex; } + inline const Index* _outerIndexPtr() const { return m_outerIndex; } + inline Index* _outerIndexPtr() { return m_outerIndex; } - inline Scalar coeff(int row, int col) const + inline Scalar coeff(Index row, Index col) const { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; return m_data.atInRange(m_outerIndex[outer], m_outerIndex[outer+1], inner); } - inline Scalar& coeffRef(int row, int col) + inline Scalar& coeffRef(Index row, Index col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; - int start = m_outerIndex[outer]; - int end = m_outerIndex[outer+1]; + Index start = m_outerIndex[outer]; + Index end = m_outerIndex[outer+1]; ei_assert(end>=start && "you probably called coeffRef on a non finalized matrix"); ei_assert(end>start && "coeffRef cannot be called on a zero coefficient"); - const int id = m_data.searchLowerIndex(start,end-1,inner); + const Index id = m_data.searchLowerIndex(start,end-1,inner); ei_assert((id<end) && (m_data.index(id)==inner) && "coeffRef cannot be called on a zero coefficient"); return m_data.value(id); } @@ -129,40 +129,40 @@ class SparseMatrix inline void setZero() { m_data.clear(); - memset(m_outerIndex, 0, (m_outerSize+1)*sizeof(int)); + memset(m_outerIndex, 0, (m_outerSize+1)*sizeof(Index)); } /** \returns the number of non zero coefficients */ - inline int nonZeros() const { return static_cast<int>(m_data.size()); } + inline Index nonZeros() const { return static_cast<Index>(m_data.size()); } /** \deprecated use setZero() and reserve() * Initializes the filling process of \c *this. * \param reserveSize approximate number of nonzeros * Note that the matrix \c *this is zero-ed. */ - EIGEN_DEPRECATED void startFill(int reserveSize = 1000) + EIGEN_DEPRECATED void startFill(Index reserveSize = 1000) { setZero(); m_data.reserve(reserveSize); } /** Preallocates \a reserveSize non zeros */ - inline void reserve(int reserveSize) + inline void reserve(Index reserveSize) { m_data.reserve(reserveSize); } /** \deprecated use insert() */ - EIGEN_DEPRECATED Scalar& fill(int row, int col) + EIGEN_DEPRECATED Scalar& fill(Index row, Index col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; if (m_outerIndex[outer+1]==0) { // we start a new inner vector - int i = outer; + Index i = outer; while (i>=0 && m_outerIndex[i]==0) { m_outerIndex[i] = m_data.size(); @@ -176,7 +176,7 @@ class SparseMatrix } // std::cerr << size_t(m_outerIndex[outer+1]) << " == " << m_data.size() << "\n"; assert(size_t(m_outerIndex[outer+1]) == m_data.size()); - int id = m_outerIndex[outer+1]; + Index id = m_outerIndex[outer+1]; ++m_outerIndex[outer+1]; m_data.append(0, inner); @@ -185,25 +185,25 @@ class SparseMatrix //--- low level purely coherent filling --- - inline Scalar& insertBack(int outer, int inner) + inline Scalar& insertBack(Index outer, Index inner) { ei_assert(size_t(m_outerIndex[outer+1]) == m_data.size() && "wrong sorted insertion"); ei_assert( (m_outerIndex[outer+1]-m_outerIndex[outer]==0 || m_data.index(m_data.size()-1)<inner) && "wrong sorted insertion"); - int id = m_outerIndex[outer+1]; + Index id = m_outerIndex[outer+1]; ++m_outerIndex[outer+1]; m_data.append(0, inner); return m_data.value(id); } - inline Scalar& insertBackNoCheck(int outer, int inner) + inline Scalar& insertBackNoCheck(Index outer, Index inner) { - int id = m_outerIndex[outer+1]; + Index id = m_outerIndex[outer+1]; ++m_outerIndex[outer+1]; m_data.append(0, inner); return m_data.value(id); } - inline void startVec(int outer) + inline void startVec(Index outer) { ei_assert(m_outerIndex[outer]==int(m_data.size()) && "you must call startVec on each inner vec"); ei_assert(m_outerIndex[outer+1]==0 && "you must call startVec on each inner vec"); @@ -215,7 +215,7 @@ class SparseMatrix /** \deprecated use insert() * Like fill() but with random inner coordinates. */ - EIGEN_DEPRECATED Scalar& fillrand(int row, int col) + EIGEN_DEPRECATED Scalar& fillrand(Index row, Index col) { return insert(row,col); } @@ -228,18 +228,18 @@ class SparseMatrix * * After an insertion session, you should call the finalize() function. */ - EIGEN_DONT_INLINE Scalar& insert(int row, int col) + EIGEN_DONT_INLINE Scalar& insert(Index row, Index col) { - const int outer = IsRowMajor ? row : col; - const int inner = IsRowMajor ? col : row; + const Index outer = IsRowMajor ? row : col; + const Index inner = IsRowMajor ? col : row; - int previousOuter = outer; + Index previousOuter = outer; if (m_outerIndex[outer+1]==0) { // we start a new inner vector while (previousOuter>=0 && m_outerIndex[previousOuter]==0) { - m_outerIndex[previousOuter] = static_cast<int>(m_data.size()); + m_outerIndex[previousOuter] = static_cast<Index>(m_data.size()); --previousOuter; } m_outerIndex[outer+1] = m_outerIndex[outer]; @@ -285,9 +285,9 @@ class SparseMatrix { // oops wrong guess. // let's correct the outer offsets - for (int k=0; k<=(outer+1); ++k) + for (Index k=0; k<=(outer+1); ++k) m_outerIndex[k] = 0; - int k=outer+1; + Index k=outer+1; while(m_outerIndex[k]==0) m_outerIndex[k++] = 1; while (k<=m_outerSize && m_outerIndex[k]!=0) @@ -306,13 +306,13 @@ class SparseMatrix { // we are not inserting into the last inner vec // update outer indices: - int j = outer+2; + Index j = outer+2; while (j<=m_outerSize && m_outerIndex[j]!=0) m_outerIndex[j++]++; --j; // shift data of last vecs: - int k = m_outerIndex[j]-1; - while (k>=int(id)) + Index k = m_outerIndex[j]-1; + while (k>=Index(id)) { m_data.index(k) = m_data.index(k-1); m_data.value(k) = m_data.value(k-1); @@ -338,8 +338,8 @@ class SparseMatrix */ inline void finalize() { - int size = static_cast<int>(m_data.size()); - int i = m_outerSize; + Index size = static_cast<Index>(m_data.size()); + Index i = m_outerSize; // find the last filled column while (i>=0 && m_outerIndex[i]==0) --i; @@ -353,13 +353,13 @@ class SparseMatrix void prune(Scalar reference, RealScalar epsilon = NumTraits<RealScalar>::dummy_precision()) { - int k = 0; - for (int j=0; j<m_outerSize; ++j) + Index k = 0; + for (Index j=0; j<m_outerSize; ++j) { - int previousStart = m_outerIndex[j]; + Index previousStart = m_outerIndex[j]; m_outerIndex[j] = k; - int end = m_outerIndex[j+1]; - for (int i=previousStart; i<end; ++i) + Index end = m_outerIndex[j+1]; + for (Index i=previousStart; i<end; ++i) { if (!ei_isMuchSmallerThan(m_data.value(i), reference, epsilon)) { @@ -374,22 +374,22 @@ class SparseMatrix } /** 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(int rows, int cols) + void resize(Index rows, Index cols) { - const int outerSize = IsRowMajor ? rows : cols; + const Index outerSize = IsRowMajor ? rows : cols; m_innerSize = IsRowMajor ? cols : rows; m_data.clear(); if (m_outerSize != outerSize || m_outerSize==0) { delete[] m_outerIndex; - m_outerIndex = new int [outerSize+1]; + m_outerIndex = new Index [outerSize+1]; m_outerSize = outerSize; } - memset(m_outerIndex, 0, (m_outerSize+1)*sizeof(int)); + memset(m_outerIndex, 0, (m_outerSize+1)*sizeof(Index)); } - void resizeNonZeros(int size) + void resizeNonZeros(Index size) { m_data.resize(size); } @@ -400,7 +400,7 @@ class SparseMatrix resize(0, 0); } - inline SparseMatrix(int rows, int cols) + inline SparseMatrix(Index rows, Index cols) : m_outerSize(0), m_innerSize(0), m_outerIndex(0) { resize(rows, cols); @@ -438,7 +438,7 @@ class SparseMatrix else { resize(other.rows(), other.cols()); - memcpy(m_outerIndex, other.m_outerIndex, (m_outerSize+1)*sizeof(int)); + memcpy(m_outerIndex, other.m_outerIndex, (m_outerSize+1)*sizeof(Index)); m_data = other.m_data; } return *this; @@ -465,19 +465,19 @@ class SparseMatrix OtherCopy otherCopy(other.derived()); resize(other.rows(), other.cols()); - Eigen::Map<VectorXi>(m_outerIndex,outerSize()).setZero(); + Eigen::Map<Matrix<Index, Dynamic, 1> > (m_outerIndex,outerSize()).setZero(); // pass 1 // FIXME the above copy could be merged with that pass - for (int j=0; j<otherCopy.outerSize(); ++j) + for (Index j=0; j<otherCopy.outerSize(); ++j) for (typename _OtherCopy::InnerIterator it(otherCopy, j); it; ++it) ++m_outerIndex[it.index()]; // prefix sum - int count = 0; + Index count = 0; VectorXi positions(outerSize()); - for (int j=0; j<outerSize(); ++j) + for (Index j=0; j<outerSize(); ++j) { - int tmp = m_outerIndex[j]; + Index tmp = m_outerIndex[j]; m_outerIndex[j] = count; positions[j] = count; count += tmp; @@ -486,11 +486,11 @@ class SparseMatrix // alloc m_data.resize(count); // pass 2 - for (int j=0; j<otherCopy.outerSize(); ++j) + for (Index j=0; j<otherCopy.outerSize(); ++j) { for (typename _OtherCopy::InnerIterator it(otherCopy, j); it; ++it) { - int pos = positions[it.index()]++; + Index pos = positions[it.index()]++; m_data.index(pos) = j; m_data.value(pos) = it.value(); } @@ -508,14 +508,14 @@ class SparseMatrix { EIGEN_DBG_SPARSE( s << "Nonzero entries:\n"; - for (int i=0; i<m.nonZeros(); ++i) + for (Index i=0; i<m.nonZeros(); ++i) { s << "(" << m.m_data.value(i) << "," << m.m_data.index(i) << ") "; } s << std::endl; s << std::endl; s << "Column pointers:\n"; - for (int i=0; i<m.outerSize(); ++i) + for (Index i=0; i<m.outerSize(); ++i) { s << m.m_outerIndex[i] << " "; } @@ -540,12 +540,12 @@ template<typename Scalar, int _Options> class SparseMatrix<Scalar,_Options>::InnerIterator { public: - InnerIterator(const SparseMatrix& mat, int outer) + InnerIterator(const SparseMatrix& mat, Index outer) : m_matrix(mat), m_outer(outer), m_id(mat.m_outerIndex[outer]), m_start(m_id), m_end(mat.m_outerIndex[outer+1]) {} template<unsigned int Added, unsigned int Removed> - InnerIterator(const Flagged<SparseMatrix,Added,Removed>& mat, int outer) + InnerIterator(const Flagged<SparseMatrix,Added,Removed>& mat, Index outer) : m_matrix(mat._expression()), m_outer(outer), m_id(m_matrix.m_outerIndex[outer]), m_start(m_id), m_end(m_matrix.m_outerIndex[outer+1]) {} @@ -555,19 +555,19 @@ class SparseMatrix<Scalar,_Options>::InnerIterator inline Scalar value() const { return m_matrix.m_data.value(m_id); } inline Scalar& valueRef() { return const_cast<Scalar&>(m_matrix.m_data.value(m_id)); } - inline int index() const { return m_matrix.m_data.index(m_id); } - inline int outer() const { return m_outer; } - inline int row() const { return IsRowMajor ? m_outer : index(); } - inline int col() const { return IsRowMajor ? index() : m_outer; } + inline Index index() const { return m_matrix.m_data.index(m_id); } + inline Index outer() const { return m_outer; } + inline Index row() const { return IsRowMajor ? m_outer : index(); } + inline Index col() const { return IsRowMajor ? index() : m_outer; } inline operator bool() const { return (m_id < m_end) && (m_id>=m_start); } protected: const SparseMatrix& 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_SPARSEMATRIX_H diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h index 65fa19a79..a4326821d 100644 --- a/Eigen/src/Sparse/SparseMatrixBase.h +++ b/Eigen/src/Sparse/SparseMatrixBase.h @@ -42,6 +42,9 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> typedef typename ei_traits<Derived>::Scalar Scalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar; + typedef typename ei_traits<Derived>::StorageKind StorageKind; + typedef typename ei_index<StorageKind>::type Index; + typedef SparseMatrixBase StorageBaseType; enum { @@ -145,15 +148,15 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> #endif // not EIGEN_PARSED_BY_DOXYGEN /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ - inline int rows() const { return derived().rows(); } + inline Index rows() const { return derived().rows(); } /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ - inline int cols() const { return derived().cols(); } + 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 { return rows() * cols(); } + 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 { return derived().nonZeros(); } + inline Index nonZeros() const { return derived().nonZeros(); } /** \returns true if either the number of rows or the number of columns is equal to 1. * In other words, this function returns * \code rows()==1 || cols()==1 \endcode @@ -161,10 +164,10 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> inline bool isVector() const { return rows()==1 || cols()==1; } /** \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 { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); } + 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 { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); } + Index innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); } bool isRValue() const { return m_isRValue; } Derived& markAsRValue() { m_isRValue = true; return derived(); } @@ -193,13 +196,13 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) }; - const int outerSize = other.outerSize(); + const Index outerSize = other.outerSize(); //typedef typename ei_meta_if<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::ret TempType; // thanks to shallow copies, we always eval to a tempary Derived temp(other.rows(), other.cols()); temp.reserve(std::max(this->rows(),this->cols())*2); - for (int j=0; j<outerSize; ++j) + for (Index j=0; j<outerSize; ++j) { temp.startVec(j); for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it) @@ -222,14 +225,14 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> // std::cout << Flags << " " << OtherDerived::Flags << "\n"; const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); // std::cout << "eval transpose = " << transpose << "\n"; - const int outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols(); + const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols(); if ((!transpose) && other.isRValue()) { // eval without temporary derived().resize(other.rows(), other.cols()); derived().setZero(); derived().reserve(std::max(this->rows(),this->cols())*2); - for (int j=0; j<outerSize; ++j) + for (Index j=0; j<outerSize; ++j) { derived().startVec(j); for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it) @@ -258,9 +261,9 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> { if (Flags&RowMajorBit) { - for (int row=0; row<m.outerSize(); ++row) + for (Index row=0; row<m.outerSize(); ++row) { - int col = 0; + Index col = 0; for (typename Derived::InnerIterator it(m.derived(), row); it; ++it) { for ( ; col<it.index(); ++col) @@ -276,7 +279,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> else { if (m.cols() == 1) { - int row = 0; + Index row = 0; for (typename Derived::InnerIterator it(m.derived(), 0); it; ++it) { for ( ; row<it.index(); ++row) @@ -405,20 +408,20 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> const AdjointReturnType adjoint() const { return transpose(); } // sub-vector - SparseInnerVectorSet<Derived,1> row(int i); - const SparseInnerVectorSet<Derived,1> row(int i) const; - SparseInnerVectorSet<Derived,1> col(int j); - const SparseInnerVectorSet<Derived,1> col(int j) const; - SparseInnerVectorSet<Derived,1> innerVector(int outer); - const SparseInnerVectorSet<Derived,1> innerVector(int outer) const; + SparseInnerVectorSet<Derived,1> row(Index i); + const SparseInnerVectorSet<Derived,1> row(Index i) const; + SparseInnerVectorSet<Derived,1> col(Index j); + const SparseInnerVectorSet<Derived,1> col(Index j) const; + SparseInnerVectorSet<Derived,1> innerVector(Index outer); + const SparseInnerVectorSet<Derived,1> innerVector(Index outer) const; // set of sub-vectors - SparseInnerVectorSet<Derived,Dynamic> subrows(int start, int size); - const SparseInnerVectorSet<Derived,Dynamic> subrows(int start, int size) const; - SparseInnerVectorSet<Derived,Dynamic> subcols(int start, int size); - const SparseInnerVectorSet<Derived,Dynamic> subcols(int start, int size) const; - SparseInnerVectorSet<Derived,Dynamic> innerVectors(int outerStart, int outerSize); - const SparseInnerVectorSet<Derived,Dynamic> innerVectors(int outerStart, int outerSize) const; + SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index size); + const SparseInnerVectorSet<Derived,Dynamic> subrows(Index start, Index size) const; + SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index size); + const SparseInnerVectorSet<Derived,Dynamic> subcols(Index start, Index size) const; + SparseInnerVectorSet<Derived,Dynamic> innerVectors(Index outerStart, Index outerSize); + const SparseInnerVectorSet<Derived,Dynamic> innerVectors(Index outerStart, Index outerSize) const; // typename BlockReturnType<Derived>::Type block(int startRow, int startCol, int blockRows, int blockCols); // const typename BlockReturnType<Derived>::Type @@ -493,7 +496,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> void evalTo(MatrixBase<DenseDerived>& dst) const { dst.setZero(); - for (int j=0; j<outerSize(); ++j) + for (Index j=0; j<outerSize(); ++j) for (typename Derived::InnerIterator i(derived(),j); i; ++i) dst.coeffRef(i.row(),i.col()) = i.value(); } diff --git a/Eigen/src/Sparse/SparseProduct.h b/Eigen/src/Sparse/SparseProduct.h index 078ac5f48..fb53902f4 100644 --- a/Eigen/src/Sparse/SparseProduct.h +++ b/Eigen/src/Sparse/SparseProduct.h @@ -126,8 +126,8 @@ class SparseProduct : ei_no_assignment_operator, EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) } - EIGEN_STRONG_INLINE int rows() const { return m_lhs.rows(); } - EIGEN_STRONG_INLINE int cols() const { return m_rhs.cols(); } + EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); } + EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); } EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; } EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; } @@ -140,16 +140,17 @@ class SparseProduct : ei_no_assignment_operator, template<typename Lhs, typename Rhs, typename ResultType> static void ei_sparse_product_impl2(const Lhs& lhs, const Rhs& rhs, ResultType& res) { - typedef typename ei_traits<typename ei_cleantype<Lhs>::type>::Scalar Scalar; + typedef typename ei_cleantype<Lhs>::type::Scalar Scalar; + typedef typename ei_cleantype<Lhs>::type::Index Index; // make sure to call innerSize/outerSize since we fake the storage order. - int rows = lhs.innerSize(); - int cols = rhs.outerSize(); + Index rows = lhs.innerSize(); + Index cols = rhs.outerSize(); ei_assert(lhs.outerSize() == rhs.innerSize()); std::vector<bool> mask(rows,false); Matrix<Scalar,Dynamic,1> values(rows); - Matrix<int,Dynamic,1> indices(rows); + Matrix<Index,Dynamic,1> indices(rows); // estimate the number of non zero entries float ratioLhs = float(lhs.nonZeros())/(float(lhs.rows())*float(lhs.cols())); @@ -160,20 +161,20 @@ static void ei_sparse_product_impl2(const Lhs& lhs, const Rhs& rhs, ResultType& // int t = (rows*100)/139; res.resize(rows, cols); - res.reserve(int(ratioRes*rows*cols)); + res.reserve(Index(ratioRes*rows*cols)); // we compute each column of the result, one after the other - for (int j=0; j<cols; ++j) + for (Index j=0; j<cols; ++j) { res.startVec(j); - int nnz = 0; + Index nnz = 0; for (typename Rhs::InnerIterator rhsIt(rhs, j); rhsIt; ++rhsIt) { Scalar y = rhsIt.value(); - int k = rhsIt.index(); + Index k = rhsIt.index(); for (typename Lhs::InnerIterator lhsIt(lhs, k); lhsIt; ++lhsIt) { - int i = lhsIt.index(); + Index i = lhsIt.index(); Scalar x = lhsIt.value(); if(!mask[i]) { @@ -225,11 +226,12 @@ static void ei_sparse_product_impl(const Lhs& lhs, const Rhs& rhs, ResultType& r { // return ei_sparse_product_impl2(lhs,rhs,res); - typedef typename ei_traits<typename ei_cleantype<Lhs>::type>::Scalar Scalar; + typedef typename ei_cleantype<Lhs>::type::Scalar Scalar; + typedef typename ei_cleantype<Lhs>::type::Index Index; // make sure to call innerSize/outerSize since we fake the storage order. - int rows = lhs.innerSize(); - int cols = rhs.outerSize(); + Index rows = lhs.innerSize(); + Index cols = rhs.outerSize(); //int size = lhs.outerSize(); ei_assert(lhs.outerSize() == rhs.innerSize()); @@ -242,8 +244,8 @@ static void ei_sparse_product_impl(const Lhs& lhs, const Rhs& rhs, ResultType& r float ratioRes = std::min(ratioLhs * avgNnzPerRhsColumn, 1.f); res.resize(rows, cols); - res.reserve(int(ratioRes*rows*cols)); - for (int j=0; j<cols; ++j) + res.reserve(Index(ratioRes*rows*cols)); + for (Index j=0; j<cols; ++j) { // let's do a more accurate determination of the nnz ratio for the current column j of res //float ratioColRes = std::min(ratioLhs * rhs.innerNonZeros(j), 1.f); @@ -514,7 +516,7 @@ class SparseTimeDenseProduct typedef typename ei_cleantype<Rhs>::type _Rhs; typedef typename _Lhs::InnerIterator LhsInnerIterator; enum { LhsIsRowMajor = (_Lhs::Flags&RowMajorBit)==RowMajorBit }; - for(int j=0; j<m_lhs.outerSize(); ++j) + for(Index j=0; j<m_lhs.outerSize(); ++j) { typename Rhs::Scalar rhs_j = alpha * m_rhs.coeff(j,0); Block<Dest,1,Dest::ColsAtCompileTime> dest_j(dest.row(LhsIsRowMajor ? j : 0)); @@ -555,7 +557,7 @@ class DenseTimeSparseProduct typedef typename ei_cleantype<Rhs>::type _Rhs; typedef typename _Rhs::InnerIterator RhsInnerIterator; enum { RhsIsRowMajor = (_Rhs::Flags&RowMajorBit)==RowMajorBit }; - for(int j=0; j<m_rhs.outerSize(); ++j) + for(Index j=0; j<m_rhs.outerSize(); ++j) for(RhsInnerIterator i(m_rhs,j); i; ++i) dest.col(RhsIsRowMajor ? i.index() : j) += (alpha*i.value()) * m_lhs.col(RhsIsRowMajor ? j : i.index()); } diff --git a/Eigen/src/Sparse/SparseRedux.h b/Eigen/src/Sparse/SparseRedux.h index a243be6ab..ea2ce1870 100644 --- a/Eigen/src/Sparse/SparseRedux.h +++ b/Eigen/src/Sparse/SparseRedux.h @@ -31,7 +31,7 @@ SparseMatrixBase<Derived>::sum() const { ei_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); Scalar res = 0; - for (int j=0; j<outerSize(); ++j) + for (Index j=0; j<outerSize(); ++j) for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter) res += iter.value(); return res; diff --git a/Eigen/src/Sparse/SparseSelfAdjointView.h b/Eigen/src/Sparse/SparseSelfAdjointView.h index d47705337..703ca64bc 100644 --- a/Eigen/src/Sparse/SparseSelfAdjointView.h +++ b/Eigen/src/Sparse/SparseSelfAdjointView.h @@ -49,7 +49,8 @@ template<typename MatrixType, unsigned int UpLo> class SparseSelfAdjointView { public: - typedef typename ei_traits<MatrixType>::Scalar Scalar; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::Index Index; inline SparseSelfAdjointView(const MatrixType& matrix) : m_matrix(matrix) { @@ -57,8 +58,8 @@ template<typename MatrixType, unsigned int UpLo> class SparseSelfAdjointView ei_assert(rows()==cols() && "SelfAdjointView is only for squared matrices"); } - inline int rows() const { return m_matrix.rows(); } - inline int cols() const { return m_matrix.cols(); } + inline Index rows() const { return m_matrix.rows(); } + inline Index cols() const { return m_matrix.cols(); } /** \internal \returns a reference to the nested matrix */ const MatrixType& matrix() const { return m_matrix; } @@ -173,7 +174,7 @@ class SparseSelfAdjointTimeDenseProduct || ( (UpLo&Lower) && LhsIsRowMajor), ProcessSecondHalf = !ProcessFirstHalf }; - for (int j=0; j<m_lhs.outerSize(); ++j) + for (Index j=0; j<m_lhs.outerSize(); ++j) { LhsInnerIterator i(m_lhs,j); if (ProcessSecondHalf && i && (i.index()==j)) @@ -184,8 +185,8 @@ class SparseSelfAdjointTimeDenseProduct Block<Dest,1,Dest::ColsAtCompileTime> dest_j(dest.row(LhsIsRowMajor ? j : 0)); for(; (ProcessFirstHalf ? i && i.index() < j : i) ; ++i) { - int a = LhsIsRowMajor ? j : i.index(); - int b = LhsIsRowMajor ? i.index() : j; + Index a = LhsIsRowMajor ? j : i.index(); + Index b = LhsIsRowMajor ? i.index() : j; typename Lhs::Scalar v = i.value(); dest.row(a) += (v) * m_rhs.row(b); dest.row(b) += ei_conj(v) * m_rhs.row(a); diff --git a/Eigen/src/Sparse/SparseTranspose.h b/Eigen/src/Sparse/SparseTranspose.h index b8c38617a..a94f5ae7c 100644 --- a/Eigen/src/Sparse/SparseTranspose.h +++ b/Eigen/src/Sparse/SparseTranspose.h @@ -35,19 +35,19 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Sparse> class InnerIterator; class ReverseInnerIterator; - inline int nonZeros() const { return derived().nestedExpression().nonZeros(); } + inline Index nonZeros() const { return derived().nestedExpression().nonZeros(); } // FIXME should be keep them ? - inline Scalar& coeffRef(int row, int col) + inline Scalar& coeffRef(Index row, Index col) { return const_cast_derived().nestedExpression().coeffRef(col, row); } - inline const Scalar coeff(int row, int col) const + inline const Scalar coeff(Index row, Index col) const { return derived().nestedExpression().coeff(col, row); } - inline const Scalar coeff(int index) const + inline const Scalar coeff(Index index) const { return derived().nestedExpression().coeff(index); } - inline Scalar& coeffRef(int index) + inline Scalar& coeffRef(Index index) { return const_cast_derived().nestedExpression().coeffRef(index); } }; @@ -56,11 +56,11 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::InnerItera typedef typename MatrixType::InnerIterator Base; public: - EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, int outer) + EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, Index outer) : Base(trans.derived().nestedExpression(), outer) {} - inline int row() const { return Base::col(); } - inline int col() const { return Base::row(); } + inline Index row() const { return Base::col(); } + inline Index col() const { return Base::row(); } }; template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::ReverseInnerIterator : public MatrixType::ReverseInnerIterator @@ -68,11 +68,11 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::ReverseInn typedef typename MatrixType::ReverseInnerIterator Base; public: - EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, int outer) + EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, Index outer) : Base(xpr.derived().nestedExpression(), outer) {} - inline int row() const { return Base::col(); } - inline int col() const { return Base::row(); } + inline Index row() const { return Base::col(); } + inline Index col() const { return Base::row(); } }; #endif // EIGEN_SPARSETRANSPOSE_H diff --git a/Eigen/src/Sparse/SparseTriangularView.h b/Eigen/src/Sparse/SparseTriangularView.h index e713220b9..2588c3698 100644 --- a/Eigen/src/Sparse/SparseTriangularView.h +++ b/Eigen/src/Sparse/SparseTriangularView.h @@ -38,11 +38,12 @@ template<typename MatrixType, int Mode> class SparseTriangularView public: class InnerIterator; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::Index Index; - inline int rows() { return m_matrix.rows(); } - inline int cols() { return m_matrix.cols(); } + inline Index rows() { return m_matrix.rows(); } + inline Index cols() { return m_matrix.cols(); } - typedef typename ei_traits<MatrixType>::Scalar Scalar; typedef typename ei_meta_if<ei_must_nest_by_value<MatrixType>::ret, MatrixType, const MatrixType&>::ret MatrixTypeNested; @@ -68,15 +69,15 @@ class SparseTriangularView<MatrixType,Mode>::InnerIterator : public MatrixType:: typedef typename MatrixType::InnerIterator Base; public: - EIGEN_STRONG_INLINE InnerIterator(const SparseTriangularView& view, int outer) + EIGEN_STRONG_INLINE InnerIterator(const SparseTriangularView& view, Index outer) : Base(view.nestedExpression(), outer) { if(SkipFirst) while((*this) && this->index()<outer) ++(*this); } - inline int row() const { return Base::row(); } - inline int col() const { return Base::col(); } + inline Index row() const { return Base::row(); } + inline Index col() const { return Base::col(); } EIGEN_STRONG_INLINE operator bool() const { diff --git a/Eigen/src/Sparse/SparseUtil.h b/Eigen/src/Sparse/SparseUtil.h index 782690b26..7f100401a 100644 --- a/Eigen/src/Sparse/SparseUtil.h +++ b/Eigen/src/Sparse/SparseUtil.h @@ -57,16 +57,18 @@ EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \ EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) #define _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \ -typedef BaseClass Base; \ -typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ -typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ -typedef typename Eigen::ei_nested<Derived>::type Nested; \ -enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ - ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ - Flags = Eigen::ei_traits<Derived>::Flags, \ - CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \ - SizeAtCompileTime = Base::SizeAtCompileTime, \ - IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; + typedef BaseClass Base; \ + typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ + typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ + typedef typename Eigen::ei_nested<Derived>::type Nested; \ + typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \ + typedef typename Eigen::ei_index<StorageKind>::type Index; \ + enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ + ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ + Flags = Eigen::ei_traits<Derived>::Flags, \ + CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \ + SizeAtCompileTime = Base::SizeAtCompileTime, \ + IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; #define EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived) \ _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>) @@ -76,6 +78,8 @@ enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \ typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \ typedef typename Eigen::ei_nested<Derived>::type Nested; \ + typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \ + typedef typename Eigen::ei_index<StorageKind>::type Index; \ enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \ Flags = Eigen::ei_traits<Derived>::Flags, \ @@ -88,6 +92,12 @@ enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \ #define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \ _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>) +template<> +struct ei_index<Sparse> +{ typedef EIGEN_DEFAULT_SPARSE_INDEX_TYPE type; }; + +typedef typename ei_index<Sparse>::type SparseIndex; + enum SparseBackend { DefaultBackend, Taucs, diff --git a/Eigen/src/Sparse/SparseVector.h b/Eigen/src/Sparse/SparseVector.h index 6806ab288..4013b4de5 100644 --- a/Eigen/src/Sparse/SparseVector.h +++ b/Eigen/src/Sparse/SparseVector.h @@ -70,33 +70,33 @@ class SparseVector enum { IsColVector = ei_traits<SparseVector>::IsColVector }; CompressedStorage<Scalar> m_data; - int m_size; + Index m_size; CompressedStorage<Scalar>& _data() { return m_data; } CompressedStorage<Scalar>& _data() const { return m_data; } public: - EIGEN_STRONG_INLINE int rows() const { return IsColVector ? m_size : 1; } - EIGEN_STRONG_INLINE int cols() const { return IsColVector ? 1 : m_size; } - EIGEN_STRONG_INLINE int innerSize() const { return m_size; } - EIGEN_STRONG_INLINE int outerSize() const { return 1; } - EIGEN_STRONG_INLINE int innerNonZeros(int j) const { ei_assert(j==0); return m_size; } + EIGEN_STRONG_INLINE Index rows() const { return IsColVector ? m_size : 1; } + EIGEN_STRONG_INLINE Index cols() const { return IsColVector ? 1 : m_size; } + EIGEN_STRONG_INLINE Index innerSize() const { return m_size; } + EIGEN_STRONG_INLINE Index outerSize() const { return 1; } + EIGEN_STRONG_INLINE Index innerNonZeros(Index j) const { ei_assert(j==0); return m_size; } EIGEN_STRONG_INLINE const Scalar* _valuePtr() const { return &m_data.value(0); } EIGEN_STRONG_INLINE Scalar* _valuePtr() { return &m_data.value(0); } - EIGEN_STRONG_INLINE const int* _innerIndexPtr() const { return &m_data.index(0); } - EIGEN_STRONG_INLINE int* _innerIndexPtr() { return &m_data.index(0); } + EIGEN_STRONG_INLINE const Index* _innerIndexPtr() const { return &m_data.index(0); } + EIGEN_STRONG_INLINE Index* _innerIndexPtr() { return &m_data.index(0); } - inline Scalar coeff(int row, int col) const + inline Scalar coeff(Index row, Index col) const { ei_assert((IsColVector ? col : row)==0); return coeff(IsColVector ? row : col); } - inline Scalar coeff(int i) const { return m_data.at(i); } + inline Scalar coeff(Index i) const { return m_data.at(i); } - inline Scalar& coeffRef(int row, int col) + inline Scalar& coeffRef(Index row, Index col) { ei_assert((IsColVector ? col : row)==0); return coeff(IsColVector ? row : col); @@ -108,7 +108,7 @@ class SparseVector * * This insertion might be very costly if the number of nonzeros above \a i is large. */ - inline Scalar& coeffRef(int i) + inline Scalar& coeffRef(Index i) { return m_data.atWithInsertion(i); } @@ -120,33 +120,33 @@ class SparseVector inline void setZero() { m_data.clear(); } /** \returns the number of non zero coefficients */ - inline int nonZeros() const { return static_cast<int>(m_data.size()); } + inline Index nonZeros() const { return static_cast<Index>(m_data.size()); } - inline void startVec(int outer) + inline void startVec(Index outer) { ei_assert(outer==0); } - inline Scalar& insertBack(int outer, int inner) + inline Scalar& insertBack(Index outer, Index inner) { ei_assert(outer==0); return insertBack(inner); } - inline Scalar& insertBack(int i) + inline Scalar& insertBack(Index i) { m_data.append(0, i); return m_data.value(m_data.size()-1); } - inline Scalar& insert(int outer, int inner) + inline Scalar& insert(Index outer, Index inner) { ei_assert(outer==0); return insert(inner); } - Scalar& insert(int i) + Scalar& insert(Index i) { - int startId = 0; - int id = m_data.size() - 1; + Index startId = 0; + Index id = m_data.size() - 1; // TODO smart realloc m_data.resize(id+2,1); @@ -163,38 +163,38 @@ class SparseVector /** */ - inline void reserve(int reserveSize) { m_data.reserve(reserveSize); } + inline void reserve(Index reserveSize) { m_data.reserve(reserveSize); } /** \deprecated use setZero() and reserve() */ - EIGEN_DEPRECATED void startFill(int reserve) + EIGEN_DEPRECATED void startFill(Index reserve) { setZero(); m_data.reserve(reserve); } - /** \deprecated use insertBack(int,int) */ - EIGEN_DEPRECATED Scalar& fill(int r, int c) + /** \deprecated use insertBack(Index,Index) */ + EIGEN_DEPRECATED Scalar& fill(Index r, Index c) { ei_assert(r==0 || c==0); return fill(IsColVector ? r : c); } - /** \deprecated use insertBack(int) */ - EIGEN_DEPRECATED Scalar& fill(int i) + /** \deprecated use insertBack(Index) */ + EIGEN_DEPRECATED Scalar& fill(Index i) { m_data.append(0, i); return m_data.value(m_data.size()-1); } - /** \deprecated use insert(int,int) */ - EIGEN_DEPRECATED Scalar& fillrand(int r, int c) + /** \deprecated use insert(Index,Index) */ + EIGEN_DEPRECATED Scalar& fillrand(Index r, Index c) { ei_assert(r==0 || c==0); return fillrand(IsColVector ? r : c); } - /** \deprecated use insert(int) */ - EIGEN_DEPRECATED Scalar& fillrand(int i) + /** \deprecated use insert(Index) */ + EIGEN_DEPRECATED Scalar& fillrand(Index i) { return insert(i); } @@ -208,25 +208,25 @@ class SparseVector m_data.prune(reference,epsilon); } - void resize(int rows, int cols) + void resize(Index rows, Index cols) { ei_assert(rows==1 || cols==1); resize(IsColVector ? rows : cols); } - void resize(int newSize) + void resize(Index newSize) { m_size = newSize; m_data.clear(); } - void resizeNonZeros(int size) { m_data.resize(size); } + void resizeNonZeros(Index size) { m_data.resize(size); } inline SparseVector() : m_size(0) { resize(0); } - inline SparseVector(int size) : m_size(0) { resize(size); } + inline SparseVector(Index size) : m_size(0) { resize(size); } - inline SparseVector(int rows, int cols) : m_size(0) { resize(rows,cols); } + inline SparseVector(Index rows, Index cols) : m_size(0) { resize(rows,cols); } template<typename OtherDerived> inline SparseVector(const MatrixBase<OtherDerived>& other) @@ -329,7 +329,7 @@ class SparseVector friend std::ostream & operator << (std::ostream & s, const SparseVector& m) { - for (unsigned int i=0; i<m.nonZeros(); ++i) + for (Index i=0; i<m.nonZeros(); ++i) s << "(" << m.m_data.value(i) << "," << m.m_data.index(i) << ") "; s << std::endl; return s; @@ -368,18 +368,18 @@ template<typename Scalar, int _Options> class SparseVector<Scalar,_Options>::InnerIterator { public: - InnerIterator(const SparseVector& vec, int outer=0) - : m_data(vec.m_data), m_id(0), m_end(static_cast<int>(m_data.size())) + InnerIterator(const SparseVector& vec, Index outer=0) + : m_data(vec.m_data), m_id(0), m_end(static_cast<Index>(m_data.size())) { ei_assert(outer==0); } InnerIterator(const CompressedStorage<Scalar>& data) - : m_data(data), m_id(0), m_end(static_cast<int>(m_data.size())) + : m_data(data), m_id(0), m_end(static_cast<Index>(m_data.size())) {} template<unsigned int Added, unsigned int Removed> - InnerIterator(const Flagged<SparseVector,Added,Removed>& vec, int ) + InnerIterator(const Flagged<SparseVector,Added,Removed>& vec, Index ) : m_data(vec._expression().m_data), m_id(0), m_end(m_data.size()) {} @@ -388,16 +388,16 @@ class SparseVector<Scalar,_Options>::InnerIterator inline Scalar value() const { return m_data.value(m_id); } inline Scalar& valueRef() { return const_cast<Scalar&>(m_data.value(m_id)); } - inline int index() const { return m_data.index(m_id); } - inline int row() const { return IsColVector ? index() : 0; } - inline int col() const { return IsColVector ? 0 : index(); } + inline Index index() const { return m_data.index(m_id); } + inline Index row() const { return IsColVector ? index() : 0; } + inline Index col() const { return IsColVector ? 0 : index(); } inline operator bool() const { return (m_id < m_end); } protected: const CompressedStorage<Scalar>& m_data; - int m_id; - const int m_end; + Index m_id; + const Index m_end; }; #endif // EIGEN_SPARSEVECTOR_H |