mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-24 19:40:45 +08:00
Extend reshaped unit tests and remove useless const_cast
This commit is contained in:
parent
b57c9787b1
commit
4b7cf7ff82
@ -191,7 +191,7 @@ class ReshapedImpl_dense<XprType,Rows,Cols,Order,false>
|
||||
/** \returns the nested expression */
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename internal::remove_reference<XprType>::type&
|
||||
nestedExpression() { return m_xpr.const_cast_derived(); }
|
||||
nestedExpression() { return m_xpr; }
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -49,10 +49,25 @@ void check_auto_reshape4x4(MatType m)
|
||||
VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, fix< 1> ), m.template reshaped<Order>(v16, fix< 1>)));
|
||||
}
|
||||
|
||||
template <typename MatType>
|
||||
void check_direct_access_reshape4x4(MatType , internal::FixedInt<RowMajorBit>) {}
|
||||
|
||||
template <typename MatType>
|
||||
void check_direct_access_reshape4x4(MatType m, internal::FixedInt<0>) {
|
||||
VERIFY_IS_EQUAL(m.reshaped( 1, 16).data(), m.data());
|
||||
VERIFY_IS_EQUAL(m.reshaped( 1, 16).innerStride(), 1);
|
||||
|
||||
VERIFY_IS_EQUAL(m.reshaped( 2, 8).data(), m.data());
|
||||
VERIFY_IS_EQUAL(m.reshaped( 2, 8).innerStride(), 1);
|
||||
VERIFY_IS_EQUAL(m.reshaped( 2, 8).outerStride(), 2);
|
||||
}
|
||||
|
||||
// just test a 4x4 matrix, enumerate all combination manually
|
||||
template <typename MatType>
|
||||
void reshape4x4(MatType m)
|
||||
{
|
||||
typedef typename MatType::Scalar Scalar;
|
||||
|
||||
internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 1> v1( 1);
|
||||
internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 2> v2( 2);
|
||||
internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 4> v4( 4);
|
||||
@ -124,12 +139,7 @@ void reshape4x4(MatType m)
|
||||
check_auto_reshape4x4<ColMajor> (m.transpose());
|
||||
check_auto_reshape4x4<AutoOrder>(m.transpose());
|
||||
|
||||
VERIFY_IS_EQUAL(m.reshaped( 1, 16).data(), m.data());
|
||||
VERIFY_IS_EQUAL(m.reshaped( 1, 16).innerStride(), 1);
|
||||
|
||||
VERIFY_IS_EQUAL(m.reshaped( 2, 8).data(), m.data());
|
||||
VERIFY_IS_EQUAL(m.reshaped( 2, 8).innerStride(), 1);
|
||||
VERIFY_IS_EQUAL(m.reshaped( 2, 8).outerStride(), 2);
|
||||
check_direct_access_reshape4x4(m,fix<MatType::Flags&RowMajorBit>);
|
||||
|
||||
if((MatType::Flags&RowMajorBit)==0)
|
||||
{
|
||||
@ -150,8 +160,8 @@ void reshape4x4(MatType m)
|
||||
VERIFY_IS_EQUAL( m28r1, m28r2);
|
||||
|
||||
VERIFY(is_same_eq(m.reshaped(v16,fix<1>), m.reshaped()));
|
||||
VERIFY_IS_EQUAL(m.reshaped(16,1), m.reshaped());
|
||||
VERIFY_IS_EQUAL(m.reshaped(1,16), m.reshaped().transpose());
|
||||
VERIFY_IS_EQUAL(m.reshaped(16,1).eval(), m.reshaped().eval());
|
||||
VERIFY_IS_EQUAL(m.reshaped(1,16).eval(), m.reshaped().transpose().eval());
|
||||
VERIFY_IS_EQUAL(m.reshaped().reshaped(2,8), m.reshaped(2,8));
|
||||
VERIFY_IS_EQUAL(m.reshaped().reshaped(4,4), m.reshaped(4,4));
|
||||
VERIFY_IS_EQUAL(m.reshaped().reshaped(8,2), m.reshaped(8,2));
|
||||
@ -163,12 +173,30 @@ void reshape4x4(MatType m)
|
||||
|
||||
VERIFY(is_same_eq(m.reshaped(AutoSize,fix<1>), m.reshaped()));
|
||||
VERIFY_IS_EQUAL(m.template reshaped<RowMajor>(fix<1>,AutoSize), m.transpose().reshaped().transpose());
|
||||
|
||||
// check assignment
|
||||
{
|
||||
Matrix<Scalar,Dynamic,1> m1x(m.size()); m1x.setRandom();
|
||||
VERIFY_IS_APPROX(m.reshaped() = m1x, m1x);
|
||||
VERIFY_IS_APPROX(m, m1x.reshaped(4,4));
|
||||
|
||||
Matrix<Scalar,Dynamic,Dynamic> m28(2,8); m28.setRandom();
|
||||
VERIFY_IS_APPROX(m.reshaped(2,8) = m28, m28);
|
||||
VERIFY_IS_APPROX(m, m28.reshaped(4,4));
|
||||
VERIFY_IS_APPROX(m.template reshaped<RowMajor>(2,8) = m28, m28);
|
||||
|
||||
Matrix<Scalar,Dynamic,Dynamic> m24(2,4); m24.setRandom();
|
||||
VERIFY_IS_APPROX(m(seq(0,last,2),all).reshaped(2,4) = m24, m24);
|
||||
|
||||
// check constness:
|
||||
m.reshaped(2,8).nestedExpression() = m;
|
||||
}
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(reshape)
|
||||
{
|
||||
typedef Matrix<int,Dynamic,Dynamic> RowMatrixXi;
|
||||
typedef Matrix<int,4,4> RowMatrix4i;
|
||||
typedef Matrix<int,Dynamic,Dynamic,RowMajor> RowMatrixXi;
|
||||
typedef Matrix<int,4,4,RowMajor> RowMatrix4i;
|
||||
MatrixXi mx = MatrixXi::Random(4, 4);
|
||||
Matrix4i m4 = Matrix4i::Random(4, 4);
|
||||
RowMatrixXi rmx = RowMatrixXi::Random(4, 4);
|
||||
|
Loading…
x
Reference in New Issue
Block a user