diff options
author | Gael Guennebaud <g.gael@free.fr> | 2014-07-17 13:34:26 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2014-07-17 13:34:26 +0200 |
commit | 77af4cc3c9fac237d8fcf32379137b14c203033f (patch) | |
tree | 14166e356609534982653c6daf63be44ea7095bf /Eigen/src | |
parent | 5e72151ca537c84afa03b49e614667c51e40ad54 (diff) |
bug #397: add a warning for 64 to 32 bit integer conversion and fix many of these warning by splitting the index type used for storage and as size/coefficient indexes in PermutationMatrix and Transpositions.
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/Cholesky/LDLT.h | 8 | ||||
-rw-r--r-- | Eigen/src/Core/PermutationMatrix.h | 60 | ||||
-rw-r--r-- | Eigen/src/Core/Transpositions.h | 77 | ||||
-rw-r--r-- | Eigen/src/LU/PartialPivLU.h | 6 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseCwiseBinaryOp.h | 11 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseDenseProduct.h | 6 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseDiagonalProduct.h | 14 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseMatrix.h | 6 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseMatrixBase.h | 18 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseSelfAdjointView.h | 2 |
10 files changed, 114 insertions, 94 deletions
diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index 6881e1ca8..aa9784e54 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -246,6 +246,7 @@ template<> struct ldlt_inplace<Lower> typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; typedef typename MatrixType::Index Index; + typedef typename TranspositionType::StorageIndexType IndexType; eigen_assert(mat.rows()==mat.cols()); const Index size = mat.rows(); @@ -265,7 +266,7 @@ template<> struct ldlt_inplace<Lower> mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner); index_of_biggest_in_corner += k; - transpositions.coeffRef(k) = index_of_biggest_in_corner; + transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner); if(k != index_of_biggest_in_corner) { // apply the transposition while taking care to consider only @@ -274,7 +275,7 @@ template<> struct ldlt_inplace<Lower> mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k)); mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s)); std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner)); - for(int i=k+1;i<index_of_biggest_in_corner;++i) + for(Index i=k+1;i<index_of_biggest_in_corner;++i) { Scalar tmp = mat.coeffRef(i,k); mat.coeffRef(i,k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner,i)); @@ -442,6 +443,7 @@ template<typename MatrixType, int _UpLo> template<typename Derived> LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Derived>& w, const typename NumTraits<typename MatrixType::Scalar>::Real& sigma) { + typedef typename TranspositionType::StorageIndexType IndexType; const Index size = w.rows(); if (m_isInitialized) { @@ -453,7 +455,7 @@ LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Deri m_matrix.setZero(); m_transpositions.resize(size); for (Index i = 0; i < size; i++) - m_transpositions.coeffRef(i) = i; + m_transpositions.coeffRef(i) = IndexType(i); m_temporary.resize(size); m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef; m_isInitialized = true; diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index 1297b8413..009873c78 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -66,11 +66,11 @@ class PermutationBase : public EigenBase<Derived> MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime, MaxColsAtCompileTime = Traits::MaxColsAtCompileTime }; - typedef typename Traits::Scalar Scalar; + typedef typename Traits::StorageIndexType StorageIndexType; typedef typename Traits::Index Index; - typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,0,MaxRowsAtCompileTime,MaxColsAtCompileTime> + typedef Matrix<StorageIndexType,RowsAtCompileTime,ColsAtCompileTime,0,MaxRowsAtCompileTime,MaxColsAtCompileTime> DenseMatrixType; - typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,Index> + typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,StorageIndexType> PlainPermutationType; using Base::derived; #endif @@ -147,7 +147,7 @@ class PermutationBase : public EigenBase<Derived> /** Sets *this to be the identity permutation matrix */ void setIdentity() { - for(Index i = 0; i < size(); ++i) + for(StorageIndexType i = 0; i < size(); ++i) indices().coeffRef(i) = i; } @@ -173,8 +173,8 @@ class PermutationBase : public EigenBase<Derived> eigen_assert(i>=0 && j>=0 && i<size() && j<size()); for(Index k = 0; k < size(); ++k) { - if(indices().coeff(k) == i) indices().coeffRef(k) = j; - else if(indices().coeff(k) == j) indices().coeffRef(k) = i; + if(indices().coeff(k) == i) indices().coeffRef(k) = StorageIndexType(j); + else if(indices().coeff(k) == j) indices().coeffRef(k) = StorageIndexType(i); } return derived(); } @@ -262,7 +262,7 @@ class PermutationBase : public EigenBase<Derived> * * \param SizeAtCompileTime the number of rows/cols, or Dynamic * \param MaxSizeAtCompileTime the maximum number of rows/cols, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it. - * \param IndexType the interger type of the indices + * \param StorageIndexType the interger type of the indices * * This class represents a permutation matrix, internally stored as a vector of integers. * @@ -270,17 +270,18 @@ class PermutationBase : public EigenBase<Derived> */ namespace internal { -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType> -struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType> > - : traits<Matrix<IndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> > +template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndexType> +struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndexType> > + : traits<Matrix<_StorageIndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> > { - typedef IndexType Index; - typedef Matrix<IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType; + typedef Matrix<_StorageIndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType; + typedef typename IndicesType::Index Index; + typedef _StorageIndexType StorageIndexType; }; } -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType> -class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType> > +template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndexType> +class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndexType> > { typedef PermutationBase<PermutationMatrix> Base; typedef internal::traits<PermutationMatrix> Traits; @@ -288,6 +289,8 @@ class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompile #ifndef EIGEN_PARSED_BY_DOXYGEN typedef typename Traits::IndicesType IndicesType; + typedef typename Traits::StorageIndexType StorageIndexType; + typedef typename Traits::Index Index; #endif inline PermutationMatrix() @@ -295,7 +298,7 @@ class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompile /** Constructs an uninitialized permutation matrix of given size. */ - inline PermutationMatrix(int size) : m_indices(size) + inline PermutationMatrix(Index size) : m_indices(size) {} /** Copy constructor. */ @@ -384,18 +387,19 @@ class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompile namespace internal { -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int _PacketAccess> -struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>,_PacketAccess> > - : traits<Matrix<IndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> > +template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndexType, int _PacketAccess> +struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndexType>,_PacketAccess> > + : traits<Matrix<_StorageIndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> > { - typedef IndexType Index; - typedef Map<const Matrix<IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, _PacketAccess> IndicesType; + typedef Map<const Matrix<_StorageIndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, _PacketAccess> IndicesType; + typedef typename IndicesType::Index Index; + typedef _StorageIndexType StorageIndexType; }; } -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int _PacketAccess> -class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>,_PacketAccess> - : public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>,_PacketAccess> > +template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndexType, int _PacketAccess> +class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndexType>,_PacketAccess> + : public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndexType>,_PacketAccess> > { typedef PermutationBase<Map> Base; typedef internal::traits<Map> Traits; @@ -403,14 +407,15 @@ class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>, #ifndef EIGEN_PARSED_BY_DOXYGEN typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar Index; + typedef typename IndicesType::Scalar StorageIndexType; + typedef typename IndicesType::Index Index; #endif - inline Map(const Index* indicesPtr) + inline Map(const StorageIndexType* indicesPtr) : m_indices(indicesPtr) {} - inline Map(const Index* indicesPtr, Index size) + inline Map(const StorageIndexType* indicesPtr, Index size) : m_indices(indicesPtr,size) {} @@ -466,7 +471,8 @@ struct traits<PermutationWrapper<_IndicesType> > { typedef PermutationStorage StorageKind; typedef typename _IndicesType::Scalar Scalar; - typedef typename _IndicesType::Scalar Index; + typedef typename _IndicesType::Scalar StorageIndexType; + typedef typename _IndicesType::Index Index; typedef _IndicesType IndicesType; enum { RowsAtCompileTime = _IndicesType::SizeAtCompileTime, diff --git a/Eigen/src/Core/Transpositions.h b/Eigen/src/Core/Transpositions.h index e4ba0756f..92261118f 100644 --- a/Eigen/src/Core/Transpositions.h +++ b/Eigen/src/Core/Transpositions.h @@ -53,7 +53,8 @@ class TranspositionsBase public: typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar Index; + typedef typename IndicesType::Scalar StorageIndexType; + typedef typename IndicesType::Index Index; Derived& derived() { return *static_cast<Derived*>(this); } const Derived& derived() const { return *static_cast<const Derived*>(this); } @@ -81,17 +82,17 @@ class TranspositionsBase inline Index size() const { return indices().size(); } /** Direct access to the underlying index vector */ - inline const Index& coeff(Index i) const { return indices().coeff(i); } + inline const StorageIndexType& coeff(Index i) const { return indices().coeff(i); } /** Direct access to the underlying index vector */ - inline Index& coeffRef(Index i) { return indices().coeffRef(i); } + inline StorageIndexType& coeffRef(Index i) { return indices().coeffRef(i); } /** Direct access to the underlying index vector */ - inline const Index& operator()(Index i) const { return indices()(i); } + inline const StorageIndexType& operator()(Index i) const { return indices()(i); } /** Direct access to the underlying index vector */ - inline Index& operator()(Index i) { return indices()(i); } + inline StorageIndexType& operator()(Index i) { return indices()(i); } /** Direct access to the underlying index vector */ - inline const Index& operator[](Index i) const { return indices()(i); } + inline const StorageIndexType& operator[](Index i) const { return indices()(i); } /** Direct access to the underlying index vector */ - inline Index& operator[](Index i) { return indices()(i); } + inline StorageIndexType& operator[](Index i) { return indices()(i); } /** const version of indices(). */ const IndicesType& indices() const { return derived().indices(); } @@ -99,7 +100,7 @@ class TranspositionsBase IndicesType& indices() { return derived().indices(); } /** Resizes to given size. */ - inline void resize(int newSize) + inline void resize(Index newSize) { indices().resize(newSize); } @@ -107,7 +108,7 @@ class TranspositionsBase /** Sets \c *this to represents an identity transformation */ void setIdentity() { - for(int i = 0; i < indices().size(); ++i) + for(StorageIndexType i = 0; i < indices().size(); ++i) coeffRef(i) = i; } @@ -144,23 +145,26 @@ class TranspositionsBase }; namespace internal { -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType> -struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType> > +template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndexType> +struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndexType> > { - typedef IndexType Index; - typedef Matrix<Index, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType; + typedef Matrix<_StorageIndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType; + typedef typename IndicesType::Index Index; + typedef _StorageIndexType StorageIndexType; }; } -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType> -class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType> > +template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndexType> +class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndexType> > { typedef internal::traits<Transpositions> Traits; public: typedef TranspositionsBase<Transpositions> Base; typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar Index; + typedef typename IndicesType::Scalar StorageIndexType; + typedef typename IndicesType::Index Index; + inline Transpositions() {} @@ -215,30 +219,32 @@ class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTim namespace internal { -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int _PacketAccess> -struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,_PacketAccess> > +template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndexType, int _PacketAccess> +struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndexType>,_PacketAccess> > { - typedef IndexType Index; - typedef Map<const Matrix<Index,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType; + typedef Map<const Matrix<_StorageIndexType,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType; + typedef typename IndicesType::Index Index; + typedef _StorageIndexType StorageIndexType; }; } -template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int PacketAccess> -class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,PacketAccess> - : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,PacketAccess> > +template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndexType, int PacketAccess> +class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndexType>,PacketAccess> + : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_StorageIndexType>,PacketAccess> > { typedef internal::traits<Map> Traits; public: typedef TranspositionsBase<Map> Base; typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar Index; + typedef typename IndicesType::Scalar StorageIndexType; + typedef typename IndicesType::Index Index; - inline Map(const Index* indicesPtr) + inline Map(const StorageIndexType* indicesPtr) : m_indices(indicesPtr) {} - inline Map(const Index* indicesPtr, Index size) + inline Map(const StorageIndexType* indicesPtr, Index size) : m_indices(indicesPtr,size) {} @@ -275,7 +281,8 @@ namespace internal { template<typename _IndicesType> struct traits<TranspositionsWrapper<_IndicesType> > { - typedef typename _IndicesType::Scalar Index; + typedef typename _IndicesType::Scalar StorageIndexType; + typedef typename _IndicesType::Index Index; typedef _IndicesType IndicesType; }; } @@ -289,7 +296,8 @@ class TranspositionsWrapper typedef TranspositionsBase<TranspositionsWrapper> Base; typedef typename Traits::IndicesType IndicesType; - typedef typename IndicesType::Scalar Index; + typedef typename IndicesType::Scalar StorageIndexType; + typedef typename IndicesType::Index Index; inline TranspositionsWrapper(IndicesType& a_indices) : m_indices(a_indices) @@ -363,24 +371,25 @@ struct transposition_matrix_product_retval { typedef typename remove_all<typename MatrixType::Nested>::type MatrixTypeNestedCleaned; typedef typename TranspositionType::Index Index; + typedef typename TranspositionType::StorageIndexType StorageIndexType; transposition_matrix_product_retval(const TranspositionType& tr, const MatrixType& matrix) : m_transpositions(tr), m_matrix(matrix) {} - 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(); } template<typename Dest> inline void evalTo(Dest& dst) const { - const int size = m_transpositions.size(); - Index j = 0; + const Index size = m_transpositions.size(); + StorageIndexType j = 0; if(!(is_same<MatrixTypeNestedCleaned,Dest>::value && extract_data(dst) == extract_data(m_matrix))) dst = m_matrix; - for(int k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k) - if((j=m_transpositions.coeff(k))!=k) + for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k) + if(Index(j=m_transpositions.coeff(k))!=k) { if(Side==OnTheLeft) dst.row(k).swap(dst.row(j)); diff --git a/Eigen/src/LU/PartialPivLU.h b/Eigen/src/LU/PartialPivLU.h index 91383db31..2f65c3a49 100644 --- a/Eigen/src/LU/PartialPivLU.h +++ b/Eigen/src/LU/PartialPivLU.h @@ -371,13 +371,13 @@ struct partial_lu_impl /** \internal performs the LU decomposition with partial pivoting in-place. */ template<typename MatrixType, typename TranspositionType> -void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, typename TranspositionType::Index& nb_transpositions) +void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, typename TranspositionType::StorageIndexType& nb_transpositions) { eigen_assert(lu.cols() == row_transpositions.size()); eigen_assert((&row_transpositions.coeffRef(1)-&row_transpositions.coeffRef(0)) == 1); partial_lu_impl - <typename MatrixType::Scalar, MatrixType::Flags&RowMajorBit?RowMajor:ColMajor, typename TranspositionType::Index> + <typename MatrixType::Scalar, MatrixType::Flags&RowMajorBit?RowMajor:ColMajor, typename TranspositionType::StorageIndexType> ::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpositions.coeffRef(0), nb_transpositions); } @@ -396,7 +396,7 @@ PartialPivLU<MatrixType>& PartialPivLU<MatrixType>::compute(const MatrixType& ma m_rowsTranspositions.resize(size); - typename TranspositionType::Index nb_transpositions; + typename TranspositionType::StorageIndexType nb_transpositions; internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions); m_det_p = (nb_transpositions%2) ? -1 : 1; diff --git a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h b/Eigen/src/SparseCore/SparseCwiseBinaryOp.h index ec86ca933..60fdd214a 100644 --- a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +++ b/Eigen/src/SparseCore/SparseCwiseBinaryOp.h @@ -69,7 +69,6 @@ class CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator : public internal::sparse_cwise_binary_op_inner_iterator_selector<BinaryOp,Lhs,Rhs,typename CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator> { public: - typedef typename Lhs::Index Index; typedef internal::sparse_cwise_binary_op_inner_iterator_selector< BinaryOp,Lhs,Rhs, InnerIterator> Base; @@ -95,11 +94,11 @@ class sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Derived { typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> CwiseBinaryXpr; typedef typename traits<CwiseBinaryXpr>::Scalar Scalar; + typedef typename traits<CwiseBinaryXpr>::Index Index; typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested; typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested; typedef typename _LhsNested::InnerIterator LhsIterator; typedef typename _RhsNested::InnerIterator RhsIterator; - typedef typename Lhs::Index Index; public: @@ -161,11 +160,11 @@ class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, typedef scalar_product_op<T> BinaryFunc; typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr; typedef typename CwiseBinaryXpr::Scalar Scalar; + typedef typename CwiseBinaryXpr::Index Index; typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested; typedef typename _LhsNested::InnerIterator LhsIterator; typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested; typedef typename _RhsNested::InnerIterator RhsIterator; - typedef typename Lhs::Index Index; public: EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer) @@ -215,15 +214,15 @@ class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, typedef scalar_product_op<T> BinaryFunc; typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr; typedef typename CwiseBinaryXpr::Scalar Scalar; + typedef typename CwiseBinaryXpr::Index Index; typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested; typedef typename 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 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) + : m_rhs(xpr.rhs()), m_lhsIter(xpr.lhs(),typename _LhsNested::Index(outer)), m_functor(xpr.functor()), m_outer(outer) {} EIGEN_STRONG_INLINE Derived& operator++() @@ -256,9 +255,9 @@ class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, typedef scalar_product_op<T> BinaryFunc; typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr; typedef typename CwiseBinaryXpr::Scalar Scalar; + typedef typename CwiseBinaryXpr::Index Index; typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested; typedef typename _RhsNested::InnerIterator RhsIterator; - typedef typename Lhs::Index Index; enum { IsRowMajor = (int(Rhs::Flags)&RowMajorBit)==RowMajorBit }; public: diff --git a/Eigen/src/SparseCore/SparseDenseProduct.h b/Eigen/src/SparseCore/SparseDenseProduct.h index 295b2e81f..4a7813296 100644 --- a/Eigen/src/SparseCore/SparseDenseProduct.h +++ b/Eigen/src/SparseCore/SparseDenseProduct.h @@ -102,8 +102,8 @@ class SparseDenseOuterProduct EIGEN_STATIC_ASSERT(Tr,YOU_MADE_A_PROGRAMMING_MISTAKE); } - EIGEN_STRONG_INLINE Index rows() const { return Tr ? m_rhs.rows() : m_lhs.rows(); } - EIGEN_STRONG_INLINE Index cols() const { return Tr ? m_lhs.cols() : m_rhs.cols(); } + EIGEN_STRONG_INLINE Index rows() const { return Tr ? Index(m_rhs.rows()) : m_lhs.rows(); } + EIGEN_STRONG_INLINE Index cols() const { return Tr ? m_lhs.cols() : Index(m_rhs.cols()); } EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; } EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; } @@ -139,7 +139,7 @@ class SparseDenseOuterProduct<Lhs,Rhs,Transpose>::InnerIterator : public _LhsNes Scalar get(const _RhsNested &rhs, Index outer, Sparse = Sparse()) { typename Traits::_RhsNested::InnerIterator it(rhs, outer); - if (it && it.index()==0 && it.value()!=0) + if (it && it.index()==0 && it.value()!=Scalar(0)) return it.value(); m_empty = true; return Scalar(0); diff --git a/Eigen/src/SparseCore/SparseDiagonalProduct.h b/Eigen/src/SparseCore/SparseDiagonalProduct.h index 1bb590e64..c056b4914 100644 --- a/Eigen/src/SparseCore/SparseDiagonalProduct.h +++ b/Eigen/src/SparseCore/SparseDiagonalProduct.h @@ -32,8 +32,10 @@ struct traits<SparseDiagonalProduct<Lhs, Rhs> > typedef typename remove_all<Lhs>::type _Lhs; typedef typename remove_all<Rhs>::type _Rhs; typedef typename _Lhs::Scalar Scalar; - typedef typename promote_index_type<typename traits<Lhs>::Index, - typename traits<Rhs>::Index>::type Index; + // propagate the index type of the sparse matrix + typedef typename conditional< is_diagonal<_Lhs>::ret, + typename traits<Rhs>::Index, + typename traits<Lhs>::Index>::type Index; typedef Sparse StorageKind; typedef MatrixXpr XprKind; enum { @@ -90,8 +92,8 @@ class SparseDiagonalProduct eigen_assert(lhs.cols() == rhs.rows() && "invalid sparse matrix * diagonal matrix product"); } - EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); } - EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); } + EIGEN_STRONG_INLINE Index rows() const { return Index(m_lhs.rows()); } + EIGEN_STRONG_INLINE Index cols() const { return Index(m_rhs.cols()); } EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; } EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; } @@ -109,7 +111,7 @@ class sparse_diagonal_product_inner_iterator_selector : public CwiseUnaryOp<scalar_multiple_op<typename Lhs::Scalar>,const Rhs>::InnerIterator { typedef typename CwiseUnaryOp<scalar_multiple_op<typename Lhs::Scalar>,const Rhs>::InnerIterator Base; - typedef typename Lhs::Index Index; + typedef typename Rhs::Index Index; public: inline sparse_diagonal_product_inner_iterator_selector( const SparseDiagonalProductType& expr, Index outer) @@ -129,7 +131,7 @@ class sparse_diagonal_product_inner_iterator_selector scalar_product_op<typename Lhs::Scalar>, const typename Rhs::ConstInnerVectorReturnType, const typename Lhs::DiagonalVectorType>::InnerIterator Base; - typedef typename Lhs::Index Index; + typedef typename Rhs::Index Index; Index m_outer; public: inline sparse_diagonal_product_inner_iterator_selector( diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index ed935c40d..2ed2f3ebd 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -800,7 +800,9 @@ protected: template<typename Other> void initAssignment(const Other& other) { - resize(other.rows(), other.cols()); + eigen_assert( other.rows() == typename Other::Index(Index(other.rows())) + && other.cols() == typename Other::Index(Index(other.cols())) ); + resize(Index(other.rows()), Index(other.cols())); if(m_innerNonZeros) { std::free(m_innerNonZeros); @@ -940,7 +942,7 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa enum { IsRowMajor = SparseMatrixType::IsRowMajor }; typedef typename SparseMatrixType::Scalar Scalar; typedef typename SparseMatrixType::Index Index; - SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor> trMat(mat.rows(),mat.cols()); + SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor,Index> trMat(mat.rows(),mat.cols()); if(begin!=end) { diff --git a/Eigen/src/SparseCore/SparseMatrixBase.h b/Eigen/src/SparseCore/SparseMatrixBase.h index c64d74da0..1050cf3f1 100644 --- a/Eigen/src/SparseCore/SparseMatrixBase.h +++ b/Eigen/src/SparseCore/SparseMatrixBase.h @@ -202,20 +202,20 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> inline Derived& assign(const OtherDerived& other) { const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); - const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols(); + const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? Index(other.rows()) : Index(other.cols()); if ((!transpose) && other.isRValue()) { // eval without temporary - derived().resize(other.rows(), other.cols()); + derived().resize(Index(other.rows()), Index(other.cols())); derived().setZero(); derived().reserve((std::max)(this->rows(),this->cols())*2); for (Index j=0; j<outerSize; ++j) { derived().startVec(j); - for (typename OtherDerived::InnerIterator it(other, j); it; ++it) + for (typename OtherDerived::InnerIterator it(other, typename OtherDerived::Index(j)); it; ++it) { Scalar v = it.value(); - derived().insertBackByOuterInner(j,it.index()) = v; + derived().insertBackByOuterInner(j,Index(it.index())) = v; } } derived().finalize(); @@ -237,19 +237,19 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) }; - const Index outerSize = other.outerSize(); + const Index outerSize = Index(other.outerSize()); //typedef typename internal::conditional<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::type TempType; // thanks to shallow copies, we always eval to a tempary - Derived temp(other.rows(), other.cols()); + Derived temp(Index(other.rows()), Index(other.cols())); temp.reserve((std::max)(this->rows(),this->cols())*2); for (Index j=0; j<outerSize; ++j) { temp.startVec(j); - for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it) + for (typename OtherDerived::InnerIterator it(other.derived(), typename OtherDerived::Index(j)); it; ++it) { Scalar v = it.value(); - temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v; + temp.insertBackByOuterInner(Flip?Index(it.index()):j,Flip?j:Index(it.index())) = v; } } temp.finalize(); @@ -401,7 +401,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> { dst.setZero(); for (Index j=0; j<outerSize(); ++j) - for (typename Derived::InnerIterator i(derived(),j); i; ++i) + for (typename Derived::InnerIterator i(derived(),typename Derived::Index(j)); i; ++i) dst.coeffRef(i.row(),i.col()) = i.value(); } diff --git a/Eigen/src/SparseCore/SparseSelfAdjointView.h b/Eigen/src/SparseCore/SparseSelfAdjointView.h index 0eda96bc4..56c922929 100644 --- a/Eigen/src/SparseCore/SparseSelfAdjointView.h +++ b/Eigen/src/SparseCore/SparseSelfAdjointView.h @@ -246,7 +246,7 @@ class SparseSelfAdjointTimeDenseProduct || ( (UpLo&Lower) && LhsIsRowMajor), ProcessSecondHalf = !ProcessFirstHalf }; - for (Index j=0; j<m_lhs.outerSize(); ++j) + for (typename _Lhs::Index j=0; j<m_lhs.outerSize(); ++j) { LhsInnerIterator i(m_lhs,j); if (ProcessSecondHalf) |