From 1bf12880ae65dcf6215354b3383e419ef2cedcc0 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 21 Sep 2018 16:50:04 +0200 Subject: Add reshaped<>() shortcuts when returning vectors and remove the reshaping version of operator()(all) --- Eigen/src/plugins/ReshapedMethods.h | 52 +++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'Eigen/src/plugins') diff --git a/Eigen/src/plugins/ReshapedMethods.h b/Eigen/src/plugins/ReshapedMethods.h index 9aeb7f3ee..5366e2711 100644 --- a/Eigen/src/plugins/ReshapedMethods.h +++ b/Eigen/src/plugins/ReshapedMethods.h @@ -6,7 +6,7 @@ /// \param nRows the number of rows in the reshaped expression, specified at either run-time or compile-time, or AutoSize /// \param nCols the number of columns in the reshaped expression, specified at either run-time or compile-time, or AutoSize /// \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. +/// or follows the \em natural order of the nested expression (AutoOrder). The default is ColMajor. /// \tparam NRowsType the type of the value handling the number of rows, typically Index. /// \tparam NColsType the type of the value handling the number of columns, typically Index. /// @@ -38,6 +38,36 @@ 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 +/// +/// \tparam Order specifies whether to glue columns or rows, and returns a column or row vector. +/// Possible values are ColMajor, RowMajor or 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 \code A(all) \endcode and \code A.reshaped(fix<1>,AutoSize) \endcode. +/// +/// If Order==RowMajor, then it returns a row vector from the glued rows of \c *this. +/// This is equivalent to \code A.reshaped(fix<1>,AutoSize) \endcode. +/// +/// If Order=AutoOrder, the it returns the same expression as \code A.reshaped() \endcode +/// +/// 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 operator()(all), reshaped(NRowsType,NColsType), class Reshaped +/// +template +EIGEN_DEVICE_FUNC +inline Reshaped +reshaped(); + +/** This is the const version of reshaped(). */ +template +EIGEN_DEVICE_FUNC +inline const Reshaped +reshaped() const; + /// \returns as expression of \c *this with columns stacked to a linear column vector /// /// This overload is essentially a shortcut for @@ -104,11 +134,29 @@ reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST EIGEN_DEVICE_FUNC inline Reshaped -operator()(const Eigen::internal::all_t&) EIGEN_RESHAPED_METHOD_CONST +reshaped() EIGEN_RESHAPED_METHOD_CONST { return Reshaped(derived(),size(),1); } +template +EIGEN_DEVICE_FUNC +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); +} + #undef EIGEN_RESHAPED_METHOD_CONST #ifndef EIGEN_RESHAPED_METHOD_2ND_PASS -- cgit v1.2.3