mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-06 05:05:12 +08:00
Define non-const operator() in Reverse; enable test for this.
Introduction of DenseCoeffBase (revision bfdc1c49730c79e6058ba1506628341559670c25 ) 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:
parent
07a65dd02b
commit
c21390a611
@ -84,6 +84,10 @@ template<typename MatrixType, int Direction> class Reverse
|
|||||||
EIGEN_DENSE_PUBLIC_INTERFACE(Reverse)
|
EIGEN_DENSE_PUBLIC_INTERFACE(Reverse)
|
||||||
using Base::IsRowMajor;
|
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:
|
protected:
|
||||||
enum {
|
enum {
|
||||||
PacketSize = ei_packet_traits<Scalar>::size,
|
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 rows() const { return m_matrix.rows(); }
|
||||||
inline Index cols() const { return m_matrix.cols(); }
|
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)
|
inline Scalar& coeffRef(Index row, Index col)
|
||||||
{
|
{
|
||||||
return m_matrix.const_cast_derived().coeffRef(ReverseRow ? m_matrix.rows() - row - 1 : row,
|
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);
|
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>
|
template<int LoadMode>
|
||||||
inline const PacketScalar packet(Index row, Index col) const
|
inline const PacketScalar packet(Index row, Index col) const
|
||||||
{
|
{
|
||||||
|
@ -380,8 +380,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
|
|||||||
/** \returns a matrix expression
|
/** \returns a matrix expression
|
||||||
* where each column (or row) are reversed.
|
* where each column (or row) are reversed.
|
||||||
*
|
*
|
||||||
* Example: \include PartialRedux_reverse.cpp
|
* Example: \include VectorWise_reverse.cpp
|
||||||
* Output: \verbinclude PartialRedux_reverse.out
|
* Output: \verbinclude VectorWise_reverse.out
|
||||||
*
|
*
|
||||||
* \sa DenseBase::reverse() */
|
* \sa DenseBase::reverse() */
|
||||||
const Reverse<ExpressionType, Direction> reverse() const
|
const Reverse<ExpressionType, Direction> reverse() const
|
||||||
|
@ -103,47 +103,6 @@ template<typename MatrixType> void reverse(const MatrixType& m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
cout << "m1:" << endl << m1 << endl;
|
|
||||||
cout << "m1c_reversed:" << endl << m1c_reversed << endl;
|
|
||||||
|
|
||||||
cout << "----------------" << endl;
|
|
||||||
|
|
||||||
for ( int i=0; i< rows*cols; i++){
|
|
||||||
cout << m1c_reversed.coeff(i) << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "----------------" << endl;
|
|
||||||
|
|
||||||
for ( int i=0; i< rows*cols; i++){
|
|
||||||
cout << m1c_reversed.colwise().reverse().coeff(i) << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "================" << endl;
|
|
||||||
|
|
||||||
cout << "m1.coeff( ind ): " << m1.coeff( ind ) << endl;
|
|
||||||
cout << "m1c_reversed.colwise().reverse().coeff( ind ): " << m1c_reversed.colwise().reverse().coeff( ind ) << endl;
|
|
||||||
*/
|
|
||||||
|
|
||||||
//MatrixType m1r_reversed = m1.rowwise().reverse();
|
|
||||||
//VERIFY_IS_APPROX( m1r_reversed.rowwise().reverse().coeff( ind ), m1.coeff( ind ) );
|
|
||||||
|
|
||||||
/*
|
|
||||||
cout << "m1" << endl << m1 << endl;
|
|
||||||
cout << "m1 using coeff(int index)" << endl;
|
|
||||||
for ( int i = 0; i < rows*cols; i++) {
|
|
||||||
cout << m1.coeff(i) << " ";
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
cout << "m1.transpose()" << endl << m1.transpose() << endl;
|
|
||||||
cout << "m1.transpose() using coeff(int index)" << endl;
|
|
||||||
for ( int i = 0; i < rows*cols; i++) {
|
|
||||||
cout << m1.transpose().coeff(i) << " ";
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
Scalar x = ei_random<Scalar>();
|
Scalar x = ei_random<Scalar>();
|
||||||
|
|
||||||
int r = ei_random<int>(0, rows-1),
|
int r = ei_random<int>(0, rows-1),
|
||||||
@ -152,6 +111,7 @@ template<typename MatrixType> void reverse(const MatrixType& m)
|
|||||||
m1.reverse()(r, c) = x;
|
m1.reverse()(r, c) = x;
|
||||||
VERIFY_IS_APPROX(x, m1(rows - 1 - r, cols - 1 - c));
|
VERIFY_IS_APPROX(x, m1(rows - 1 - r, cols - 1 - c));
|
||||||
|
|
||||||
|
/*
|
||||||
m1.colwise().reverse()(r, c) = x;
|
m1.colwise().reverse()(r, c) = x;
|
||||||
VERIFY_IS_APPROX(x, m1(rows - 1 - r, c));
|
VERIFY_IS_APPROX(x, m1(rows - 1 - r, c));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user