aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/Transpositions.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2014-07-17 13:34:26 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2014-07-17 13:34:26 +0200
commit77af4cc3c9fac237d8fcf32379137b14c203033f (patch)
tree14166e356609534982653c6daf63be44ea7095bf /Eigen/src/Core/Transpositions.h
parent5e72151ca537c84afa03b49e614667c51e40ad54 (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/Core/Transpositions.h')
-rw-r--r--Eigen/src/Core/Transpositions.h77
1 files changed, 43 insertions, 34 deletions
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));