From 12c79b595fb66a2d33c94ae9e1bf33fcb06a0673 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 27 May 2021 12:15:44 +0200 Subject: [PATCH] rpacknum: replace mkfor --- src/include/map_range.cc.h | 7 ++-- src/include/ranges/container_range.h | 12 ++---- src/include/ranges/multi_range.h | 8 ++-- src/include/ranges/range_helper.h | 40 ++++++++++++++++++ src/include/ranges/rpack_num.cc.h | 63 ---------------------------- src/include/ranges/rpack_num.h | 30 ------------- src/include/xfor/exttype.h | 3 +- 7 files changed, 52 insertions(+), 111 deletions(-) diff --git a/src/include/map_range.cc.h b/src/include/map_range.cc.h index fcb2a49..91d707c 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -309,9 +309,10 @@ namespace MultiArrayTools template auto GenMapIndex::ifor(size_t step, Exprs exs) const { - return RPackNum::mkForh - (0, mIPack, mBlockSizes, OpExpr,Exprs,XSTYPE> - ( range()->map(), this, step, exs ) ); + return RangeHelper::mkFor<0> + (0, mIPack, mBlockSizes, + OpExpr,Exprs,XSTYPE> + ( range()->map(), this, step, exs )); } template diff --git a/src/include/ranges/container_range.h b/src/include/ranges/container_range.h index 34d0b3c..de606dc 100644 --- a/src/include/ranges/container_range.h +++ b/src/include/ranges/container_range.h @@ -159,15 +159,12 @@ namespace MultiArrayTools template auto ifor(size_t step, Exprs exs) const; - //-> decltype(RPackNum::mkFor(step, mIPack, mBlockSizes, exs)); template auto iforh(size_t step, Exprs exs) const; - // -> decltype(RPackNum::mkForh(step, mIPack, mBlockSizes, exs)); template auto pifor(size_t step, Exprs exs) const; - // -> decltype(RPackNum::mkPFor(step, mIPack, mBlockSizes, exs)); std::intptr_t container() const; ContainerIndex& format(const std::array& blocks); @@ -482,25 +479,22 @@ namespace MultiArrayTools template template auto ContainerIndex::ifor(size_t step, Exprs exs) const - // -> decltype(RPackNum::mkFor(step, mIPack, mBlockSizes, exs)) { - return RPackNum::mkFor(step, mIPack, mBlockSizes, exs); + return RangeHelper::mkFor<0>(step, mIPack, mBlockSizes, exs); } template template auto ContainerIndex::iforh(size_t step, Exprs exs) const - // -> decltype(RPackNum::mkForh(step, mIPack, mBlockSizes, exs)) { - return RPackNum::mkForh(step, mIPack, mBlockSizes, exs); + return RangeHelper::mkForh<0>(step, mIPack, mBlockSizes, exs); } template template auto ContainerIndex::pifor(size_t step, Exprs exs) const - // -> decltype(RPackNum::mkPFor(step, mIPack, mBlockSizes, exs)) { - return RPackNum::mkPFor(step, mIPack, mBlockSizes, exs); + return RangeHelper::mkPFor<0>(step, mIPack, mBlockSizes, exs); } template diff --git a/src/include/ranges/multi_range.h b/src/include/ranges/multi_range.h index 33e45d8..cef2e02 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -473,21 +473,21 @@ namespace MultiArrayTools template auto MultiIndex::ifor(size_t step, Exprs exs) const { - return RPackNum::mkFor(step, mIPack, mBlockSizes, exs); + return RangeHelper::mkFor<0>(step, mIPack, mBlockSizes, exs); } template template auto MultiIndex::iforh(size_t step, Exprs exs) const { - return RPackNum::mkForh(step, mIPack, mBlockSizes, exs); + return RangeHelper::mkForh<0>(step, mIPack, mBlockSizes, exs); } template template auto MultiIndex::pifor(size_t step, Exprs exs) const { - return RPackNum::mkPFor(step, mIPack, mBlockSizes, exs); + return RangeHelper::mkPFor<0>(step, mIPack, mBlockSizes, exs); } /************************* @@ -581,7 +581,6 @@ namespace MultiArrayTools return sforx_p<0,sizeof...(Indices)> ( [&](auto i) { return std::dynamic_pointer_cast(std::get(mSpace)); }, [&](auto i) { return num != i;} ); - //return RPackNum::getSub(mSpace, num); } template @@ -596,7 +595,6 @@ namespace MultiArrayTools return sfor_p<0,sizeof...(Ranges)> ( [&](auto i) { return std::get(mSpace)->size(); }, [&](auto a, auto b) { return a * b; } ); - //return RPackNum::getSize(mSpace); } template diff --git a/src/include/ranges/range_helper.h b/src/include/ranges/range_helper.h index 164cb16..40cebb1 100644 --- a/src/include/ranges/range_helper.h +++ b/src/include/ranges/range_helper.h @@ -40,6 +40,46 @@ namespace MultiArrayTools getTypeNum(res, stp); } } + + template + auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) + { + constexpr size_t S = std::tuple_size::value; + if constexpr(N < S-1){ + return std::get(ipack) + ->ifor( step*std::get(ba), mkFor(step, ipack, ba, exs) ); + } + else { + return std::get(ipack)->ifor( step*std::get(ba), exs); + } + } + + template + auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) + { + constexpr size_t S = std::tuple_size::value; + if constexpr(N < S-1){ + return std::get(ipack) + ->iforh( step*std::get(ba), mkForh(step, ipack, ba, exs) ); + } + else { + return std::get(ipack)->iforh( step*std::get(ba), exs); + } + } + + template + auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) + { + constexpr size_t S = std::tuple_size::value; + if constexpr(N < S-1){ + return std::get(ipack) + ->pifor( step*std::get(ba), mkFor(step, ipack, ba, exs) ); + // mkFor is correct here, because we want to multithread only the FIRST index!! + } + else { + return std::get(ipack)->pifor( step*std::get(ba), exs); + } + } } // namespace RangeHelper } // namespace MultiArrayTools diff --git a/src/include/ranges/rpack_num.cc.h b/src/include/ranges/rpack_num.cc.h index 4c474c9..c8ae94c 100644 --- a/src/include/ranges/rpack_num.cc.h +++ b/src/include/ranges/rpack_num.cc.h @@ -84,39 +84,6 @@ namespace MultiArrayHelper RPackNum::RangesToVec(rst, v); } - template - template - auto RPackNum::mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-N-1>(ipack) - ->ifor( 0, RPackNum::mkFor(step, ipack, ba, exs) ) ) - { - constexpr size_t NN = std::tuple_size::value-N-1; - return std::get(ipack) - ->ifor( step*std::get(ba), RPackNum::mkFor(step, ipack, ba, exs) ); - } - - template - template - auto RPackNum::mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-N-1>(ipack) - ->iforh( 0, RPackNum::mkForh(step, ipack, ba, exs) ) ) - { - constexpr size_t NN = std::tuple_size::value-N-1; - return std::get(ipack) - ->iforh( step*std::get(ba), RPackNum::mkForh(step, ipack, ba, exs) ); - } - - template - template - auto RPackNum::mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-N-1>(ipack) - ->pifor( 0, RPackNum::mkFor(step, ipack, ba, exs) ) ) - { - constexpr size_t NN = std::tuple_size::value-N-1; - return std::get(ipack) - ->pifor( step*std::get(ba), RPackNum::mkFor(step, ipack, ba, exs) ); - // mkFor is correct here, because we want to multithread only the FIRST index!! - } template template @@ -248,36 +215,6 @@ namespace MultiArrayHelper setRangeToVec(v, std::get<0>(rst)); } - template - auto RPackNum<0>::mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-1>(ipack) - ->ifor(0,exs) ) - { - constexpr size_t NN = std::tuple_size::value-1; - return std::get(ipack) - ->ifor( step*std::get(ba), exs); - } - - template - auto RPackNum<0>::mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-1>(ipack) - ->iforh(0,exs) ) - { - constexpr size_t NN = std::tuple_size::value-1; - return std::get(ipack) - ->iforh( step*std::get(ba), exs); - } - - template - auto RPackNum<0>::mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-1>(ipack) - ->pifor(0,exs) ) - { - constexpr size_t NN = std::tuple_size::value-1; - return std::get(ipack) - ->pifor( step*std::get(ba), exs); - } - template inline void RPackNum<0>::getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx) { diff --git a/src/include/ranges/rpack_num.h b/src/include/ranges/rpack_num.h index 3459c3b..9527116 100644 --- a/src/include/ranges/rpack_num.h +++ b/src/include/ranges/rpack_num.h @@ -125,21 +125,6 @@ namespace MultiArrayHelper static inline void RangesToVec(const std::tuple...>& rst, vector& v); - template - static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-N-1>(ipack) - ->ifor( 0, RPackNum::mkFor(step, ipack, ba, exs) ) ); - - template - static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-N-1>(ipack) - ->iforh( 0, RPackNum::mkForh(step, ipack, ba, exs) ) ); - - template - static auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-N-1>(ipack) - ->pifor( 0, RPackNum::mkFor(step, ipack, ba, exs) ) ); - template static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx); @@ -200,21 +185,6 @@ namespace MultiArrayHelper static inline void RangesToVec(const std::tuple...>& rst, vector >& v); - template - static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-1>(ipack) - ->ifor(0,exs) ); - - template - static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-1>(ipack) - ->iforh(0,exs) ); - - template - static auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs) - -> decltype(std::get::value-1>(ipack) - ->pifor(0,exs) ); - template static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx); diff --git a/src/include/xfor/exttype.h b/src/include/xfor/exttype.h index 9dd7c07..a4b6a3a 100644 --- a/src/include/xfor/exttype.h +++ b/src/include/xfor/exttype.h @@ -270,7 +270,8 @@ namespace MultiArrayHelper DExtTX() { mDExt = std::make_shared>(); } DExtTX(const DExtTX& in) : mNext(in.mNext) { mDExt = in.mDExt->deepCopy(); } - DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {} + DExtTX(DExtTX&& in) : mNext(in.mNext) + { mDExt = in.mDExt->deepCopy(); } DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; } DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; } explicit DExtTX(const DExt& in) : mDExt(in) {}