mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 12:46:00 +08:00
fix reshape flag and test case
This commit is contained in:
parent
b64a09acc1
commit
15f273b63c
@ -53,20 +53,16 @@ struct traits<Reshape<XprType, ReshapeRows, ReshapeCols> > : traits<XprType>
|
||||
typedef typename traits<XprType>::Scalar Scalar;
|
||||
typedef typename traits<XprType>::StorageKind StorageKind;
|
||||
typedef typename traits<XprType>::XprKind XprKind;
|
||||
typedef typename nested<XprType>::type XprTypeNested;
|
||||
typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
|
||||
enum{
|
||||
MatrixRows = traits<XprType>::RowsAtCompileTime,
|
||||
MatrixCols = traits<XprType>::ColsAtCompileTime,
|
||||
RowsAtCompileTime = MatrixRows == 0 ? 0 : ReshapeRows,
|
||||
ColsAtCompileTime = MatrixCols == 0 ? 0 : ReshapeCols,
|
||||
MaxRowsAtCompileTime = ReshapeRows==0 ? 0
|
||||
: int(RowsAtCompileTime),
|
||||
MaxColsAtCompileTime = ReshapeCols==0 ? 0
|
||||
: int(ColsAtCompileTime),
|
||||
XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
|
||||
IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
|
||||
: (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
|
||||
RowsAtCompileTime = ReshapeRows,
|
||||
ColsAtCompileTime = ReshapeCols,
|
||||
MaxRowsAtCompileTime = ReshapeRows,
|
||||
MaxColsAtCompileTime = ReshapeCols,
|
||||
XprTypeIsRowMajor = (int(traits<XprType>::Flags) & RowMajorBit) != 0,
|
||||
IsRowMajor = (RowsAtCompileTime == 1 && ColsAtCompileTime != 1) ? 1
|
||||
: (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ? 0
|
||||
: XprTypeIsRowMajor,
|
||||
HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
|
||||
InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
|
||||
@ -83,14 +79,11 @@ struct traits<Reshape<XprType, ReshapeRows, ReshapeCols> > : traits<XprType>
|
||||
FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
|
||||
FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
|
||||
FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
|
||||
IsSameShapeAtCompileTime = RowsAtCompileTime == ReshapeRows
|
||||
&& ColsAtCompileTime == ReshapeCols
|
||||
&& RowsAtCompileTime != Dynamic
|
||||
&& ColsAtCompileTime != Dynamic,
|
||||
Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) |
|
||||
(traits<XprType>::Flags & ~DirectAccessBit) |
|
||||
MaskPacketAccessBit |
|
||||
MaskAlignedBit),
|
||||
MaskAlignedBit)
|
||||
& ~DirectAccessBit,
|
||||
|
||||
Flags = (Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit)
|
||||
};
|
||||
};
|
||||
|
@ -18,18 +18,18 @@ template <typename MatType>
|
||||
void reshape_all_size(MatType m) {
|
||||
typedef Eigen::Map<MatrixXi> MapMat;
|
||||
// dynamic
|
||||
VERIFY_IS_EQUAL((m.template reshape( 1, 16)), MapMat(m.eval().data(), 1, 16));
|
||||
VERIFY_IS_EQUAL((m.template reshape( 2, 8)), MapMat(m.eval().data(), 2, 8));
|
||||
VERIFY_IS_EQUAL((m.template reshape( 4, 4)), MapMat(m.eval().data(), 4, 4));
|
||||
VERIFY_IS_EQUAL((m.template reshape( 8, 2)), MapMat(m.eval().data(), 8, 2));
|
||||
VERIFY_IS_EQUAL((m.template reshape(16, 1)), MapMat(m.eval().data(), 16, 1));
|
||||
VERIFY_IS_EQUAL((m.template reshape( 1, 16)), MapMat(m.data(), 1, 16));
|
||||
VERIFY_IS_EQUAL((m.template reshape( 2, 8)), MapMat(m.data(), 2, 8));
|
||||
VERIFY_IS_EQUAL((m.template reshape( 4, 4)), MapMat(m.data(), 4, 4));
|
||||
VERIFY_IS_EQUAL((m.template reshape( 8, 2)), MapMat(m.data(), 8, 2));
|
||||
VERIFY_IS_EQUAL((m.template reshape(16, 1)), MapMat(m.data(), 16, 1));
|
||||
|
||||
// static
|
||||
VERIFY_IS_EQUAL((m.template reshape< 1, 16>()), MapMat(m.eval().data(), 1, 16));
|
||||
VERIFY_IS_EQUAL((m.template reshape< 2, 8>()), MapMat(m.eval().data(), 2, 8));
|
||||
VERIFY_IS_EQUAL((m.template reshape< 4, 4>()), MapMat(m.eval().data(), 4, 4));
|
||||
VERIFY_IS_EQUAL((m.template reshape< 8, 2>()), MapMat(m.eval().data(), 8, 2));
|
||||
VERIFY_IS_EQUAL((m.template reshape<16, 1>()), MapMat(m.eval().data(), 16, 1));
|
||||
VERIFY_IS_EQUAL((m.template reshape< 1, 16>()), MapMat(m.data(), 1, 16));
|
||||
VERIFY_IS_EQUAL((m.template reshape< 2, 8>()), MapMat(m.data(), 2, 8));
|
||||
VERIFY_IS_EQUAL((m.template reshape< 4, 4>()), MapMat(m.data(), 4, 4));
|
||||
VERIFY_IS_EQUAL((m.template reshape< 8, 2>()), MapMat(m.data(), 8, 2));
|
||||
VERIFY_IS_EQUAL((m.template reshape<16, 1>()), MapMat(m.data(), 16, 1));
|
||||
|
||||
// reshape chain
|
||||
VERIFY_IS_EQUAL(
|
||||
@ -45,7 +45,7 @@ void reshape_all_size(MatType m) {
|
||||
.template reshape( 8, 2)
|
||||
.template reshape< 4, 4>()
|
||||
),
|
||||
MapMat(m.eval().data(), 4, 4)
|
||||
MapMat(m.data(), 4, 4)
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user