From 2260e11eb019161cc861ef2b832ce3b8a92efecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 29 Nov 2022 19:39:29 +0000 Subject: [PATCH] Fix reshape strides when input has non-zero inner stride. --- Eigen/src/Core/Reshaped.h | 2 +- test/reshape.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Eigen/src/Core/Reshaped.h b/Eigen/src/Core/Reshaped.h index c90e61f2c8..81355ace55 100644 --- a/Eigen/src/Core/Reshaped.h +++ b/Eigen/src/Core/Reshaped.h @@ -251,7 +251,7 @@ class ReshapedImpl_dense EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const { - return ((Flags&RowMajorBit)==RowMajorBit) ? this->cols() : this->rows(); + return (((Flags&RowMajorBit)==RowMajorBit) ? this->cols() : this->rows()) * m_xpr.innerStride(); } protected: diff --git a/test/reshape.cpp b/test/reshape.cpp index d248f01cb8..ca7a73e61e 100644 --- a/test/reshape.cpp +++ b/test/reshape.cpp @@ -196,6 +196,24 @@ void reshape4x4(MatType m) } } +template +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 RowMatrixXi; @@ -216,4 +234,5 @@ EIGEN_DECLARE_TEST(reshape) CALL_SUBTEST(reshape4x4(rmx)); CALL_SUBTEST(reshape4x4(rm4)); + CALL_SUBTEST(reshape_block(rm4.col(1))); }