diff --git a/Eigen/src/Core/VectorwiseOp.h b/Eigen/src/Core/VectorwiseOp.h index 893bc796f..e44cbd468 100644 --- a/Eigen/src/Core/VectorwiseOp.h +++ b/Eigen/src/Core/VectorwiseOp.h @@ -186,24 +186,7 @@ template class VectorwiseOp }; protected: - - typedef typename internal::conditional::type SubVector; - /** \internal - * \returns the i-th subvector according to the \c Direction */ - EIGEN_DEVICE_FUNC - SubVector subVector(Index i) - { - return SubVector(m_matrix.derived(),i); - } - - /** \internal - * \returns the number of subvectors in the direction \c Direction */ - EIGEN_DEVICE_FUNC - Index subVectors() const - { return isVertical?m_matrix.cols():m_matrix.rows(); } - + template struct ExtendedType { typedef Replicate +typename internal::conditional::type +subVector(Index i) +{ + return typename internal::conditional::type(derived(),i); +} + +/** This is the const version of subVector(Index) */ +EIGEN_DEVICE_FUNC +template +typename internal::conditional::type +subVector(Index i) const +{ + return typename internal::conditional::type(derived(),i); +} + +/** \returns the number of subvectors (rows or columns) in the direction \c Direction + * \sa subVector(Index) + */ +EIGEN_DEVICE_FUNC +template +Index subVectors() const +{ return (Direction==Vertical)?cols():rows(); } + diff --git a/test/block.cpp b/test/block.cpp index ca13539a9..27b60d778 100644 --- a/test/block.cpp +++ b/test/block.cpp @@ -220,6 +220,13 @@ template void block(const MatrixType& m) VERIFY_RAISES_ASSERT( m1.array() *= m1.col(0).array() ); VERIFY_RAISES_ASSERT( m1.array() /= m1.col(0).array() ); } + + VERIFY_IS_EQUAL( m1.template subVector(r1), m1.row(r1) ); + VERIFY_IS_APPROX( (m1+m1).template subVector(r1), (m1+m1).row(r1) ); + VERIFY_IS_EQUAL( m1.template subVector(c1), m1.col(c1) ); + VERIFY_IS_APPROX( (m1+m1).template subVector(c1), (m1+m1).col(c1) ); + VERIFY_IS_EQUAL( m1.template subVectors(), m1.rows() ); + VERIFY_IS_EQUAL( m1.template subVectors(), m1.cols() ); }