bug #877, bug #572: Introduce a global Index typedef. Rename Sparse*::Index to StorageIndex, make Dense*::StorageIndex an alias to DenseIndex. Overall this commit gets rid of all Index conversion warnings.

This commit is contained in:
Christoph Hertzberg
2014-12-04 22:48:53 +01:00
parent 6ccf97f3e6
commit e8cdbedefb
95 changed files with 1101 additions and 1111 deletions

View File

@@ -31,7 +31,7 @@ class KroneckerProductBase : public ReturnByValue<Derived>
protected:
typedef typename Traits::Lhs Lhs;
typedef typename Traits::Rhs Rhs;
typedef typename Traits::Index Index;
typedef typename Traits::StorageIndex StorageIndex;
public:
/*! \brief Constructor. */
@@ -39,8 +39,8 @@ class KroneckerProductBase : public ReturnByValue<Derived>
: m_A(A), m_B(B)
{}
inline Index rows() const { return m_A.rows() * m_B.rows(); }
inline Index cols() const { return m_A.cols() * m_B.cols(); }
inline StorageIndex rows() const { return m_A.rows() * m_B.rows(); }
inline StorageIndex cols() const { return m_A.cols() * m_B.cols(); }
/*!
* This overrides ReturnByValue::coeff because this function is
@@ -48,8 +48,8 @@ class KroneckerProductBase : public ReturnByValue<Derived>
*/
Scalar coeff(Index row, Index col) const
{
return m_A.coeff(typename Lhs::Index(row / m_B.rows()), typename Lhs::Index(col / m_B.cols())) *
m_B.coeff(typename Rhs::Index(row % m_B.rows()), typename Rhs::Index(col % m_B.cols()));
return m_A.coeff(row / m_B.rows(), col / m_B.cols()) *
m_B.coeff(row % m_B.rows(), col % m_B.cols());
}
/*!
@@ -59,7 +59,7 @@ class KroneckerProductBase : public ReturnByValue<Derived>
Scalar coeff(Index i) const
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
return m_A.coeff(typename Lhs::Index(i / m_A.size())) * m_B.coeff(typename Rhs::Index(i % m_A.size()));
return m_A.coeff(i / m_A.size()) * m_B.coeff(i % m_A.size());
}
protected:
@@ -134,7 +134,6 @@ template<typename Lhs, typename Rhs>
template<typename Dest>
void KroneckerProduct<Lhs,Rhs>::evalTo(Dest& dst) const
{
typedef typename Base::Index Index;
const int BlockRows = Rhs::RowsAtCompileTime,
BlockCols = Rhs::ColsAtCompileTime;
const Index Br = m_B.rows(),
@@ -148,12 +147,8 @@ template<typename Lhs, typename Rhs>
template<typename Dest>
void KroneckerProductSparse<Lhs,Rhs>::evalTo(Dest& dst) const
{
typedef typename Dest::Index DestIndex;
const typename Rhs::Index Br = m_B.rows(),
Bc = m_B.cols();
eigen_assert(this->rows() <= NumTraits<DestIndex>::highest());
eigen_assert(this->cols() <= NumTraits<DestIndex>::highest());
dst.resize(DestIndex(this->rows()), DestIndex(this->cols()));
Index Br = m_B.rows(), Bc = m_B.cols();
dst.resize(this->rows(), this->cols());
dst.resizeNonZeros(0);
// 1 - evaluate the operands if needed:
@@ -170,13 +165,14 @@ void KroneckerProductSparse<Lhs,Rhs>::evalTo(Dest& dst) const
// compute number of non-zeros per innervectors of dst
{
// TODO VectorXi is not necessarily big enough!
VectorXi nnzA = VectorXi::Zero(Dest::IsRowMajor ? m_A.rows() : m_A.cols());
for (typename Lhs::Index kA=0; kA < m_A.outerSize(); ++kA)
for (Index kA=0; kA < m_A.outerSize(); ++kA)
for (LhsInnerIterator itA(lhs1,kA); itA; ++itA)
nnzA(Dest::IsRowMajor ? itA.row() : itA.col())++;
VectorXi nnzB = VectorXi::Zero(Dest::IsRowMajor ? m_B.rows() : m_B.cols());
for (typename Rhs::Index kB=0; kB < m_B.outerSize(); ++kB)
for (Index kB=0; kB < m_B.outerSize(); ++kB)
for (RhsInnerIterator itB(rhs1,kB); itB; ++itB)
nnzB(Dest::IsRowMajor ? itB.row() : itB.col())++;
@@ -184,17 +180,16 @@ void KroneckerProductSparse<Lhs,Rhs>::evalTo(Dest& dst) const
dst.reserve(VectorXi::Map(nnzAB.data(), nnzAB.size()));
}
for (typename Lhs::Index kA=0; kA < m_A.outerSize(); ++kA)
for (Index kA=0; kA < m_A.outerSize(); ++kA)
{
for (typename Rhs::Index kB=0; kB < m_B.outerSize(); ++kB)
for (Index kB=0; kB < m_B.outerSize(); ++kB)
{
for (LhsInnerIterator itA(lhs1,kA); itA; ++itA)
{
for (RhsInnerIterator itB(rhs1,kB); itB; ++itB)
{
const DestIndex
i = DestIndex(itA.row() * Br + itB.row()),
j = DestIndex(itA.col() * Bc + itB.col());
Index i = itA.row() * Br + itB.row(),
j = itA.col() * Bc + itB.col();
dst.insert(i,j) = itA.value() * itB.value();
}
}
@@ -210,7 +205,7 @@ struct traits<KroneckerProduct<_Lhs,_Rhs> >
typedef typename remove_all<_Lhs>::type Lhs;
typedef typename remove_all<_Rhs>::type Rhs;
typedef typename scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar;
typedef typename promote_index_type<typename Lhs::Index, typename Rhs::Index>::type Index;
typedef typename promote_index_type<typename Lhs::StorageIndex, typename Rhs::StorageIndex>::type StorageIndex;
enum {
Rows = size_at_compile_time<traits<Lhs>::RowsAtCompileTime, traits<Rhs>::RowsAtCompileTime>::ret,
@@ -230,7 +225,7 @@ struct traits<KroneckerProductSparse<_Lhs,_Rhs> >
typedef typename remove_all<_Rhs>::type Rhs;
typedef typename scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar;
typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind, typename traits<Rhs>::StorageKind, scalar_product_op<typename Lhs::Scalar, typename Rhs::Scalar> >::ret StorageKind;
typedef typename promote_index_type<typename Lhs::Index, typename Rhs::Index>::type Index;
typedef typename promote_index_type<typename Lhs::StorageIndex, typename Rhs::StorageIndex>::type StorageIndex;
enum {
LhsFlags = Lhs::Flags,
@@ -249,7 +244,7 @@ struct traits<KroneckerProductSparse<_Lhs,_Rhs> >
CoeffReadCost = Dynamic
};
typedef SparseMatrix<Scalar, 0, Index> ReturnType;
typedef SparseMatrix<Scalar, 0, StorageIndex> ReturnType;
};
} // end namespace internal