mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-15 01:21:48 +08:00
Fix reshape strides when input has non-zero inner stride.
(cherry picked from commit 2260e11eb019161cc861ef2b832ce3b8a92efecd)
This commit is contained in:
parent
3eb0c8b69e
commit
f5593b4baa
@ -250,7 +250,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:
|
||||||
|
@ -193,6 +193,24 @@ void reshape4x4(MatType m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename BlockType>
|
||||||
|
void reshape_block(const BlockType& M) {
|
||||||
|
typename BlockType::PlainObject 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;
|
||||||
@ -213,4 +231,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)));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user