diff --git a/Eigen/Core b/Eigen/Core index 468ae0c76..f1c952832 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -345,6 +345,7 @@ using std::ptrdiff_t; #include "src/Core/Stride.h" #include "src/Core/Map.h" #include "src/Core/Block.h" +#include "src/Core/Reshape.h" #include "src/Core/VectorBlock.h" #include "src/Core/Ref.h" #include "src/Core/Transpose.h" diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 0a2144c69..a4f3435bb 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -79,6 +79,7 @@ template class ForceAlignedAccess; template class SwapWrapper; template class Block; +template class Reshape; template class VectorBlock; template class Transpose; diff --git a/Eigen/src/plugins/BlockMethods.h b/Eigen/src/plugins/BlockMethods.h index 9b7fdc4aa..d1da27766 100644 --- a/Eigen/src/plugins/BlockMethods.h +++ b/Eigen/src/plugins/BlockMethods.h @@ -993,3 +993,59 @@ inline typename ConstFixedSegmentReturnType::Type tail(Index n = N) const EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return typename ConstFixedSegmentReturnType::Type(derived(), size() - n); } + +/** \returns a dynamic-size expression of a reshape in *this. + * + * \param reshapeRows the number of rows in the reshape + * \param reshapeCols the number of columns in the reshape + * + * Example: \include MatrixBase_reshape_int_int.cpp + * Output: \verbinclude MatrixBase_reshape_int_int.out + * + * \note Even though the returned expression has dynamic size, in the case + * when it is applied to a fixed-size matrix, it inherits a fixed maximal size, + * which means that evaluating it does not cause a dynamic memory allocation. + * + * \sa class Reshape, reshape() + */ +EIGEN_DEVICE_FUNC +inline Reshape reshape(Index reshapeRows, Index reshapeCols) +{ + return Reshape(derived(), reshapeRows, reshapeCols); +} + +/** This is the const version of reshape(Index,Index). */ +EIGEN_DEVICE_FUNC +inline const Reshape reshape(Index reshapeRows, Index reshapeCols) const +{ + return Reshape(derived(), reshapeRows, reshapeCols); +} + +/** \returns a fixed-size expression of a reshape in *this. + * + * The template parameters \a ReshapeRows and \a ReshapeCols are the number of + * rows and columns in the reshape. + * + * Example: \include MatrixBase_reshape.cpp + * Output: \verbinclude MatrixBase_reshape.out + * + * \note since reshape is a templated member, the keyword template has to be used + * if the matrix type is also a template parameter: \code m.template reshape<3,3>(); \endcode + * + * \sa class Reshape, reshape(Index,Index) + */ +template +EIGEN_DEVICE_FUNC +inline Reshape reshape() +{ + return Reshape(derived()); +} + +/** This is the const version of reshape<>(Index, Index). */ +template +EIGEN_DEVICE_FUNC +inline const Reshape reshape() const +{ + return Reshape(derived()); +} +