Fix reshape strides when input has non-zero inner stride.

This commit is contained in:
Antonio Sánchez 2022-11-29 19:39:29 +00:00 committed by Rasmus Munk Larsen
parent 23524ab6fc
commit 2260e11eb0
2 changed files with 20 additions and 1 deletions

View File

@ -251,7 +251,7 @@ class ReshapedImpl_dense<XprType, Rows, Cols, Order, true>
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index outerStride() const inline Index outerStride() const
{ {
return ((Flags&RowMajorBit)==RowMajorBit) ? this->cols() : this->rows(); return (((Flags&RowMajorBit)==RowMajorBit) ? this->cols() : this->rows()) * m_xpr.innerStride();
} }
protected: protected:

View File

@ -196,6 +196,24 @@ void reshape4x4(MatType m)
} }
} }
template<typename BlockType>
void reshape_block(const BlockType& M) {
auto dense = M.eval();
Index rows = M.size() / 2;
Index cols = M.size() / rows;
VERIFY_IS_EQUAL(dense.reshaped(rows, cols), M.reshaped(rows, cols));
for (Index i=0; i<rows; ++i) {
VERIFY_IS_EQUAL(dense.reshaped(rows, cols).row(i),
M.reshaped(rows, cols).row(i));
}
for (Index j = 0; j<cols; ++j) {
VERIFY_IS_EQUAL(dense.reshaped(rows, cols).col(j),
M.reshaped(rows, cols).col(j));
}
}
EIGEN_DECLARE_TEST(reshape) EIGEN_DECLARE_TEST(reshape)
{ {
typedef Matrix<int,Dynamic,Dynamic,RowMajor> RowMatrixXi; typedef Matrix<int,Dynamic,Dynamic,RowMajor> RowMatrixXi;
@ -216,4 +234,5 @@ EIGEN_DECLARE_TEST(reshape)
CALL_SUBTEST(reshape4x4(rmx)); CALL_SUBTEST(reshape4x4(rmx));
CALL_SUBTEST(reshape4x4(rm4)); CALL_SUBTEST(reshape4x4(rm4));
CALL_SUBTEST(reshape_block(rm4.col(1)));
} }