From dfa8439e4d71a3b8dafc38a8419998e683f3ee96 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 19 Sep 2018 11:49:26 +0200 Subject: [PATCH] Update reshaped API to use RowMajor/ColMajor directly as integral values instead of introducing RowOrder/ColOrder types. The API changed from A.respahed(rows,cols,RowOrder) to A.template reshaped(rows,cols). --- Eigen/src/Core/Reshaped.h | 6 +- Eigen/src/Core/util/IntegralConstant.h | 5 -- Eigen/src/Core/util/ReshapedHelper.h | 1 + Eigen/src/plugins/ReshapedMethods.h | 16 +++--- test/reshape.cpp | 76 +++++++++++++------------- 5 files changed, 50 insertions(+), 54 deletions(-) diff --git a/Eigen/src/Core/Reshaped.h b/Eigen/src/Core/Reshaped.h index 56fd3519a..aaa5a5739 100644 --- a/Eigen/src/Core/Reshaped.h +++ b/Eigen/src/Core/Reshaped.h @@ -62,7 +62,7 @@ struct traits > : traits : (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ? ColMajor : XpxStorageOrder, HasSameStorageOrderAsXprType = (ReshapedStorageOrder == XpxStorageOrder), - InnerSize = (ReshapedStorageOrder==RowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), + InnerSize = (ReshapedStorageOrder==int(RowMajor)) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), InnerStrideAtCompileTime = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time::ret) : Dynamic, @@ -78,7 +78,7 @@ struct traits > : traits //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 = (ReshapedStorageOrder==RowMajor) ? RowMajorBit : 0, + FlagsRowMajorBit = (ReshapedStorageOrder==int(RowMajor)) ? RowMajorBit : 0, FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0, Flags0 = traits::Flags & ( (HereditaryBits & ~RowMajorBit) | MaskPacketAccessBit), @@ -284,7 +284,7 @@ struct evaluator > // OuterStrideAtCompileTime = Dynamic, FlagsLinearAccessBit = (traits::RowsAtCompileTime == 1 || traits::ColsAtCompileTime == 1 || HasDirectAccess) ? LinearAccessBit : 0, - FlagsRowMajorBit = (traits::ReshapedStorageOrder==RowMajor) ? RowMajorBit : 0, + FlagsRowMajorBit = (traits::ReshapedStorageOrder==int(RowMajor)) ? RowMajorBit : 0, FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0, Flags0 = evaluator::Flags & (HereditaryBits & ~RowMajorBit), Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit | FlagsDirectAccessBit, diff --git a/Eigen/src/Core/util/IntegralConstant.h b/Eigen/src/Core/util/IntegralConstant.h index 4310aada1..c7d3b1c06 100644 --- a/Eigen/src/Core/util/IntegralConstant.h +++ b/Eigen/src/Core/util/IntegralConstant.h @@ -265,11 +265,6 @@ static const auto fix(int val); #endif // EIGEN_PARSED_BY_DOXYGEN -const int AutoOrderValue = 2; -const internal::FixedInt ColOrder; -const internal::FixedInt RowOrder; -const internal::FixedInt AutoOrder; - } // end namespace Eigen #endif // EIGEN_INTEGRAL_CONSTANT_H diff --git a/Eigen/src/Core/util/ReshapedHelper.h b/Eigen/src/Core/util/ReshapedHelper.h index 7b7435205..97370c138 100644 --- a/Eigen/src/Core/util/ReshapedHelper.h +++ b/Eigen/src/Core/util/ReshapedHelper.h @@ -14,6 +14,7 @@ namespace Eigen { enum AutoSize_t { AutoSize }; +const int AutoOrder = 2; namespace internal { diff --git a/Eigen/src/plugins/ReshapedMethods.h b/Eigen/src/plugins/ReshapedMethods.h index b22d8bb32..db55cffe7 100644 --- a/Eigen/src/plugins/ReshapedMethods.h +++ b/Eigen/src/plugins/ReshapedMethods.h @@ -27,16 +27,16 @@ /// \sa operator()(placeholders::all), class Reshaped, fix, fix(int) /// #ifdef EIGEN_PARSED_BY_DOXYGEN -template +template EIGEN_DEVICE_FUNC inline Reshaped -reshaped(NRowsType nRows, NColsType nCols, OrderType order = ColOrder); +reshaped(NRowsType nRows, NColsType nCols); /** This is the const version of reshaped(NRowsType,NColsType). */ -template +template EIGEN_DEVICE_FUNC inline const Reshaped -reshaped(NRowsType nRows, NColsType nCols, OrderType order = ColOrder) const; +reshaped(NRowsType nRows, NColsType nCols) const; /// \returns as expression of \c *this with columns stacked to a linear column vector /// @@ -83,18 +83,18 @@ reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST internal::get_runtime_reshape_size(nCols,internal::get_runtime_value(nRows),size())); } -template +template EIGEN_DEVICE_FUNC inline Reshaped::value, internal::get_compiletime_reshape_size::value, - OrderType::value==AutoOrderValue?Flags&RowMajorBit:OrderType::value> -reshaped(NRowsType nRows, NColsType nCols, OrderType) EIGEN_RESHAPED_METHOD_CONST + Order==AutoOrder?Flags&RowMajorBit:Order> +reshaped(NRowsType nRows, NColsType nCols) EIGEN_RESHAPED_METHOD_CONST { return Reshaped::value, internal::get_compiletime_reshape_size::value, - OrderType::value==AutoOrderValue?Flags&RowMajorBit:OrderType::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())); diff --git a/test/reshape.cpp b/test/reshape.cpp index 8fe0b9348..77aec1f95 100644 --- a/test/reshape.cpp +++ b/test/reshape.cpp @@ -17,8 +17,8 @@ is_same_eq(const T1& a, const T2& b) return (a.array() == b.array()).all(); } -template -void check_auto_reshape4x4(MatType m,OrderType order) +template +void check_auto_reshape4x4(MatType m) { internal::VariableAndFixedInt v1( 1); internal::VariableAndFixedInt v2( 2); @@ -26,27 +26,27 @@ void check_auto_reshape4x4(MatType m,OrderType order) internal::VariableAndFixedInt v8( 8); internal::VariableAndFixedInt v16(16); - VERIFY(is_same_eq(m.reshaped( 1, AutoSize, order), m.reshaped( 1, 16, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, 16, order), m.reshaped( 1, 16, order))); - VERIFY(is_same_eq(m.reshaped( 2, AutoSize, order), m.reshaped( 2, 8, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, 8, order), m.reshaped( 2, 8, order))); - VERIFY(is_same_eq(m.reshaped( 4, AutoSize, order), m.reshaped( 4, 4, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, 4, order), m.reshaped( 4, 4, order))); - VERIFY(is_same_eq(m.reshaped( 8, AutoSize, order), m.reshaped( 8, 2, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, 2, order), m.reshaped( 8, 2, order))); - VERIFY(is_same_eq(m.reshaped(16, AutoSize, order), m.reshaped(16, 1, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, 1, order), m.reshaped(16, 1, order))); + VERIFY(is_same_eq(m.template reshaped( 1, AutoSize), m.template reshaped( 1, 16))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, 16 ), m.template reshaped( 1, 16))); + VERIFY(is_same_eq(m.template reshaped( 2, AutoSize), m.template reshaped( 2, 8))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, 8 ), m.template reshaped( 2, 8))); + VERIFY(is_same_eq(m.template reshaped( 4, AutoSize), m.template reshaped( 4, 4))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, 4 ), m.template reshaped( 4, 4))); + VERIFY(is_same_eq(m.template reshaped( 8, AutoSize), m.template reshaped( 8, 2))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, 2 ), m.template reshaped( 8, 2))); + VERIFY(is_same_eq(m.template reshaped(16, AutoSize), m.template reshaped(16, 1))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, 1 ), m.template reshaped(16, 1))); - VERIFY(is_same_eq(m.reshaped(fix< 1>, AutoSize, order), m.reshaped(fix< 1>, v16, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, fix<16>, order), m.reshaped( v1, fix<16>, order))); - VERIFY(is_same_eq(m.reshaped(fix< 2>, AutoSize, order), m.reshaped(fix< 2>, v8, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, fix< 8>, order), m.reshaped( v2, fix< 8>, order))); - VERIFY(is_same_eq(m.reshaped(fix< 4>, AutoSize, order), m.reshaped(fix< 4>, v4, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, fix< 4>, order), m.reshaped( v4, fix< 4>, order))); - VERIFY(is_same_eq(m.reshaped(fix< 8>, AutoSize, order), m.reshaped(fix< 8>, v2, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, fix< 2>, order), m.reshaped( v8, fix< 2>, order))); - VERIFY(is_same_eq(m.reshaped(fix<16>, AutoSize, order), m.reshaped(fix<16>, v1, order))); - VERIFY(is_same_eq(m.reshaped(AutoSize, fix< 1>, order), m.reshaped(v16, fix< 1>, order))); + VERIFY(is_same_eq(m.template reshaped(fix< 1>, AutoSize), m.template reshaped(fix< 1>, v16 ))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, fix<16> ), m.template reshaped( v1, fix<16>))); + VERIFY(is_same_eq(m.template reshaped(fix< 2>, AutoSize), m.template reshaped(fix< 2>, v8 ))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, fix< 8> ), m.template reshaped( v2, fix< 8>))); + VERIFY(is_same_eq(m.template reshaped(fix< 4>, AutoSize), m.template reshaped(fix< 4>, v4 ))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, fix< 4> ), m.template reshaped( v4, fix< 4>))); + VERIFY(is_same_eq(m.template reshaped(fix< 8>, AutoSize), m.template reshaped(fix< 8>, v2 ))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, fix< 2> ), m.template reshaped( v8, fix< 2>))); + VERIFY(is_same_eq(m.template reshaped(fix<16>, AutoSize), m.template reshaped(fix<16>, v1 ))); + VERIFY(is_same_eq(m.template reshaped(AutoSize, fix< 1> ), m.template reshaped(v16, fix< 1>))); } // just test a 4x4 matrix, enumerate all combination manually @@ -117,12 +117,12 @@ void reshape4x4(MatType m) 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(m,ColOrder); - check_auto_reshape4x4(m,RowOrder); - check_auto_reshape4x4(m,AutoOrder); - check_auto_reshape4x4(m.transpose(),ColOrder); - check_auto_reshape4x4(m.transpose(),RowOrder); - check_auto_reshape4x4(m.transpose(),AutoOrder); + check_auto_reshape4x4 (m); + check_auto_reshape4x4 (m); + check_auto_reshape4x4(m); + check_auto_reshape4x4 (m.transpose()); + check_auto_reshape4x4 (m.transpose()); + check_auto_reshape4x4(m.transpose()); VERIFY_IS_EQUAL(m.reshaped( 1, 16).data(), m.data()); VERIFY_IS_EQUAL(m.reshaped( 1, 16).innerStride(), 1); @@ -133,20 +133,20 @@ void reshape4x4(MatType m) if((MatType::Flags&RowMajorBit)==0) { - VERIFY_IS_EQUAL(m.reshaped(2,8,ColOrder),m.reshaped(2,8)); - VERIFY_IS_EQUAL(m.reshaped(2,8,ColOrder),m.reshaped(2,8,AutoOrder)); - VERIFY_IS_EQUAL(m.transpose().reshaped(2,8,RowOrder),m.transpose().reshaped(2,8,AutoOrder)); + VERIFY_IS_EQUAL(m.template reshaped(2,8),m.reshaped(2,8)); + VERIFY_IS_EQUAL(m.template reshaped(2,8),m.template reshaped(2,8)); + VERIFY_IS_EQUAL(m.transpose().template reshaped(2,8),m.transpose().template reshaped(2,8)); } else { - VERIFY_IS_EQUAL(m.reshaped(2,8,ColOrder),m.reshaped(2,8)); - VERIFY_IS_EQUAL(m.reshaped(2,8,RowOrder),m.reshaped(2,8,AutoOrder)); - VERIFY_IS_EQUAL(m.transpose().reshaped(2,8,ColOrder),m.transpose().reshaped(2,8,AutoOrder)); - VERIFY_IS_EQUAL(m.transpose().reshaped(2,8),m.transpose().reshaped(2,8,AutoOrder)); + VERIFY_IS_EQUAL(m.template reshaped(2,8),m.reshaped(2,8)); + VERIFY_IS_EQUAL(m.template reshaped(2,8),m.template reshaped(2,8)); + VERIFY_IS_EQUAL(m.transpose().template reshaped(2,8),m.transpose().template reshaped(2,8)); + VERIFY_IS_EQUAL(m.transpose().reshaped(2,8),m.transpose().template reshaped(2,8)); } - MatrixXi m28r1 = m.reshaped(2,8,RowOrder); - MatrixXi m28r2 = m.transpose().reshaped(8,2,ColOrder).transpose(); + MatrixXi m28r1 = m.template reshaped(2,8); + MatrixXi m28r2 = m.transpose().template reshaped(8,2).transpose(); VERIFY_IS_EQUAL( m28r1, m28r2); using placeholders::all; @@ -158,7 +158,7 @@ void reshape4x4(MatType m) 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.reshaped(fix<1>,AutoSize,RowOrder), m.transpose()(all).transpose()); + VERIFY_IS_EQUAL(m.template reshaped(fix<1>,AutoSize), m.transpose()(all).transpose()); } void test_reshape()