From 9036cda36484c4d7268b928b5976534c8ef3ce42 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 29 Jan 2017 14:57:45 +0100 Subject: [PATCH] Cleanup intitial reshape implementation: - reshape -> reshaped - make it compatible with evaluators. --- Eigen/Core | 2 +- Eigen/src/Core/DenseBase.h | 14 + Eigen/src/Core/Reshape.h | 445 +++++++++++++--------- Eigen/src/Core/util/ForwardDeclarations.h | 2 +- Eigen/src/plugins/BlockMethods.h | 56 --- test/CMakeLists.txt | 2 +- test/reshape.cpp | 43 ++- 7 files changed, 310 insertions(+), 254 deletions(-) diff --git a/Eigen/Core b/Eigen/Core index 351c7926a..e72e528a3 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -471,9 +471,9 @@ using std::ptrdiff_t; #include "src/Core/Map.h" #include "src/Core/Ref.h" #include "src/Core/Block.h" -#include "src/Core/Reshape.h" #include "src/Core/VectorBlock.h" #include "src/Core/IndexedView.h" +#include "src/Core/Reshape.h" #include "src/Core/Transpose.h" #include "src/Core/DiagonalMatrix.h" #include "src/Core/Diagonal.h" diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index a8229cf03..09e958727 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -557,6 +557,20 @@ template class DenseBase } EIGEN_DEVICE_FUNC void reverseInPlace(); + EIGEN_DEVICE_FUNC inline + Reshaped reshaped(Index nRows, Index nCols); + + EIGEN_DEVICE_FUNC inline + const Reshaped reshaped(Index nRows, Index nCols) const; + + template + EIGEN_DEVICE_FUNC + inline Reshaped reshaped(); + + template + EIGEN_DEVICE_FUNC + inline const Reshaped reshaped() const; + #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase #define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL #define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND) diff --git a/Eigen/src/Core/Reshape.h b/Eigen/src/Core/Reshape.h index e4a71312c..0f7d44c49 100644 --- a/Eigen/src/Core/Reshape.h +++ b/Eigen/src/Core/Reshape.h @@ -1,30 +1,30 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2008 Gael Guennebaud -// Copyright (C) 2006-2010 Benoit Jacob +// Copyright (C) 2008-2017 Gael Guennebaud // Copyright (C) 2014 yoco // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -#ifndef EIGEN_RESHAPE_H -#define EIGEN_RESHAPE_H +#ifndef EIGEN_RESHAPED_H +#define EIGEN_RESHAPED_H namespace Eigen { -/** \class Reshape +/** \class Reshapedd * \ingroup Core_Module * * \brief Expression of a fixed-size or dynamic-size 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 ReshapeCols the number of columns of the reshape we are taking at compile time (optional) + * \tparam XprType the type of the expression in which we are taking a reshape + * \tparam Rows the number of rows of the reshape we are taking at compile time (optional) + * \tparam Cols the number of columns of the reshape we are taking at compile time (optional) + * \tparam Order * * 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() and + * type of DenseBase::reshaped(Index,Index) and DenseBase::reshape() and * most of the time this is the only way it is used. * * However, if you want to directly maniputate reshape expressions, @@ -32,23 +32,23 @@ namespace Eigen { * will need to use this class. * * Here is an example illustrating the dynamic case: - * \include class_Reshape.cpp - * Output: \verbinclude class_Reshape.out + * \include class_Reshaped.cpp + * Output: \verbinclude class_Reshaped.out * * \note Even though this expression has dynamic size, in the case where \a XprType * has fixed size, this expression inherits a fixed maximal size which means that evaluating * it does not cause a dynamic memory allocation. * * Here is an example illustrating the fixed-size case: - * \include class_FixedReshape.cpp - * Output: \verbinclude class_FixedReshape.out + * \include class_FixedReshaped.cpp + * Output: \verbinclude class_FixedReshaped.out * - * \sa DenseBase::reshape(Index,Index), DenseBase::reshape(), class VectorReshape + * \sa DenseBase::reshaped(Index,Index), DenseBase::reshaped(), class VectorReshaped */ namespace internal { -template -struct traits > : traits +template +struct traits > : traits { typedef typename traits::Scalar Scalar; typedef typename traits::StorageKind StorageKind; @@ -56,10 +56,10 @@ struct traits > : traits enum{ MatrixRows = traits::RowsAtCompileTime, MatrixCols = traits::ColsAtCompileTime, - RowsAtCompileTime = ReshapeRows, - ColsAtCompileTime = ReshapeCols, - MaxRowsAtCompileTime = ReshapeRows, - MaxColsAtCompileTime = ReshapeCols, + RowsAtCompileTime = Rows, + ColsAtCompileTime = Cols, + MaxRowsAtCompileTime = Rows, + MaxColsAtCompileTime = Cols, XprTypeIsRowMajor = (int(traits::Flags) & RowMajorBit) != 0, IsRowMajor = (RowsAtCompileTime == 1 && ColsAtCompileTime != 1) ? 1 : (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ? 0 @@ -75,50 +75,48 @@ struct traits > : traits MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits::size) == 0) && (InnerStrideAtCompileTime == 1) ? PacketAccessBit : 0, - MaskAlignedBit = ((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, FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, - Flags0 = traits::Flags & ( (HereditaryBits & ~RowMajorBit) | - MaskPacketAccessBit | - MaskAlignedBit) + Flags0 = traits::Flags & ( (HereditaryBits & ~RowMajorBit) | MaskPacketAccessBit) & ~DirectAccessBit, Flags = (Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit) }; }; -template::ret> class ReshapeImpl_dense; +template::ret> class ReshapedImpl_dense; } // end namespace internal -template class ReshapeImpl; +template class ReshapedImpl; -template class Reshape - : public ReshapeImpl::StorageKind> +template class Reshaped + : public ReshapedImpl::StorageKind> { - typedef ReshapeImpl::StorageKind> Impl; + typedef ReshapedImpl::StorageKind> Impl; public: //typedef typename Impl::Base Base; typedef Impl Base; - EIGEN_GENERIC_PUBLIC_INTERFACE(Reshape) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reshape) + EIGEN_GENERIC_PUBLIC_INTERFACE(Reshaped) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reshaped) /** Fixed-size constructor */ EIGEN_DEVICE_FUNC - inline Reshape(XprType& xpr) + inline Reshaped(XprType& xpr) : Impl(xpr) { EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE) - eigen_assert(ReshapeRows * ReshapeCols == xpr.rows() * xpr.cols()); + eigen_assert(Rows * Cols == xpr.rows() * xpr.cols()); } /** Dynamic-size constructor */ EIGEN_DEVICE_FUNC - inline Reshape(XprType& xpr, + inline Reshaped(XprType& xpr, Index reshapeRows, Index reshapeCols) : Impl(xpr, reshapeRows, reshapeCols) { @@ -128,144 +126,56 @@ template class Reshape } }; -// 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::ReshapedImpl_dense // that must be specialized for direct and non-direct access... -template -class ReshapeImpl - : public internal::ReshapeImpl_dense +template +class ReshapedImpl + : public internal::ReshapedImpl_dense { - typedef internal::ReshapeImpl_dense Impl; - typedef typename XprType::Index Index; + typedef internal::ReshapedImpl_dense Impl; public: typedef Impl Base; - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapeImpl) - EIGEN_DEVICE_FUNC inline ReshapeImpl(XprType& xpr) : Impl(xpr) {} - EIGEN_DEVICE_FUNC inline ReshapeImpl(XprType& xpr, Index reshapeRows, Index reshapeCols) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl) + EIGEN_DEVICE_FUNC inline ReshapedImpl(XprType& xpr) : Impl(xpr) {} + EIGEN_DEVICE_FUNC inline ReshapedImpl(XprType& xpr, Index reshapeRows, Index reshapeCols) : Impl(xpr, reshapeRows, reshapeCols) {} }; namespace internal { -/** \internal Internal implementation of dense Reshapes in the general case. */ -template class ReshapeImpl_dense - : public internal::dense_xpr_base >::type +/** \internal Internal implementation of dense Reshapeds in the general case. */ +template class ReshapedImpl_dense + : public internal::dense_xpr_base >::type { - typedef Reshape ReshapeType; + typedef Reshaped ReshapedType; public: - typedef typename internal::dense_xpr_base::type Base; - EIGEN_DENSE_PUBLIC_INTERFACE(ReshapeType) - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapeImpl_dense) + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense) + + typedef typename internal::ref_selector::non_const_type MatrixTypeNested; + typedef typename internal::remove_all::type NestedExpression; class InnerIterator; /** Fixed-size constructor */ EIGEN_DEVICE_FUNC - inline ReshapeImpl_dense(XprType& xpr) - : m_xpr(xpr), m_reshapeRows(ReshapeRows), m_reshapeCols(ReshapeCols) + inline ReshapedImpl_dense(XprType& xpr) + : m_xpr(xpr), m_rows(Rows), m_cols(Cols) {} /** Dynamic-size constructor */ EIGEN_DEVICE_FUNC - inline ReshapeImpl_dense(XprType& xpr, - Index reshapeRows, Index reshapeCols) - : m_xpr(xpr), m_reshapeRows(reshapeRows), m_reshapeCols(reshapeCols) + inline ReshapedImpl_dense(XprType& xpr, + Index nRows, Index nCols) + : m_xpr(xpr), m_rows(nRows), m_cols(nCols) {} - EIGEN_DEVICE_FUNC inline Index rows() const { return m_reshapeRows.value(); } - EIGEN_DEVICE_FUNC inline Index cols() const { return m_reshapeCols.value(); } - - typedef std::pair RowCol; - - inline RowCol index_remap(Index rowId, Index colId) const { - const Index nth_elem_idx = colId * m_reshapeRows.value() + rowId; - const Index actual_col = nth_elem_idx / m_xpr.rows(); - const Index actual_row = nth_elem_idx % m_xpr.rows(); - return RowCol(actual_row, actual_col); - } - - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index rowId, Index colId) - { - EIGEN_STATIC_ASSERT_LVALUE(XprType) - const RowCol row_col = index_remap(rowId, colId); - return m_xpr.const_cast_derived().coeffRef(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index rowId, Index colId) const - { - const RowCol row_col = index_remap(rowId, colId); - return m_xpr.derived().coeffRef(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const - { - const RowCol row_col = index_remap(rowId, colId); - return m_xpr.coeff(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - inline Scalar& coeffRef(Index index) - { - EIGEN_STATIC_ASSERT_LVALUE(XprType) - const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0); - return m_xpr.const_cast_derived().coeffRef(row_col.first, row_col.second); - - } - - EIGEN_DEVICE_FUNC - inline const Scalar& coeffRef(Index index) const - { - const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0); - return m_xpr.const_cast_derived().coeffRef(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - inline const CoeffReturnType coeff(Index index) const - { - const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0); - return m_xpr.coeff(row_col.first, row_col.second); - } - - EIGEN_DEVICE_FUNC - template - inline PacketScalar packet(Index rowId, Index colId) const - { - const RowCol row_col = index_remap(rowId, colId); - return m_xpr.template packet(row_col.first, row_col.second); - - } - - template - inline void writePacket(Index rowId, Index colId, const PacketScalar& val) - { - const RowCol row_col = index_remap(rowId, colId); - m_xpr.const_cast_derived().template writePacket - (row_col.first, row_col.second, val); - } - - template - inline PacketScalar packet(Index index) const - { - const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0); - return m_xpr.template packet(row_col.first, row_col.second); - } - - template - inline void writePacket(Index index, const PacketScalar& val) - { - const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, - RowsAtCompileTime == 1 ? index : 0); - return m_xpr.template packet(row_col.first, row_col.second, val); - } + EIGEN_DEVICE_FUNC Index rows() const { return m_rows; } + EIGEN_DEVICE_FUNC Index cols() const { return m_cols; } #ifdef EIGEN_PARSED_BY_DOXYGEN /** \sa MapBase::data() */ @@ -274,40 +184,168 @@ template::type& nestedExpression() const - { - return m_xpr; - } + const typename internal::remove_all::type& + nestedExpression() const { return m_xpr; } + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC + typename internal::remove_reference::type& + nestedExpression() { return m_xpr.const_cast_derived(); } protected: - const typename XprType::Nested m_xpr; - const internal::variable_if_dynamic m_reshapeRows; - const internal::variable_if_dynamic m_reshapeCols; + MatrixTypeNested m_xpr; + const internal::variable_if_dynamic m_rows; + const internal::variable_if_dynamic m_cols; }; -///** \internal Internal implementation of dense Reshapes in the direct access case.*/ -//template -//class ReshapeImpl_dense -// : public MapBase > + +template +struct unary_evaluator, IndexBased> + : evaluator_base > +{ + typedef Reshaped XprType; + + enum { + CoeffReadCost = evaluator::CoeffReadCost /* TODO + cost of index computations */, + + Flags = (evaluator::Flags & (HereditaryBits /*| LinearAccessBit | DirectAccessBit*/)), + + Alignment = 0 + }; + + EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr) + { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + typedef std::pair RowCol; + + inline RowCol index_remap(Index rowId, Index colId) const { + const Index nth_elem_idx = colId * m_xpr.rows() + rowId; + const Index actual_col = nth_elem_idx / m_xpr.nestedExpression().rows(); + const Index actual_row = nth_elem_idx % m_xpr.nestedExpression().rows(); + return RowCol(actual_row, actual_col); + } + + EIGEN_DEVICE_FUNC + inline Scalar& coeffRef(Index rowId, Index colId) + { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.coeffRef(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC + inline const Scalar& coeffRef(Index rowId, Index colId) const + { + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.coeffRef(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC + EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const + { + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.coeff(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC + inline Scalar& coeffRef(Index index) + { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + const RowCol row_col = index_remap(Rows == 1 ? 0 : index, + Rows == 1 ? index : 0); + return m_argImpl.coeffRef(row_col.first, row_col.second); + + } + + EIGEN_DEVICE_FUNC + inline const Scalar& coeffRef(Index index) const + { + const RowCol row_col = index_remap(Rows == 1 ? 0 : index, + Rows == 1 ? index : 0); + return m_argImpl.coeffRef(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC + inline const CoeffReturnType coeff(Index index) const + { + const RowCol row_col = index_remap(Rows == 1 ? 0 : index, + Rows == 1 ? index : 0); + return m_argImpl.coeff(row_col.first, row_col.second); + } +#if 0 + EIGEN_DEVICE_FUNC + template + inline PacketScalar packet(Index rowId, Index colId) const + { + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.template packet(row_col.first, row_col.second); + + } + + template + EIGEN_DEVICE_FUNC + inline void writePacket(Index rowId, Index colId, const PacketScalar& val) + { + const RowCol row_col = index_remap(rowId, colId); + m_argImpl.const_cast_derived().template writePacket + (row_col.first, row_col.second, val); + } + + template + EIGEN_DEVICE_FUNC + inline PacketScalar packet(Index index) const + { + const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, + RowsAtCompileTime == 1 ? index : 0); + return m_argImpl.template packet(row_col.first, row_col.second); + } + + template + EIGEN_DEVICE_FUNC + inline void writePacket(Index index, const PacketScalar& val) + { + const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, + RowsAtCompileTime == 1 ? index : 0); + return m_argImpl.template packet(row_col.first, row_col.second, val); + } +#endif +protected: + + evaluator m_argImpl; + const XprType& m_xpr; + +}; + + +///** \internal Internal implementation of dense Reshapeds in the direct access case.*/ +//template +//class ReshapedImpl_dense +// : public MapBase > //{ -// typedef Reshape ReshapeType; +// typedef Reshaped ReshapedType; // public: // -// typedef MapBase Base; -// EIGEN_DENSE_PUBLIC_INTERFACE(ReshapeType) -// EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapeImpl_dense) +// typedef MapBase Base; +// EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType) +// EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense) // // /** Column or Row constructor // */ // EIGEN_DEVICE_FUNC -// inline ReshapeImpl_dense(XprType& xpr, Index i) +// inline ReshapedImpl_dense(XprType& xpr, Index i) // : Base(internal::const_cast_ptr(&xpr.coeffRef( -// (ReshapeRows==1) && (ReshapeCols==XprType::ColsAtCompileTime) ? i : 0, -// (ReshapeRows==XprType::RowsAtCompileTime) && (ReshapeCols==1) ? i : 0)), -// ReshapeRows==1 ? 1 : xpr.rows(), -// ReshapeCols==1 ? 1 : xpr.cols()), +// (ReshapedRows==1) && (ReshapedCols==XprType::ColsAtCompileTime) ? i : 0, +// (ReshapedRows==XprType::RowsAtCompileTime) && (ReshapedCols==1) ? i : 0)), +// ReshapedRows==1 ? 1 : xpr.rows(), +// ReshapedCols==1 ? 1 : xpr.cols()), // m_xpr(xpr) // { // init(); @@ -316,7 +354,7 @@ template::HasSameStorageOrderAsXprType +// return internal::traits::HasSameStorageOrderAsXprType // ? m_xpr.innerStride() // : m_xpr.outerStride(); // } @@ -364,7 +402,7 @@ template::HasSameStorageOrderAsXprType +// m_outerStride = internal::traits::HasSameStorageOrderAsXprType // ? m_xpr.outerStride() // : m_xpr.innerStride(); // } @@ -386,6 +424,65 @@ template +EIGEN_DEVICE_FUNC +inline Reshaped DenseBase::reshaped(Index reshapeRows, Index reshapeCols) +{ + return Reshaped(derived(), reshapeRows, reshapeCols); +} + +/** This is the const version of reshaped(Index,Index). */ +template +EIGEN_DEVICE_FUNC +inline const Reshaped DenseBase::reshaped(Index reshapeRows, Index reshapeCols) const +{ + return Reshaped(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, reshaped(Index,Index) + */ +template +template +EIGEN_DEVICE_FUNC +inline Reshaped DenseBase::reshaped() +{ + return Reshaped(derived()); +} + +/** This is the const version of reshape<>(Index, Index). */ +template +template +EIGEN_DEVICE_FUNC +inline const Reshaped DenseBase::reshaped() const +{ + return Reshaped(derived()); +} + } // end namespace Eigen -#endif // EIGEN_RESHAPE_H +#endif // EIGEN_RESHAPED_H diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 4e64efe24..fca8a350e 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -84,7 +84,7 @@ template class SwapWrapper; template class Block; template class IndexedView; -template class Reshape; +template class Reshaped; template class VectorBlock; template class Transpose; diff --git a/Eigen/src/plugins/BlockMethods.h b/Eigen/src/plugins/BlockMethods.h index 53401a55a..2d5a4e507 100644 --- a/Eigen/src/plugins/BlockMethods.h +++ b/Eigen/src/plugins/BlockMethods.h @@ -1354,59 +1354,3 @@ 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()); -} - diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 315b7bece..48a28b58a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -160,10 +160,10 @@ endif() ei_add_test(redux) ei_add_test(visitor) ei_add_test(block) -ei_add_test(reshape) ei_add_test(corners) ei_add_test(symbolic_index) ei_add_test(indexed_view) +ei_add_test(reshape) ei_add_test(swap) ei_add_test(resize) ei_add_test(conservative_resize) diff --git a/test/reshape.cpp b/test/reshape.cpp index 0298a2fe4..e2c045aa6 100644 --- a/test/reshape.cpp +++ b/test/reshape.cpp @@ -15,35 +15,36 @@ using Eigen::MatrixXi; // just test a 4x4 matrix, enumerate all combination manually, // so I don't have to do template-meta-programming here. template -void reshape_all_size(MatType m) { +void reshape_all_size(MatType m) +{ typedef Eigen::Map MapMat; // dynamic - VERIFY_IS_EQUAL((m.template reshape( 1, 16)), MapMat(m.data(), 1, 16)); - VERIFY_IS_EQUAL((m.template reshape( 2, 8)), MapMat(m.data(), 2, 8)); - VERIFY_IS_EQUAL((m.template reshape( 4, 4)), MapMat(m.data(), 4, 4)); - VERIFY_IS_EQUAL((m.template reshape( 8, 2)), MapMat(m.data(), 8, 2)); - VERIFY_IS_EQUAL((m.template reshape(16, 1)), MapMat(m.data(), 16, 1)); + VERIFY_IS_EQUAL((m.reshaped( 1, 16)), MapMat(m.data(), 1, 16)); + VERIFY_IS_EQUAL((m.reshaped( 2, 8)), MapMat(m.data(), 2, 8)); + VERIFY_IS_EQUAL((m.reshaped( 4, 4)), MapMat(m.data(), 4, 4)); + VERIFY_IS_EQUAL((m.reshaped( 8, 2)), MapMat(m.data(), 8, 2)); + VERIFY_IS_EQUAL((m.reshaped(16, 1)), MapMat(m.data(), 16, 1)); // static - VERIFY_IS_EQUAL((m.template reshape< 1, 16>()), MapMat(m.data(), 1, 16)); - VERIFY_IS_EQUAL((m.template reshape< 2, 8>()), MapMat(m.data(), 2, 8)); - VERIFY_IS_EQUAL((m.template reshape< 4, 4>()), MapMat(m.data(), 4, 4)); - VERIFY_IS_EQUAL((m.template reshape< 8, 2>()), MapMat(m.data(), 8, 2)); - VERIFY_IS_EQUAL((m.template reshape<16, 1>()), MapMat(m.data(), 16, 1)); + VERIFY_IS_EQUAL((m.template reshaped< 1, 16>()), MapMat(m.data(), 1, 16)); + VERIFY_IS_EQUAL((m.template reshaped< 2, 8>()), MapMat(m.data(), 2, 8)); + VERIFY_IS_EQUAL((m.template reshaped< 4, 4>()), MapMat(m.data(), 4, 4)); + VERIFY_IS_EQUAL((m.template reshaped< 8, 2>()), MapMat(m.data(), 8, 2)); + VERIFY_IS_EQUAL((m.template reshaped<16, 1>()), MapMat(m.data(), 16, 1)); // reshape chain VERIFY_IS_EQUAL( (m - .template reshape( 1, 16) - .template reshape< 2, 8>() - .template reshape(16, 1) - .template reshape< 8, 2>() - .template reshape( 2, 8) - .template reshape< 1, 16>() - .template reshape( 4, 4) - .template reshape<16, 1>() - .template reshape( 8, 2) - .template reshape< 4, 4>() + . reshaped( 1, 16) + .template reshaped< 2, 8>() + . reshaped(16, 1) + .template reshaped< 8, 2>() + . reshaped( 2, 8) + .template reshaped< 1, 16>() + . reshaped( 4, 4) + .template reshaped<16, 1>() + . reshaped( 8, 2) + .template reshaped< 4, 4>() ), MapMat(m.data(), 4, 4) );