Fix reshape strides when input has non-zero inner stride.
diff --git a/Eigen/src/Core/Reshaped.h b/Eigen/src/Core/Reshaped.h index c90e61f..81355ac 100644 --- a/Eigen/src/Core/Reshaped.h +++ b/Eigen/src/Core/Reshaped.h
@@ -251,7 +251,7 @@ 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 d248f01..ca7a73e 100644 --- a/test/reshape.cpp +++ b/test/reshape.cpp
@@ -196,6 +196,24 @@ } } +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) { typedef Matrix<int,Dynamic,Dynamic,RowMajor> RowMatrixXi; @@ -216,4 +234,5 @@ CALL_SUBTEST(reshape4x4(rmx)); CALL_SUBTEST(reshape4x4(rm4)); + CALL_SUBTEST(reshape_block(rm4.col(1))); }