Remove reshape InnerPanel, add test, fix bug

This commit is contained in:
yoco 2014-01-20 01:43:28 +08:00
parent 03723abda0
commit 2b89080903
3 changed files with 24 additions and 24 deletions

View File

@ -22,9 +22,6 @@ namespace Eigen {
* \param XprType the type of the expression in which we are taking a reshape * \param XprType the type of the expression in which we are taking a reshape
* \param ReshapeRows the number of rows of the reshape we are taking at compile time (optional) * \param ReshapeRows the number of rows of the reshape we are taking at compile time (optional)
* \param ReshapeCols the number of columns of the reshape we are taking at compile time (optional) * \param ReshapeCols the number of columns of the reshape we are taking at compile time (optional)
* \param InnerPanel is true, if the reshape maps to a set of rows of a row major matrix or
* to set of columns of a column major matrix (optional). The parameter allows to determine
* at compile time whether aligned access is possible on the reshape expression.
* *
* This class represents an expression of either a fixed-size or dynamic-size reshape. It is the return * This class represents an expression of either a fixed-size or dynamic-size reshape. It is the return
* type of DenseBase::reshape(Index,Index) and DenseBase::reshape<int,int>() and * type of DenseBase::reshape(Index,Index) and DenseBase::reshape<int,int>() and
@ -50,8 +47,8 @@ namespace Eigen {
*/ */
namespace internal { namespace internal {
template<typename XprType, int ReshapeRows, int ReshapeCols, bool InnerPanel> template<typename XprType, int ReshapeRows, int ReshapeCols>
struct traits<Reshape<XprType, ReshapeRows, ReshapeCols, InnerPanel> > : traits<XprType> struct traits<Reshape<XprType, ReshapeRows, ReshapeCols> > : traits<XprType>
{ {
typedef typename traits<XprType>::Scalar Scalar; typedef typename traits<XprType>::Scalar Scalar;
typedef typename traits<XprType>::StorageKind StorageKind; typedef typename traits<XprType>::StorageKind StorageKind;
@ -84,7 +81,7 @@ struct traits<Reshape<XprType, ReshapeRows, ReshapeCols, InnerPanel> > : traits<
MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0) MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
&& (InnerStrideAtCompileTime == 1) && (InnerStrideAtCompileTime == 1)
? PacketAccessBit : 0, ? PacketAccessBit : 0,
MaskAlignedBit = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ? AlignedBit : 0, MaskAlignedBit = ((OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ? AlignedBit : 0,
FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0, FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
@ -92,7 +89,8 @@ struct traits<Reshape<XprType, ReshapeRows, ReshapeCols, InnerPanel> > : traits<
&& ColsAtCompileTime == ReshapeCols && ColsAtCompileTime == ReshapeCols
&& RowsAtCompileTime != Dynamic && RowsAtCompileTime != Dynamic
&& ColsAtCompileTime != Dynamic, && ColsAtCompileTime != Dynamic,
MaskDirectAccessBit = IsSameShapeAtCompileTime ? DirectAccessBit : 0, MaskDirectAccessBit = (IsSameShapeAtCompileTime ? DirectAccessBit : 0)
&& DirectAccessBit,
Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) | Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) |
MaskDirectAccessBit | MaskDirectAccessBit |
MaskPacketAccessBit | MaskPacketAccessBit |
@ -101,17 +99,17 @@ struct traits<Reshape<XprType, ReshapeRows, ReshapeCols, InnerPanel> > : traits<
}; };
}; };
template<typename XprType, int ReshapeRows=Dynamic, int ReshapeCols=Dynamic, bool InnerPanel = false, template<typename XprType, int ReshapeRows=Dynamic, int ReshapeCols=Dynamic,
bool HasDirectAccess = internal::has_direct_access<XprType>::ret> class ReshapeImpl_dense; bool HasDirectAccess = internal::has_direct_access<XprType>::ret> class ReshapeImpl_dense;
} // end namespace internal } // end namespace internal
template<typename XprType, int ReshapeRows, int ReshapeCols, bool InnerPanel, typename StorageKind> class ReshapeImpl; template<typename XprType, int ReshapeRows, int ReshapeCols, typename StorageKind> class ReshapeImpl;
template<typename XprType, int ReshapeRows, int ReshapeCols, bool InnerPanel> class Reshape template<typename XprType, int ReshapeRows, int ReshapeCols> class Reshape
: public ReshapeImpl<XprType, ReshapeRows, ReshapeCols, InnerPanel, typename internal::traits<XprType>::StorageKind> : public ReshapeImpl<XprType, ReshapeRows, ReshapeCols, typename internal::traits<XprType>::StorageKind>
{ {
typedef ReshapeImpl<XprType, ReshapeRows, ReshapeCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Impl; typedef ReshapeImpl<XprType, ReshapeRows, ReshapeCols, typename internal::traits<XprType>::StorageKind> Impl;
public: public:
//typedef typename Impl::Base Base; //typedef typename Impl::Base Base;
typedef Impl Base; typedef Impl Base;
@ -143,11 +141,11 @@ template<typename XprType, int ReshapeRows, int ReshapeCols, bool InnerPanel> cl
// The generic default implementation for dense reshape simplu forward to the internal::ReshapeImpl_dense // The generic default implementation for dense reshape simplu forward to the internal::ReshapeImpl_dense
// that must be specialized for direct and non-direct access... // that must be specialized for direct and non-direct access...
template<typename XprType, int ReshapeRows, int ReshapeCols, bool InnerPanel> template<typename XprType, int ReshapeRows, int ReshapeCols>
class ReshapeImpl<XprType, ReshapeRows, ReshapeCols, InnerPanel, Dense> class ReshapeImpl<XprType, ReshapeRows, ReshapeCols, Dense>
: public internal::ReshapeImpl_dense<XprType, ReshapeRows, ReshapeCols, InnerPanel> : public internal::ReshapeImpl_dense<XprType, ReshapeRows, ReshapeCols>
{ {
typedef internal::ReshapeImpl_dense<XprType, ReshapeRows, ReshapeCols, InnerPanel> Impl; typedef internal::ReshapeImpl_dense<XprType, ReshapeRows, ReshapeCols> Impl;
typedef typename XprType::Index Index; typedef typename XprType::Index Index;
public: public:
typedef Impl Base; typedef Impl Base;
@ -160,10 +158,10 @@ class ReshapeImpl<XprType, ReshapeRows, ReshapeCols, InnerPanel, Dense>
namespace internal { namespace internal {
/** \internal Internal implementation of dense Reshapes in the general case. */ /** \internal Internal implementation of dense Reshapes in the general case. */
template<typename XprType, int ReshapeRows, int ReshapeCols, bool InnerPanel, bool HasDirectAccess> class ReshapeImpl_dense template<typename XprType, int ReshapeRows, int ReshapeCols, bool HasDirectAccess> class ReshapeImpl_dense
: public internal::dense_xpr_base<Reshape<XprType, ReshapeRows, ReshapeCols, InnerPanel> >::type : public internal::dense_xpr_base<Reshape<XprType, ReshapeRows, ReshapeCols> >::type
{ {
typedef Reshape<XprType, ReshapeRows, ReshapeCols, InnerPanel> ReshapeType; typedef Reshape<XprType, ReshapeRows, ReshapeCols> ReshapeType;
public: public:
typedef typename internal::dense_xpr_base<ReshapeType>::type Base; typedef typename internal::dense_xpr_base<ReshapeType>::type Base;
@ -301,11 +299,11 @@ template<typename XprType, int ReshapeRows, int ReshapeCols, bool InnerPanel, bo
}; };
///** \internal Internal implementation of dense Reshapes in the direct access case.*/ ///** \internal Internal implementation of dense Reshapes in the direct access case.*/
//template<typename XprType, int ReshapeRows, int ReshapeCols, bool InnerPanel> //template<typename XprType, int ReshapeRows, int ReshapeCols>
//class ReshapeImpl_dense<XprType,ReshapeRows,ReshapeCols, InnerPanel, true> //class ReshapeImpl_dense<XprType,ReshapeRows,ReshapeCols, true>
// : public MapBase<Reshape<XprType, ReshapeRows, ReshapeCols, InnerPanel> > // : public MapBase<Reshape<XprType, ReshapeRows, ReshapeCols> >
//{ //{
// typedef Reshape<XprType, ReshapeRows, ReshapeCols, InnerPanel> ReshapeType; // typedef Reshape<XprType, ReshapeRows, ReshapeCols> ReshapeType;
// public: // public:
// //
// typedef MapBase<ReshapeType> Base; // typedef MapBase<ReshapeType> Base;

View File

@ -79,7 +79,7 @@ template<typename ExpressionType> class ForceAlignedAccess;
template<typename ExpressionType> class SwapWrapper; template<typename ExpressionType> class SwapWrapper;
template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false> class Block; template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false> class Block;
template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false> class Reshape; template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic> class Reshape;
template<typename MatrixType, int Size=Dynamic> class VectorBlock; template<typename MatrixType, int Size=Dynamic> class VectorBlock;
template<typename MatrixType> class Transpose; template<typename MatrixType> class Transpose;

View File

@ -53,6 +53,8 @@ void test_reshape()
} }
} }
mx.reshape(8, 2).leftCols(2);
// test dynamic-size matrix // test dynamic-size matrix
CALL_SUBTEST(dynamic_reshape_all_size(mx, 4, 4)); CALL_SUBTEST(dynamic_reshape_all_size(mx, 4, 4));
CALL_SUBTEST(static_reshape_all_size(mx)); CALL_SUBTEST(static_reshape_all_size(mx));