diff --git a/Eigen/src/Core/Reshaped.h b/Eigen/src/Core/Reshaped.h index aaa5a5739..b7bd1b292 100644 --- a/Eigen/src/Core/Reshaped.h +++ b/Eigen/src/Core/Reshaped.h @@ -125,7 +125,7 @@ template 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... template class ReshapedImpl diff --git a/Eigen/src/plugins/ReshapedMethods.h b/Eigen/src/plugins/ReshapedMethods.h index 574eb987b..ca9251ed2 100644 --- a/Eigen/src/plugins/ReshapedMethods.h +++ b/Eigen/src/plugins/ReshapedMethods.h @@ -32,30 +32,29 @@ EIGEN_DEVICE_FUNC inline Reshaped reshaped(NRowsType nRows, NColsType nCols); -/** This is the const version of reshaped(NRowsType,NColsType). */ +/// This is the const version of reshaped(NRowsType,NColsType). template EIGEN_DEVICE_FUNC inline const Reshaped 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 -/// to cat rows to a row-vector (RowMajor). The default is ColMajor. +/// \tparam Order specifies whether the coefficients should be processed in column-major-order (ColMajor), in row-major-order (RowMajor), +/// 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 is equivalent to `A.reshaped(AutoSize,fix<1>)`. +/// This overloads is essentially a shortcut for `A.reshaped(AutoSize,fix<1>). /// -/// If Order==RowMajor, then it returns a row vector from the glued rows of \c *this. -/// This is equivalent to `A.reshaped(fix<1>,AutoSize)`. +/// - If Order==ColMajor (the default), then it returns a column-vector from the stacked columns of \c *this. +/// - 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: /// \include MatrixBase_reshaped_to_vector.cpp /// Output: \verbinclude MatrixBase_reshaped_to_vector.out /// /// 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(AutoSize,fix<1>) \endcode /// /// \sa reshaped(NRowsType,NColsType), class Reshaped /// @@ -64,7 +63,7 @@ EIGEN_DEVICE_FUNC inline Reshaped reshaped(); -/** This is the const version of reshaped(). */ +/// This is the const version of reshaped(). template EIGEN_DEVICE_FUNC inline const Reshaped @@ -129,20 +128,12 @@ reshaped() EIGEN_RESHAPED_METHOD_CONST template EIGEN_DEVICE_FUNC -inline Reshaped +inline Reshaped reshaped() EIGEN_RESHAPED_METHOD_CONST { - EIGEN_STATIC_ASSERT(Order==RowMajor || Order==ColMajor, INVALID_TEMPLATE_PARAMETER); - return Reshaped - (derived(), - Order==RowMajor ? 1 : size(), - Order==RowMajor ? size() : 1); + EIGEN_STATIC_ASSERT(Order==RowMajor || Order==ColMajor || Order==AutoOrder, INVALID_TEMPLATE_PARAMETER); + return Reshaped + (derived(), size(), 1); } #undef EIGEN_RESHAPED_METHOD_CONST diff --git a/doc/snippets/MatrixBase_reshaped_to_vector.cpp b/doc/snippets/MatrixBase_reshaped_to_vector.cpp index ee844c203..37f65f7c6 100644 --- a/doc/snippets/MatrixBase_reshaped_to_vector.cpp +++ b/doc/snippets/MatrixBase_reshaped_to_vector.cpp @@ -1,4 +1,4 @@ Matrix4i m = Matrix4i::Random(); 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(): " << endl << m.reshaped() << endl; +cout << "Here is m.reshaped().transpose(): " << endl << m.reshaped().transpose() << endl; diff --git a/test/reshape.cpp b/test/reshape.cpp index 2c241f2fe..14a02bb3b 100644 --- a/test/reshape.cpp +++ b/test/reshape.cpp @@ -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(), m.template reshaped()); - VERIFY_IS_EQUAL(m.transpose().reshaped().transpose(), m.template reshaped()); - VERIFY_IS_EQUAL(m.template reshaped(fix<1>, AutoSize), m.template reshaped()); + VERIFY_IS_EQUAL(m.transpose().reshaped(), m.template reshaped()); + VERIFY_IS_EQUAL(m.template reshaped(AutoSize,fix<1>), m.template reshaped()); + VERIFY_IS_EQUAL(m.template reshaped(AutoSize,fix<1>), m.template reshaped()); VERIFY(is_same_eq(m.reshaped(AutoSize,fix<1>), m.reshaped())); VERIFY_IS_EQUAL(m.template reshaped(fix<1>,AutoSize), m.transpose().reshaped().transpose());