Define non-const operator() in Reverse; enable test for this.

Introduction of DenseCoeffBase (revision bfdc1c4973
) meant that non-const
operator() is only defined if DirectAccess is set. This caused the line
"m.reverse()(1,0) = 4;" in MatrixBase_reverse.cpp to fail at compile-time.
Not sure this is correct solution; perhaps we should disallow this? Or make
Reverse DirectAccess with a negative stride - would that break something?
This commit is contained in:
Jitse Niesen
2010-05-31 14:42:04 +01:00
parent 07a65dd02b
commit c21390a611
3 changed files with 19 additions and 43 deletions

View File

@@ -84,6 +84,10 @@ template<typename MatrixType, int Direction> class Reverse
EIGEN_DENSE_PUBLIC_INTERFACE(Reverse)
using Base::IsRowMajor;
// next line is necessary because otherwise const version of operator()
// is hidden by non-const version defined in this file
using Base::operator();
protected:
enum {
PacketSize = ei_packet_traits<Scalar>::size,
@@ -106,6 +110,12 @@ template<typename MatrixType, int Direction> class Reverse
inline Index rows() const { return m_matrix.rows(); }
inline Index cols() const { return m_matrix.cols(); }
inline Scalar& operator()(Index row, Index col)
{
ei_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
return coeffRef(row, col);
}
inline Scalar& coeffRef(Index row, Index col)
{
return m_matrix.const_cast_derived().coeffRef(ReverseRow ? m_matrix.rows() - row - 1 : row,
@@ -128,6 +138,12 @@ template<typename MatrixType, int Direction> class Reverse
return m_matrix.const_cast_derived().coeffRef(m_matrix.size() - index - 1);
}
inline Scalar& operator()(Index index)
{
ei_assert(index >= 0 && index < m_matrix.size());
return coeffRef(index);
}
template<int LoadMode>
inline const PacketScalar packet(Index row, Index col) const
{

View File

@@ -380,8 +380,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
/** \returns a matrix expression
* where each column (or row) are reversed.
*
* Example: \include PartialRedux_reverse.cpp
* Output: \verbinclude PartialRedux_reverse.out
* Example: \include VectorWise_reverse.cpp
* Output: \verbinclude VectorWise_reverse.out
*
* \sa DenseBase::reverse() */
const Reverse<ExpressionType, Direction> reverse() const