Change the logic of A.reshaped<Order>() to be a simple alias to A.reshaped<Order>(AutoSize,fix<1>).

This means that now AutoOrder is allowed, and it always return a column-vector.
This commit is contained in:
Gael Guennebaud 2018-10-03 11:41:47 +02:00
parent 0481900e25
commit 5f26f57598
4 changed files with 19 additions and 27 deletions

View File

@ -125,7 +125,7 @@ template<typename XprType, int Rows, int Cols, int Order> class Reshaped
} }
}; };
// The generic default implementation for dense reshape simplu forward to the internal::ReshapedImpl_dense // The generic default implementation for dense reshape simply forward to the internal::ReshapedImpl_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 Rows, int Cols, int Order> template<typename XprType, int Rows, int Cols, int Order>
class ReshapedImpl<XprType, Rows, Cols, Order, Dense> class ReshapedImpl<XprType, Rows, Cols, Order, Dense>

View File

@ -32,30 +32,29 @@ EIGEN_DEVICE_FUNC
inline Reshaped<Derived,...> inline Reshaped<Derived,...>
reshaped(NRowsType nRows, NColsType nCols); reshaped(NRowsType nRows, NColsType nCols);
/** This is the const version of reshaped(NRowsType,NColsType). */ /// This is the const version of reshaped(NRowsType,NColsType).
template<int Order = ColMajor, typename NRowsType, typename NColsType> template<int Order = ColMajor, typename NRowsType, typename NColsType>
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
inline const Reshaped<const Derived,...> inline const Reshaped<const Derived,...>
reshaped(NRowsType nRows, NColsType nCols) const; reshaped(NRowsType nRows, NColsType nCols) const;
/// \returns an expression of \c *this with columns (or rows) stacked to a linear column (or row) vector /// \returns an expression of \c *this with columns (or rows) stacked to a linear column vector
/// ///
/// \tparam Order specifies whether to stack columns to a column-vector (ColMajor) or /// \tparam Order specifies whether the coefficients should be processed in column-major-order (ColMajor), in row-major-order (RowMajor),
/// to cat rows to a row-vector (RowMajor). The default is ColMajor. /// or follows the \em natural order of the nested expression (AutoOrder). The default is ColMajor.
/// ///
/// If Order==ColMajor (the default), then it returns a column vector from the stacked columns of \c *this. /// This overloads is essentially a shortcut for `A.reshaped<Order>(AutoSize,fix<1>).
/// This is equivalent to `A.reshaped<ColMajor>(AutoSize,fix<1>)`.
/// ///
/// If Order==RowMajor, then it returns a row vector from the glued rows of \c *this. /// - If Order==ColMajor (the default), then it returns a column-vector from the stacked columns of \c *this.
/// This is equivalent to `A.reshaped<RowMajor>(fix<1>,AutoSize)`. /// - If Order==RowMajor, then it returns a column-vector from the stacked rows of \c *this.
/// - If Order==AutoOrder, then it returns a column-vector with elements stacked following the storage order of \c *this.
/// This mode is the recommended one when the particular ordering of the element is not relevant.
/// ///
/// Example: /// Example:
/// \include MatrixBase_reshaped_to_vector.cpp /// \include MatrixBase_reshaped_to_vector.cpp
/// Output: \verbinclude MatrixBase_reshaped_to_vector.out /// Output: \verbinclude MatrixBase_reshaped_to_vector.out
/// ///
/// If you want more control, you can still fall back to reshaped(NRowsType,NColsType). /// If you want more control, you can still fall back to reshaped(NRowsType,NColsType).
/// For instance, to return a column vector with element stacked following the storage order,
/// you can do: \code A.reshaped<AutoOrder>(AutoSize,fix<1>) \endcode
/// ///
/// \sa reshaped(NRowsType,NColsType), class Reshaped /// \sa reshaped(NRowsType,NColsType), class Reshaped
/// ///
@ -64,7 +63,7 @@ EIGEN_DEVICE_FUNC
inline Reshaped<Derived,...> inline Reshaped<Derived,...>
reshaped(); reshaped();
/** This is the const version of reshaped(). */ /// This is the const version of reshaped().
template<int Order = ColMajor> template<int Order = ColMajor>
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
inline const Reshaped<const Derived,...> inline const Reshaped<const Derived,...>
@ -129,20 +128,12 @@ reshaped() EIGEN_RESHAPED_METHOD_CONST
template<int Order> template<int Order>
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, SizeAtCompileTime, 1, Order==AutoOrder?Flags&RowMajorBit:Order>
Order==RowMajor ? 1 : SizeAtCompileTime,
Order==RowMajor ? SizeAtCompileTime : 1,
Order==AutoOrder?Flags&RowMajorBit:Order>
reshaped() EIGEN_RESHAPED_METHOD_CONST reshaped() EIGEN_RESHAPED_METHOD_CONST
{ {
EIGEN_STATIC_ASSERT(Order==RowMajor || Order==ColMajor, INVALID_TEMPLATE_PARAMETER); EIGEN_STATIC_ASSERT(Order==RowMajor || Order==ColMajor || Order==AutoOrder, INVALID_TEMPLATE_PARAMETER);
return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, SizeAtCompileTime, 1, Order==AutoOrder?Flags&RowMajorBit:Order>
Order==RowMajor ? 1 : SizeAtCompileTime, (derived(), size(), 1);
Order==RowMajor ? SizeAtCompileTime : 1,
Order==AutoOrder?Flags&RowMajorBit:Order>
(derived(),
Order==RowMajor ? 1 : size(),
Order==RowMajor ? size() : 1);
} }
#undef EIGEN_RESHAPED_METHOD_CONST #undef EIGEN_RESHAPED_METHOD_CONST

