diff options
-rw-r--r-- | Eigen/Core | 2 | ||||
-rw-r--r-- | Eigen/src/Core/DenseBase.h | 15 | ||||
-rw-r--r-- | Eigen/src/Core/Reshaped.h (renamed from Eigen/src/Core/Reshape.h) | 63 | ||||
-rw-r--r-- | Eigen/src/plugins/ReshapedMethods.h | 46 | ||||
-rw-r--r-- | doc/snippets/MatrixBase_reshape.cpp | 3 | ||||
-rw-r--r-- | doc/snippets/MatrixBase_reshaped_fixed.cpp | 3 | ||||
-rw-r--r-- | doc/snippets/MatrixBase_reshaped_int_int.cpp (renamed from doc/snippets/MatrixBase_reshape_int_int.cpp) | 0 | ||||
-rw-r--r-- | test/reshape.cpp | 30 |
8 files changed, 68 insertions, 94 deletions
diff --git a/Eigen/Core b/Eigen/Core index e72e528a3..1174d7d16 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -473,7 +473,7 @@ using std::ptrdiff_t; #include "src/Core/Block.h" #include "src/Core/VectorBlock.h" #include "src/Core/IndexedView.h" -#include "src/Core/Reshape.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 09e958727..9cad1aa1e 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -557,20 +557,6 @@ template<typename Derived> class DenseBase } EIGEN_DEVICE_FUNC void reverseInPlace(); - EIGEN_DEVICE_FUNC inline - Reshaped<Derived> reshaped(Index nRows, Index nCols); - - EIGEN_DEVICE_FUNC inline - const Reshaped<const Derived> reshaped(Index nRows, Index nCols) const; - - template<int ReshapeRows, int ReshapeCols> - EIGEN_DEVICE_FUNC - inline Reshaped<Derived, ReshapeRows, ReshapeCols> reshaped(); - - template<int ReshapeRows, int ReshapeCols> - EIGEN_DEVICE_FUNC - inline const Reshaped<const Derived, ReshapeRows, ReshapeCols> 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) @@ -578,6 +564,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/Reshape.h b/Eigen/src/Core/Reshaped.h index 0f7d44c49..655baa2a2 100644 --- a/Eigen/src/Core/Reshape.h +++ b/Eigen/src/Core/Reshaped.h @@ -197,8 +197,8 @@ template<typename XprType, int Rows, int Cols, int Order, bool HasDirectAccess> protected: MatrixTypeNested m_xpr; - const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows; - const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols; + const internal::variable_if_dynamic<Index, Rows> m_rows; + const internal::variable_if_dynamic<Index, Cols> m_cols; }; @@ -424,65 +424,6 @@ protected: } // end namespace internal -/** \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, reshaped() - */ -template<typename Derived> -EIGEN_DEVICE_FUNC -inline Reshaped<Derived> DenseBase<Derived>::reshaped(Index reshapeRows, Index reshapeCols) -{ - return Reshaped<Derived>(derived(), reshapeRows, reshapeCols); -} - -/** This is the const version of reshaped(Index,Index). */ -template<typename Derived> -EIGEN_DEVICE_FUNC -inline const Reshaped<const Derived> DenseBase<Derived>::reshaped(Index reshapeRows, Index reshapeCols) const -{ - return Reshaped<const Derived>(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<typename Derived> -template<int ReshapeRows, int ReshapeCols> -EIGEN_DEVICE_FUNC -inline Reshaped<Derived, ReshapeRows, ReshapeCols> DenseBase<Derived>::reshaped() -{ - return Reshaped<Derived, ReshapeRows, ReshapeCols>(derived()); -} - -/** This is the const version of reshape<>(Index, Index). */ -template<typename Derived> -template<int ReshapeRows, int ReshapeCols> -EIGEN_DEVICE_FUNC -inline const Reshaped<const Derived, ReshapeRows, ReshapeCols> DenseBase<Derived>::reshaped() const -{ - return Reshaped<const Derived, ReshapeRows, ReshapeCols>(derived()); -} - } // end namespace Eigen #endif // EIGEN_RESHAPED_H diff --git a/Eigen/src/plugins/ReshapedMethods.h b/Eigen/src/plugins/ReshapedMethods.h new file mode 100644 index 000000000..20563c2f9 --- /dev/null +++ b/Eigen/src/plugins/ReshapedMethods.h @@ -0,0 +1,46 @@ + +/// \returns as 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 +/// \param nCols the number of columns in the reshaped expression, specified at either run-time or compile-time +/// \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 +/// +/// \sa class Reshaped, fix, fix<N>(int) +/// +template<typename NRowsType, typename NColsType> +EIGEN_DEVICE_FUNC +#ifndef EIGEN_PARSED_BY_DOXYGEN +inline Reshaped<Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value> +#else +inline Reshaped<Derived,...> +#endif +reshaped(NRowsType nRows, NColsType nCols) +{ + return Reshaped<Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>( + derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols)); +} + +/** This is the const version of reshaped(NRowsType,NColsType). */ +template<typename NRowsType, typename NColsType> +EIGEN_DEVICE_FUNC +#ifndef EIGEN_PARSED_BY_DOXYGEN +inline const Reshaped<const Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value> +#else +inline const Reshaped<const Derived,...> +#endif +reshaped(NRowsType nRows, NColsType nCols) const +{ + return Reshaped<const Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value>( + derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols)); +} + diff --git a/doc/snippets/MatrixBase_reshape.cpp b/doc/snippets/MatrixBase_reshape.cpp deleted file mode 100644 index 549bd1007..000000000 --- a/doc/snippets/MatrixBase_reshape.cpp +++ /dev/null @@ -1,3 +0,0 @@ -Matrix4i m = Matrix4i::Random(); -cout << "Here is the matrix m:" << endl << m << endl; -cout << "Here is m.reshape<2,8>():" << endl << m.reshape<2,8>() << endl; diff --git a/doc/snippets/MatrixBase_reshaped_fixed.cpp b/doc/snippets/MatrixBase_reshaped_fixed.cpp new file mode 100644 index 000000000..611205929 --- /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.reshape(fix<2>,fix<8>):" << endl << m.reshape(fix<2>,fix<8>) << endl; diff --git a/doc/snippets/MatrixBase_reshape_int_int.cpp b/doc/snippets/MatrixBase_reshaped_int_int.cpp index 1169cdb2d..1169cdb2d 100644 --- a/doc/snippets/MatrixBase_reshape_int_int.cpp +++ b/doc/snippets/MatrixBase_reshaped_int_int.cpp diff --git a/test/reshape.cpp b/test/reshape.cpp index e2c045aa6..37b6a007f 100644 --- a/test/reshape.cpp +++ b/test/reshape.cpp @@ -26,25 +26,25 @@ void reshape_all_size(MatType m) VERIFY_IS_EQUAL((m.reshaped(16, 1)), MapMat(m.data(), 16, 1)); // static - 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)); + 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) - .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>() + .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) ); |