diff options
-rw-r--r-- | Eigen/Core | 2 | ||||
-rw-r--r-- | Eigen/src/Core/DenseBase.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/Reshaped.h | 453 | ||||
-rw-r--r-- | Eigen/src/Core/util/Constants.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/util/ForwardDeclarations.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/util/ReshapedHelper.h | 46 | ||||
-rw-r--r-- | Eigen/src/plugins/ReshapedMethods.h | 120 | ||||
-rw-r--r-- | doc/examples/class_FixedReshaped.cpp | 22 | ||||
-rw-r--r-- | doc/examples/class_Reshaped.cpp | 23 | ||||
-rw-r--r-- | doc/snippets/MatrixBase_reshaped_all.cpp | 4 | ||||
-rw-r--r-- | doc/snippets/MatrixBase_reshaped_auto.cpp | 4 | ||||
-rw-r--r-- | doc/snippets/MatrixBase_reshaped_fixed.cpp | 3 | ||||
-rw-r--r-- | doc/snippets/MatrixBase_reshaped_int_int.cpp | 3 | ||||
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/reshape.cpp | 183 |
15 files changed, 868 insertions, 0 deletions
diff --git a/Eigen/Core b/Eigen/Core index 080511fc9..7347a2480 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -222,6 +222,7 @@ using std::ptrdiff_t; #endif #include "src/Core/util/IndexedViewHelper.h" +#include "src/Core/util/ReshapedHelper.h" #include "src/Core/ArithmeticSequence.h" #include "src/Core/IO.h" #include "src/Core/DenseCoeffsBase.h" @@ -265,6 +266,7 @@ using std::ptrdiff_t; #include "src/Core/Block.h" #include "src/Core/VectorBlock.h" #include "src/Core/IndexedView.h" +#include "src/Core/Reshaped.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 8b994f35c..0c0ea95f4 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -579,6 +579,7 @@ template<typename Derived> class DenseBase # include "../plugins/CommonCwiseUnaryOps.h" # include "../plugins/BlockMethods.h" # include "../plugins/IndexedViewMethods.h" +# include "../plugins/ReshapedMethods.h" # ifdef EIGEN_DENSEBASE_PLUGIN # include EIGEN_DENSEBASE_PLUGIN # endif diff --git a/Eigen/src/Core/Reshaped.h b/Eigen/src/Core/Reshaped.h new file mode 100644 index 000000000..aaa5a5739 --- /dev/null +++ b/Eigen/src/Core/Reshaped.h @@ -0,0 +1,453 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2017 Gael Guennebaud <gael.guennebaud@inria.fr> +// Copyright (C) 2014 yoco <peter.xiau@gmail.com> +// +// 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_RESHAPED_H +#define EIGEN_RESHAPED_H + +namespace Eigen { + +/** \class Reshaped + * \ingroup Core_Module + * + * \brief Expression of a fixed-size or dynamic-size reshape + * + * \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 can be ColMajor or RowMajor, default is ColMajor. + * + * This class represents an expression of either a fixed-size or dynamic-size reshape. + * It is the return type of DenseBase::reshaped(NRowsType,NColsType) and + * most of the time this is the only way it is used. + * + * However, in C++98, if you want to directly maniputate reshaped expressions, + * for instance if you want to write a function returning such an expression, you + * will need to use this class. In C++11, it is advised to use the \em auto + * keyword for such use cases. + * + * Here is an example illustrating the dynamic case: + * \include class_Reshaped.cpp + * Output: \verbinclude class_Reshaped.out + * + * Here is an example illustrating the fixed-size case: + * \include class_FixedReshaped.cpp + * Output: \verbinclude class_FixedReshaped.out + * + * \sa DenseBase::reshaped(NRowsType,NColsType) + */ + +namespace internal { +template<typename XprType, int Rows, int Cols, int Order> +struct traits<Reshaped<XprType, Rows, Cols, Order> > : traits<XprType> +{ + typedef typename traits<XprType>::Scalar Scalar; + typedef typename traits<XprType>::StorageKind StorageKind; + typedef typename traits<XprType>::XprKind XprKind; + enum{ + MatrixRows = traits<XprType>::RowsAtCompileTime, + MatrixCols = traits<XprType>::ColsAtCompileTime, + RowsAtCompileTime = Rows, + ColsAtCompileTime = Cols, + MaxRowsAtCompileTime = Rows, + MaxColsAtCompileTime = Cols, + XpxStorageOrder = ((int(traits<XprType>::Flags) & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor, + ReshapedStorageOrder = (RowsAtCompileTime == 1 && ColsAtCompileTime != 1) ? RowMajor + : (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ? ColMajor + : XpxStorageOrder, + HasSameStorageOrderAsXprType = (ReshapedStorageOrder == XpxStorageOrder), + InnerSize = (ReshapedStorageOrder==int(RowMajor)) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), + InnerStrideAtCompileTime = HasSameStorageOrderAsXprType + ? int(inner_stride_at_compile_time<XprType>::ret) + : Dynamic, + OuterStrideAtCompileTime = Dynamic, + + HasDirectAccess = internal::has_direct_access<XprType>::ret + && (Order==int(XpxStorageOrder)) + && ((evaluator<XprType>::Flags&LinearAccessBit)==LinearAccessBit), + + MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0) + && (InnerStrideAtCompileTime == 1) + ? PacketAccessBit : 0, + //MaskAlignedBit = ((OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ? AlignedBit : 0, + FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, + FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0, + FlagsRowMajorBit = (ReshapedStorageOrder==int(RowMajor)) ? RowMajorBit : 0, + FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0, + Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) | MaskPacketAccessBit), + + Flags = (Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit | FlagsDirectAccessBit) + }; +}; + +template<typename XprType, int Rows, int Cols, int Order, bool HasDirectAccess> class ReshapedImpl_dense; + +} // end namespace internal + +template<typename XprType, int Rows, int Cols, int Order, typename StorageKind> class ReshapedImpl; + +template<typename XprType, int Rows, int Cols, int Order> class Reshaped + : public ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind> +{ + typedef ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind> Impl; + public: + //typedef typename Impl::Base Base; + typedef Impl Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(Reshaped) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reshaped) + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC + inline Reshaped(XprType& xpr) + : Impl(xpr) + { + EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE) + eigen_assert(Rows * Cols == xpr.rows() * xpr.cols()); + } + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC + inline Reshaped(XprType& xpr, + Index reshapeRows, Index reshapeCols) + : Impl(xpr, reshapeRows, reshapeCols) + { + eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==reshapeRows) + && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==reshapeCols)); + eigen_assert(reshapeRows * reshapeCols == xpr.rows() * xpr.cols()); + } +}; + +// 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<typename XprType, int Rows, int Cols, int Order> +class ReshapedImpl<XprType, Rows, Cols, Order, Dense> + : public internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,internal::traits<Reshaped<XprType,Rows,Cols,Order> >::HasDirectAccess> +{ + typedef internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,internal::traits<Reshaped<XprType,Rows,Cols,Order> >::HasDirectAccess> Impl; + public: + typedef Impl Base; + 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 Reshaped in the general case. */ +template<typename XprType, int Rows, int Cols, int Order> +class ReshapedImpl_dense<XprType,Rows,Cols,Order,false> + : public internal::dense_xpr_base<Reshaped<XprType, Rows, Cols, Order> >::type +{ + typedef Reshaped<XprType, Rows, Cols, Order> ReshapedType; + public: + + typedef typename internal::dense_xpr_base<ReshapedType>::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense) + + typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested; + typedef typename internal::remove_all<XprType>::type NestedExpression; + + class InnerIterator; + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC + inline ReshapedImpl_dense(XprType& xpr) + : m_xpr(xpr), m_rows(Rows), m_cols(Cols) + {} + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC + inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols) + : m_xpr(xpr), m_rows(nRows), m_cols(nCols) + {} + + 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() */ + EIGEN_DEVICE_FUNC inline const Scalar* data() const; + EIGEN_DEVICE_FUNC inline Index innerStride() const; + EIGEN_DEVICE_FUNC inline Index outerStride() const; + #endif + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC + const typename internal::remove_all<XprType>::type& + nestedExpression() const { return m_xpr; } + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC + typename internal::remove_reference<XprType>::type& + nestedExpression() { return m_xpr.const_cast_derived(); } + + protected: + + MatrixTypeNested m_xpr; + const internal::variable_if_dynamic<Index, Rows> m_rows; + const internal::variable_if_dynamic<Index, Cols> m_cols; +}; + + +/** \internal Internal implementation of dense Reshaped in the direct access case. */ +template<typename XprType, int Rows, int Cols, int Order> +class ReshapedImpl_dense<XprType, Rows, Cols, Order, true> + : public MapBase<Reshaped<XprType, Rows, Cols, Order> > +{ + typedef Reshaped<XprType, Rows, Cols, Order> ReshapedType; + typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested; + public: + + typedef MapBase<ReshapedType> Base; + EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense) + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC + inline ReshapedImpl_dense(XprType& xpr) + : Base(xpr.data()), m_xpr(xpr) + {} + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC + inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols) + : Base(xpr.data(), nRows, nCols), + m_xpr(xpr) + {} + + EIGEN_DEVICE_FUNC + const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const + { + return m_xpr; + } + + EIGEN_DEVICE_FUNC + XprType& nestedExpression() { return m_xpr; } + + /** \sa MapBase::innerStride() */ + EIGEN_DEVICE_FUNC + inline Index innerStride() const + { + return m_xpr.innerStride(); + } + + /** \sa MapBase::outerStride() */ + EIGEN_DEVICE_FUNC + inline Index outerStride() const + { + return ((Flags&RowMajorBit)==RowMajorBit) ? this->cols() : this->rows(); + } + + protected: + + XprTypeNested m_xpr; +}; + +// Evaluators +template<typename ArgType, int Rows, int Cols, int Order, bool HasDirectAccess> struct reshaped_evaluator; + +template<typename ArgType, int Rows, int Cols, int Order> +struct evaluator<Reshaped<ArgType, Rows, Cols, Order> > + : reshaped_evaluator<ArgType, Rows, Cols, Order, traits<Reshaped<ArgType,Rows,Cols,Order> >::HasDirectAccess> +{ + typedef Reshaped<ArgType, Rows, Cols, Order> XprType; + typedef typename XprType::Scalar Scalar; + // TODO: should check for smaller packet types + typedef typename packet_traits<Scalar>::type PacketScalar; + + enum { + CoeffReadCost = evaluator<ArgType>::CoeffReadCost, + HasDirectAccess = traits<XprType>::HasDirectAccess, + +// RowsAtCompileTime = traits<XprType>::RowsAtCompileTime, +// ColsAtCompileTime = traits<XprType>::ColsAtCompileTime, +// MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime, +// MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime, +// +// InnerStrideAtCompileTime = traits<XprType>::HasSameStorageOrderAsXprType +// ? int(inner_stride_at_compile_time<ArgType>::ret) +// : Dynamic, +// OuterStrideAtCompileTime = Dynamic, + + FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1 || HasDirectAccess) ? LinearAccessBit : 0, + FlagsRowMajorBit = (traits<XprType>::ReshapedStorageOrder==int(RowMajor)) ? RowMajorBit : 0, + FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0, + Flags0 = evaluator<ArgType>::Flags & (HereditaryBits & ~RowMajorBit), + Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit | FlagsDirectAccessBit, + + PacketAlignment = unpacket_traits<PacketScalar>::alignment, + Alignment = evaluator<ArgType>::Alignment + }; + typedef reshaped_evaluator<ArgType, Rows, Cols, Order, HasDirectAccess> reshaped_evaluator_type; + EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : reshaped_evaluator_type(xpr) + { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } +}; + +template<typename ArgType, int Rows, int Cols, int Order> +struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ false> + : evaluator_base<Reshaped<ArgType, Rows, Cols, Order> > +{ + typedef Reshaped<ArgType, Rows, Cols, Order> XprType; + + enum { + CoeffReadCost = evaluator<ArgType>::CoeffReadCost /* TODO + cost of index computations */, + + Flags = (evaluator<ArgType>::Flags & (HereditaryBits /*| LinearAccessBit | DirectAccessBit*/)), + + Alignment = 0 + }; + + EIGEN_DEVICE_FUNC explicit reshaped_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<Index, Index> RowCol; + + inline RowCol index_remap(Index rowId, Index colId) const + { + if(Order==ColMajor) + { + const Index nth_elem_idx = colId * m_xpr.rows() + rowId; + return RowCol(nth_elem_idx % m_xpr.nestedExpression().rows(), + nth_elem_idx / m_xpr.nestedExpression().rows()); + } + else + { + const Index nth_elem_idx = colId + rowId * m_xpr.cols(); + return RowCol(nth_elem_idx / m_xpr.nestedExpression().cols(), + nth_elem_idx % m_xpr.nestedExpression().cols()); + } + } + + 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<int LoadMode> + inline PacketScalar packet(Index rowId, Index colId) const + { + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second); + + } + + template<int LoadMode> + 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<Unaligned> + (row_col.first, row_col.second, val); + } + + template<int LoadMode> + 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<Unaligned>(row_col.first, row_col.second); + } + + template<int LoadMode> + 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<Unaligned>(row_col.first, row_col.second, val); + } +#endif +protected: + + evaluator<ArgType> m_argImpl; + const XprType& m_xpr; + +}; + +template<typename ArgType, int Rows, int Cols, int Order> +struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ true> +: mapbase_evaluator<Reshaped<ArgType, Rows, Cols, Order>, + typename Reshaped<ArgType, Rows, Cols, Order>::PlainObject> +{ + typedef Reshaped<ArgType, Rows, Cols, Order> XprType; + typedef typename XprType::Scalar Scalar; + + EIGEN_DEVICE_FUNC explicit reshaped_evaluator(const XprType& xpr) + : mapbase_evaluator<XprType, typename XprType::PlainObject>(xpr) + { + // TODO: for the 3.4 release, this should be turned to an internal assertion, but let's keep it as is for the beta lifetime + eigen_assert(((internal::UIntPtr(xpr.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) && "data is not aligned"); + } +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_RESHAPED_H diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index f1afb4db9..a5f63a9b5 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -339,6 +339,8 @@ enum SideType { OnTheRight = 2 }; + + /* the following used to be written as: * * struct NoChange_t {}; diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 1a48cff04..fca8a350e 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -84,6 +84,7 @@ template<typename ExpressionType> class SwapWrapper; template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false> class Block; template<typename XprType, typename RowIndices, typename ColIndices> class IndexedView; +template<typename XprType, int Rows=Dynamic, int Cols=Dynamic, int Order=0> class Reshaped; template<typename MatrixType, int Size=Dynamic> class VectorBlock; template<typename MatrixType> class Transpose; diff --git a/Eigen/src/Core/util/ReshapedHelper.h b/Eigen/src/Core/util/ReshapedHelper.h new file mode 100644 index 000000000..97370c138 --- /dev/null +++ b/Eigen/src/Core/util/ReshapedHelper.h @@ -0,0 +1,46 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> +// +// 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_RESHAPED_HELPER_H +#define EIGEN_RESHAPED_HELPER_H + +namespace Eigen { + +enum AutoSize_t { AutoSize }; +const int AutoOrder = 2; + +namespace internal { + +template<typename SizeType,typename OtherSize, int TotalSize> +struct get_compiletime_reshape_size { + enum { value = get_fixed_value<SizeType>::value }; +}; + +template<typename SizeType> +Index get_runtime_reshape_size(SizeType size, Index /*other*/, Index /*total*/) { + return internal::get_runtime_value(size); +} + +template<typename OtherSize, int TotalSize> +struct get_compiletime_reshape_size<AutoSize_t,OtherSize,TotalSize> { + enum { + other_size = get_fixed_value<OtherSize>::value, + value = (TotalSize==Dynamic || other_size==Dynamic) ? Dynamic : TotalSize / other_size }; +}; + +inline Index get_runtime_reshape_size(AutoSize_t /*size*/, Index other, Index total) { + return total/other; +} + +} + +} // end namespace Eigen + +#endif // EIGEN_RESHAPED_HELPER_H diff --git a/Eigen/src/plugins/ReshapedMethods.h b/Eigen/src/plugins/ReshapedMethods.h new file mode 100644 index 000000000..9aeb7f3ee --- /dev/null +++ b/Eigen/src/plugins/ReshapedMethods.h @@ -0,0 +1,120 @@ + +#ifdef EIGEN_PARSED_BY_DOXYGEN + +/// \returns an expression of \c *this with reshaped sizes. +/// +/// \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. +/// \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. +/// +/// Dynamic size example: \include MatrixBase_reshaped_int_int.cpp +/// Output: \verbinclude MatrixBase_reshaped_int_int.out +/// +/// The number of rows \a nRows and columns \a nCols can also be specified at compile-time by passing Eigen::fix<N>, +/// or Eigen::fix<N>(n) as arguments. In the later case, \c n plays the role of a runtime fallback value in case \c N equals Eigen::Dynamic. +/// Here is an example with a fixed number of rows and columns: +/// \include MatrixBase_reshaped_fixed.cpp +/// Output: \verbinclude MatrixBase_reshaped_fixed.out +/// +/// Finally, one of the sizes parameter can be automatically deduced from the other one by passing AutoSize as in the following example: +/// \include MatrixBase_reshaped_auto.cpp +/// Output: \verbinclude MatrixBase_reshaped_auto.out +/// AutoSize does preserve compile-time sizes when possible, i.e., when the sizes of the input are known at compile time \b and +/// that the other size is passed at compile-time using Eigen::fix<N> as above. +/// +/// \sa operator()(all), class Reshaped, fix, fix<N>(int) +/// +template<int Order = ColMajor, typename NRowsType, typename NColsType> +EIGEN_DEVICE_FUNC +inline Reshaped<Derived,...> +reshaped(NRowsType nRows, NColsType nCols); + +/** This is the const version of reshaped(NRowsType,NColsType). */ +template<int Order = ColMajor, typename NRowsType, typename NColsType> +EIGEN_DEVICE_FUNC +inline const Reshaped<const Derived,...> +reshaped(NRowsType nRows, NColsType nCols) const; + +/// \returns as expression of \c *this with columns stacked to a linear column vector +/// +/// This overload is essentially a shortcut for +/// \code this->reshape(AutoSize,fix<1>) \endcode +/// +/// Example: +/// \include MatrixBase_reshaped_all.cpp +/// Output: \verbinclude MatrixBase_reshaped_all.out +/// +/// \sa reshaped() +EIGEN_DEVICE_FUNC +inline Reshaped<Derived,SizeAtCompileTime,1> +operator()(all); + +#else + +// This file is automatically included twice to generate const and non-const versions + +#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS +#define EIGEN_RESHAPED_METHOD_CONST const +#else +#define EIGEN_RESHAPED_METHOD_CONST +#endif + +#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS + +// This part is included once + +#endif + +template<typename NRowsType, typename NColsType> +EIGEN_DEVICE_FUNC +inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, + internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value, + internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value> +reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST +{ + return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, + internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value, + internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value> + (derived(), + internal::get_runtime_reshape_size(nRows,internal::get_runtime_value(nCols),size()), + internal::get_runtime_reshape_size(nCols,internal::get_runtime_value(nRows),size())); +} + +template<int Order, typename NRowsType, typename NColsType> +EIGEN_DEVICE_FUNC +inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, + internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value, + internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value, + Order==AutoOrder?Flags&RowMajorBit:Order> +reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST +{ + return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived, + internal::get_compiletime_reshape_size<NRowsType,NColsType,SizeAtCompileTime>::value, + internal::get_compiletime_reshape_size<NColsType,NRowsType,SizeAtCompileTime>::value, + Order==AutoOrder?Flags&RowMajorBit:Order> + (derived(), + internal::get_runtime_reshape_size(nRows,internal::get_runtime_value(nCols),size()), + internal::get_runtime_reshape_size(nCols,internal::get_runtime_value(nRows),size())); +} + +// Views as linear vectors + +EIGEN_DEVICE_FUNC +inline Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,SizeAtCompileTime,1> +operator()(const Eigen::internal::all_t&) EIGEN_RESHAPED_METHOD_CONST +{ + return Reshaped<EIGEN_RESHAPED_METHOD_CONST Derived,SizeAtCompileTime,1>(derived(),size(),1); +} + +#undef EIGEN_RESHAPED_METHOD_CONST + +#ifndef EIGEN_RESHAPED_METHOD_2ND_PASS +#define EIGEN_RESHAPED_METHOD_2ND_PASS +#include "ReshapedMethods.h" +#undef EIGEN_RESHAPED_METHOD_2ND_PASS +#endif + +#endif // EIGEN_PARSED_BY_DOXYGEN diff --git a/doc/examples/class_FixedReshaped.cpp b/doc/examples/class_FixedReshaped.cpp new file mode 100644 index 000000000..b6d4085de --- /dev/null +++ b/doc/examples/class_FixedReshaped.cpp @@ -0,0 +1,22 @@ +#include <Eigen/Core> +#include <iostream> +using namespace Eigen; +using namespace std; + +template<typename Derived> +Eigen::Reshaped<Derived, 4, 2> +reshape_helper(MatrixBase<Derived>& m) +{ + return Eigen::Reshaped<Derived, 4, 2>(m.derived()); +} + +int main(int, char**) +{ + MatrixXd m(2, 4); + m << 1, 2, 3, 4, + 5, 6, 7, 8; + MatrixXd n = reshape_helper(m); + cout << "matrix m is:" << endl << m << endl; + cout << "matrix n is:" << endl << n << endl; + return 0; +} diff --git a/doc/examples/class_Reshaped.cpp b/doc/examples/class_Reshaped.cpp new file mode 100644 index 000000000..18fb45454 --- /dev/null +++ b/doc/examples/class_Reshaped.cpp @@ -0,0 +1,23 @@ +#include <Eigen/Core> +#include <iostream> +using namespace std; +using namespace Eigen; + +template<typename Derived> +const Reshaped<const Derived> +reshape_helper(const MatrixBase<Derived>& m, int rows, int cols) +{ + return Reshaped<const Derived>(m.derived(), rows, cols); +} + +int main(int, char**) +{ + MatrixXd m(3, 4); + m << 1, 4, 7, 10, + 2, 5, 8, 11, + 3, 6, 9, 12; + cout << m << endl; + Ref<const MatrixXd> n = reshape_helper(m, 2, 6); + cout << "Matrix m is:" << endl << m << endl; + cout << "Matrix n is:" << endl << n << endl; +} diff --git a/doc/snippets/MatrixBase_reshaped_all.cpp b/doc/snippets/MatrixBase_reshaped_all.cpp new file mode 100644 index 000000000..a4841834f --- /dev/null +++ b/doc/snippets/MatrixBase_reshaped_all.cpp @@ -0,0 +1,4 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m(all).transpose():" << endl << m(all).transpose() << endl; +cout << "Here is m.reshaped(fix<1>,AutoSize):" << endl << m.reshaped(fix<1>,AutoSize) << endl; diff --git a/doc/snippets/MatrixBase_reshaped_auto.cpp b/doc/snippets/MatrixBase_reshaped_auto.cpp new file mode 100644 index 000000000..59f9d3f60 --- /dev/null +++ b/doc/snippets/MatrixBase_reshaped_auto.cpp @@ -0,0 +1,4 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.reshaped(2, AutoSize):" << endl << m.reshaped(2, AutoSize) << endl; +cout << "Here is m.reshaped<RowMajor>(AutoSize, fix<8>):" << endl << m.reshaped<RowMajor>(AutoSize, fix<8>) << endl; diff --git a/doc/snippets/MatrixBase_reshaped_fixed.cpp b/doc/snippets/MatrixBase_reshaped_fixed.cpp new file mode 100644 index 000000000..3e9e2cfb6 --- /dev/null +++ b/doc/snippets/MatrixBase_reshaped_fixed.cpp @@ -0,0 +1,3 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.reshaped(fix<2>,fix<8>):" << endl << m.reshaped(fix<2>,fix<8>) << endl; diff --git a/doc/snippets/MatrixBase_reshaped_int_int.cpp b/doc/snippets/MatrixBase_reshaped_int_int.cpp new file mode 100644 index 000000000..af4ca592f --- /dev/null +++ b/doc/snippets/MatrixBase_reshaped_int_int.cpp @@ -0,0 +1,3 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.reshaped(2, 8):" << endl << m.reshaped(2, 8) << endl; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c215bfbb2..45e7abbd1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -183,6 +183,7 @@ ei_add_test(block) 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 new file mode 100644 index 000000000..da5c01183 --- /dev/null +++ b/test/reshape.cpp @@ -0,0 +1,183 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr> +// Copyright (C) 2014 yoco <peter.xiau@gmail.com> +// +// 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/. + +#include "main.h" + +template<typename T1,typename T2> +typename internal::enable_if<internal::is_same<T1,T2>::value,bool>::type +is_same_eq(const T1& a, const T2& b) +{ + return (a.array() == b.array()).all(); +} + +template <int Order,typename MatType> +void check_auto_reshape4x4(MatType m) +{ + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 1> v1( 1); + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 2> v2( 2); + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 4> v4( 4); + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 8> v8( 8); + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1:16> v16(16); + + VERIFY(is_same_eq(m.template reshaped<Order>( 1, AutoSize), m.template reshaped<Order>( 1, 16))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, 16 ), m.template reshaped<Order>( 1, 16))); + VERIFY(is_same_eq(m.template reshaped<Order>( 2, AutoSize), m.template reshaped<Order>( 2, 8))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, 8 ), m.template reshaped<Order>( 2, 8))); + VERIFY(is_same_eq(m.template reshaped<Order>( 4, AutoSize), m.template reshaped<Order>( 4, 4))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, 4 ), m.template reshaped<Order>( 4, 4))); + VERIFY(is_same_eq(m.template reshaped<Order>( 8, AutoSize), m.template reshaped<Order>( 8, 2))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, 2 ), m.template reshaped<Order>( 8, 2))); + VERIFY(is_same_eq(m.template reshaped<Order>(16, AutoSize), m.template reshaped<Order>(16, 1))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, 1 ), m.template reshaped<Order>(16, 1))); + + VERIFY(is_same_eq(m.template reshaped<Order>(fix< 1>, AutoSize), m.template reshaped<Order>(fix< 1>, v16 ))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, fix<16> ), m.template reshaped<Order>( v1, fix<16>))); + VERIFY(is_same_eq(m.template reshaped<Order>(fix< 2>, AutoSize), m.template reshaped<Order>(fix< 2>, v8 ))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, fix< 8> ), m.template reshaped<Order>( v2, fix< 8>))); + VERIFY(is_same_eq(m.template reshaped<Order>(fix< 4>, AutoSize), m.template reshaped<Order>(fix< 4>, v4 ))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, fix< 4> ), m.template reshaped<Order>( v4, fix< 4>))); + VERIFY(is_same_eq(m.template reshaped<Order>(fix< 8>, AutoSize), m.template reshaped<Order>(fix< 8>, v2 ))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, fix< 2> ), m.template reshaped<Order>( v8, fix< 2>))); + VERIFY(is_same_eq(m.template reshaped<Order>(fix<16>, AutoSize), m.template reshaped<Order>(fix<16>, v1 ))); + VERIFY(is_same_eq(m.template reshaped<Order>(AutoSize, fix< 1> ), m.template reshaped<Order>(v16, fix< 1>))); +} + +// just test a 4x4 matrix, enumerate all combination manually +template <typename MatType> +void reshape4x4(MatType m) +{ + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 1> v1( 1); + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 2> v2( 2); + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 4> v4( 4); + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1: 8> v8( 8); + internal::VariableAndFixedInt<MatType::SizeAtCompileTime==Dynamic?-1:16> v16(16); + + if((MatType::Flags&RowMajorBit)==0) + { + typedef Map<MatrixXi> MapMat; + // dynamic + 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.reshaped(fix< 1>, fix<16>), MapMat(m.data(), 1, 16)); + VERIFY_IS_EQUAL(m.reshaped(fix< 2>, fix< 8>), MapMat(m.data(), 2, 8)); + VERIFY_IS_EQUAL(m.reshaped(fix< 4>, fix< 4>), MapMat(m.data(), 4, 4)); + VERIFY_IS_EQUAL(m.reshaped(fix< 8>, fix< 2>), MapMat(m.data(), 8, 2)); + VERIFY_IS_EQUAL(m.reshaped(fix<16>, fix< 1>), MapMat(m.data(), 16, 1)); + + + // reshape chain + VERIFY_IS_EQUAL( + (m + .reshaped( 1, 16) + .reshaped(fix< 2>,fix< 8>) + .reshaped(16, 1) + .reshaped(fix< 8>,fix< 2>) + .reshaped( 2, 8) + .reshaped(fix< 1>,fix<16>) + .reshaped( 4, 4) + .reshaped(fix<16>,fix< 1>) + .reshaped( 8, 2) + .reshaped(fix< 4>,fix< 4>) + ), + MapMat(m.data(), 4, 4) + ); + } + + VERIFY(is_same_eq(m.reshaped( 1, AutoSize), m.reshaped( 1, 16))); + VERIFY(is_same_eq(m.reshaped(AutoSize, 16), m.reshaped( 1, 16))); + VERIFY(is_same_eq(m.reshaped( 2, AutoSize), m.reshaped( 2, 8))); + VERIFY(is_same_eq(m.reshaped(AutoSize, 8), m.reshaped( 2, 8))); + VERIFY(is_same_eq(m.reshaped( 4, AutoSize), m.reshaped( 4, 4))); + VERIFY(is_same_eq(m.reshaped(AutoSize, 4), m.reshaped( 4, 4))); + VERIFY(is_same_eq(m.reshaped( 8, AutoSize), m.reshaped( 8, 2))); + VERIFY(is_same_eq(m.reshaped(AutoSize, 2), m.reshaped( 8, 2))); + VERIFY(is_same_eq(m.reshaped(16, AutoSize), m.reshaped(16, 1))); + VERIFY(is_same_eq(m.reshaped(AutoSize, 1), m.reshaped(16, 1))); + + VERIFY(is_same_eq(m.reshaped(fix< 1>, AutoSize), m.reshaped(fix< 1>, v16))); + VERIFY(is_same_eq(m.reshaped(AutoSize, fix<16>), m.reshaped( v1, fix<16>))); + VERIFY(is_same_eq(m.reshaped(fix< 2>, AutoSize), m.reshaped(fix< 2>, v8))); + VERIFY(is_same_eq(m.reshaped(AutoSize, fix< 8>), m.reshaped( v2, fix< 8>))); + VERIFY(is_same_eq(m.reshaped(fix< 4>, AutoSize), m.reshaped(fix< 4>, v4))); + VERIFY(is_same_eq(m.reshaped(AutoSize, fix< 4>), m.reshaped( v4, fix< 4>))); + VERIFY(is_same_eq(m.reshaped(fix< 8>, AutoSize), m.reshaped(fix< 8>, v2))); + VERIFY(is_same_eq(m.reshaped(AutoSize, fix< 2>), m.reshaped( v8, fix< 2>))); + VERIFY(is_same_eq(m.reshaped(fix<16>, AutoSize), m.reshaped(fix<16>, v1))); + VERIFY(is_same_eq(m.reshaped(AutoSize, fix< 1>), m.reshaped(v16, fix< 1>))); + + check_auto_reshape4x4<ColMajor> (m); + check_auto_reshape4x4<RowMajor> (m); + check_auto_reshape4x4<AutoOrder>(m); + check_auto_reshape4x4<ColMajor> (m.transpose()); + check_auto_reshape4x4<ColMajor> (m.transpose()); + check_auto_reshape4x4<AutoOrder>(m.transpose()); + + VERIFY_IS_EQUAL(m.reshaped( 1, 16).data(), m.data()); + VERIFY_IS_EQUAL(m.reshaped( 1, 16).innerStride(), 1); + + VERIFY_IS_EQUAL(m.reshaped( 2, 8).data(), m.data()); + VERIFY_IS_EQUAL(m.reshaped( 2, 8).innerStride(), 1); + VERIFY_IS_EQUAL(m.reshaped( 2, 8).outerStride(), 2); + + if((MatType::Flags&RowMajorBit)==0) + { + VERIFY_IS_EQUAL(m.template reshaped<ColMajor>(2,8),m.reshaped(2,8)); + VERIFY_IS_EQUAL(m.template reshaped<ColMajor>(2,8),m.template reshaped<AutoOrder>(2,8)); + VERIFY_IS_EQUAL(m.transpose().template reshaped<RowMajor>(2,8),m.transpose().template reshaped<AutoOrder>(2,8)); + } + else + { + VERIFY_IS_EQUAL(m.template reshaped<ColMajor>(2,8),m.reshaped(2,8)); + VERIFY_IS_EQUAL(m.template reshaped<RowMajor>(2,8),m.template reshaped<AutoOrder>(2,8)); + VERIFY_IS_EQUAL(m.transpose().template reshaped<ColMajor>(2,8),m.transpose().template reshaped<AutoOrder>(2,8)); + VERIFY_IS_EQUAL(m.transpose().reshaped(2,8),m.transpose().template reshaped<AutoOrder>(2,8)); + } + + MatrixXi m28r1 = m.template reshaped<RowMajor>(2,8); + MatrixXi m28r2 = m.transpose().template reshaped<ColMajor>(8,2).transpose(); + VERIFY_IS_EQUAL( m28r1, m28r2); + + VERIFY(is_same_eq(m.reshaped(v16,fix<1>), m(all))); + VERIFY_IS_EQUAL(m.reshaped(16,1), m(all)); + VERIFY_IS_EQUAL(m.reshaped(1,16), m(all).transpose()); + VERIFY_IS_EQUAL(m(all).reshaped(2,8), m.reshaped(2,8)); + VERIFY_IS_EQUAL(m(all).reshaped(4,4), m.reshaped(4,4)); + VERIFY_IS_EQUAL(m(all).reshaped(8,2), m.reshaped(8,2)); + + VERIFY(is_same_eq(m.reshaped(AutoSize,fix<1>), m(all))); + VERIFY_IS_EQUAL(m.template reshaped<RowMajor>(fix<1>,AutoSize), m.transpose()(all).transpose()); +} + +void test_reshape() +{ + typedef Matrix<int,Dynamic,Dynamic> RowMatrixXi; + typedef Matrix<int,4,4> RowMatrix4i; + MatrixXi mx = MatrixXi::Random(4, 4); + Matrix4i m4 = Matrix4i::Random(4, 4); + RowMatrixXi rmx = RowMatrixXi::Random(4, 4); + RowMatrix4i rm4 = RowMatrix4i::Random(4, 4); + + // test dynamic-size matrix + CALL_SUBTEST(reshape4x4(mx)); + // test static-size matrix + CALL_SUBTEST(reshape4x4(m4)); + // test dynamic-size const matrix + CALL_SUBTEST(reshape4x4(static_cast<const MatrixXi>(mx))); + // test static-size const matrix + CALL_SUBTEST(reshape4x4(static_cast<const Matrix4i>(m4))); + + CALL_SUBTEST(reshape4x4(rmx)); + CALL_SUBTEST(reshape4x4(rm4)); +} |