View File

@ -1,4 +1,4 @@
Matrix4i m = Matrix4i::Random(); Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl; cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is m.reshaped().transpose():" << endl << m.reshaped().transpose() << endl; cout << "Here is m.reshaped().transpose():" << endl << m.reshaped().transpose() << endl;
cout << "Here is m.reshaped<RowMajor>(): " << endl << m.reshaped<RowMajor>() << endl; cout << "Here is m.reshaped<RowMajor>().transpose(): " << endl << m.reshaped<RowMajor>().transpose() << endl;

View File

@ -157,8 +157,9 @@ void reshape4x4(MatType m)
VERIFY_IS_EQUAL(m.reshaped().reshaped(8,2), m.reshaped(8,2)); VERIFY_IS_EQUAL(m.reshaped().reshaped(8,2), m.reshaped(8,2));
VERIFY_IS_EQUAL(m.reshaped(), m.template reshaped<ColMajor>()); VERIFY_IS_EQUAL(m.reshaped(), m.template reshaped<ColMajor>());
VERIFY_IS_EQUAL(m.transpose().reshaped().transpose(), m.template reshaped<RowMajor>()); VERIFY_IS_EQUAL(m.transpose().reshaped(), m.template reshaped<RowMajor>());
VERIFY_IS_EQUAL(m.template reshaped<RowMajor>(fix<1>, AutoSize), m.template reshaped<RowMajor>()); VERIFY_IS_EQUAL(m.template reshaped<RowMajor>(AutoSize,fix<1>), m.template reshaped<RowMajor>());
VERIFY_IS_EQUAL(m.template reshaped<AutoOrder>(AutoSize,fix<1>), m.template reshaped<AutoOrder>());
VERIFY(is_same_eq(m.reshaped(AutoSize,fix<1>), m.reshaped())); VERIFY(is_same_eq(m.reshaped(AutoSize,fix<1>), m.reshaped()));
VERIFY_IS_EQUAL(m.template reshaped<RowMajor>(fix<1>,AutoSize), m.transpose().reshaped().transpose()); VERIFY_IS_EQUAL(m.template reshaped<RowMajor>(fix<1>,AutoSize), m.transpose().reshaped().transpose());