From 43e848635418c0a50b70d849873b5daf7dc13c16 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 7 May 2021 17:35:59 +0200 Subject: [PATCH] bugfix + continue prev com --- src/include/high_level_operation.cc.h | 118 ++++++++++---------------- src/include/map_range.cc.h | 83 ++++++------------ src/include/map_range.h | 20 +---- src/include/ranges/container_range.h | 56 ++++++++---- src/include/ranges/multi_range.h | 18 ++-- src/include/ranges/rpack_num.cc.h | 93 -------------------- src/include/ranges/rpack_num.h | 35 -------- 7 files changed, 126 insertions(+), 297 deletions(-) diff --git a/src/include/high_level_operation.cc.h b/src/include/high_level_operation.cc.h index db97d29..14643d7 100644 --- a/src/include/high_level_operation.cc.h +++ b/src/include/high_level_operation.cc.h @@ -114,82 +114,53 @@ namespace MultiArrayTools namespace { - template + template struct Create { - template - struct cx - { - template - struct ccx - { - template - static inline void - cccx(typename HighLevelOpBase::template RetT& res, - const std::array>,M>& in, - const std::shared_ptr&... inds, - const OPs&... ops, - const DOPs&... dops) - { - static_assert(N > 0, "N > 0 failed"); - auto& inn = std::get(in); - if(not inn->root()){ - auto dop = inn->create(inds...); - auto op = *dop.op.data()->mOp; - typedef decltype(op) OP; - res.appendOuter(dop); - assert(dop.op.init()); - Create::template cx::template ccx::template cccx - (res, in, inds..., op, ops..., dop, dops...); - } - else { - auto op = inn->get(); - auto vop = inn->vget(); - typedef typename std::remove_reference::type OP; - typedef typename std::remove_reference::type VOP; + template + struct ccx + { + template + static inline void + cccx(typename HighLevelOpBase::template RetT& res, + const std::array>,M>& in, + const std::shared_ptr&... inds, + const OPs&... ops, + const DOPs&... dops) + { + //static_assert(N > 0, "N > 0 failed"); + auto& inn = std::get(in); + if(not inn->root()){ + auto dop = inn->create(inds...); + auto op = *dop.op.data()->mOp; + res.appendOuter(dop); + assert(dop.op.init()); + if constexpr(N > 0){ + typedef decltype(op) OP; + Create::template ccx::template cccx + (res, in, inds..., op, ops..., dop, dops...); + } + else { + res.op = mkDynOutOp(mkFOp(op,ops...), inds...); + res.appendOuterM(dop.op,dops.op...); + } + } + else { + auto op = inn->get(); + auto vop = inn->vget(); + if constexpr(N > 0){ + typedef typename std::remove_reference::type OP; + typedef typename std::remove_reference::type VOP; if(op != nullptr){ - Create::template cx::template ccx::template cccx + Create::template ccx::template cccx (res, in, inds..., *op, ops..., dops...); } else { - Create::template cx::template ccx::template cccx + Create::template ccx::template cccx (res, in, inds..., *vop, ops..., dops...); } - } - } - }; - }; - }; - - template <> - struct Create<0> - { - template - struct cx - { - template - struct ccx - { - template - static inline void - cccx(typename HighLevelOpBase::template RetT& res, - const std::array>,M>& in, - const std::shared_ptr&... inds, - const OPs&... ops, - const DOPs&... dops) - { - auto& inn = std::get<0>(in); - if(not inn->root()){ - auto dop = inn->create(inds...); - auto op = *dop.op.data()->mOp; - res.appendOuter(dop); - res.op = mkDynOutOp(mkFOp(op,ops...), inds...); - assert(dop.op.init()); - res.appendOuterM(dop.op,dops.op...); - } - else { - auto op = inn->get(); - auto vop = inn->vget(); + } + else { if(op != nullptr){ res.op = mkDynOutOp(mkFOp(*op,ops...), inds...); } @@ -197,11 +168,12 @@ namespace MultiArrayTools res.op = mkDynOutOp(mkFOp(*vop,ops...), inds...); } res.appendOuterM(dops.op...); - } - } - }; - }; + } + } + } + }; }; + } template @@ -234,7 +206,7 @@ namespace MultiArrayTools -> typename B::template RetT { typename B::template RetT res; - Create::template cx::template ccx::template cccx + Create::template ccx::template cccx (res,mIn,inds...); return res; } diff --git a/src/include/map_range.cc.h b/src/include/map_range.cc.h index 0bcc18a..28f902d 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -87,41 +87,31 @@ namespace MultiArrayTools return std::make_shared>(mExt); } - // -> define in range_base.cc - //std::shared_ptr mkMULTI(const char** dp); - /****************** * MapIndex * ******************/ - - /* - template - MapIndex::MapIndex(const MapIndex& in) : - IndexInterface >(in) - { - RPackNum::copy(mIPack, in); - IB::mPos = RPackNum::makePos(mIPack); - } - - template - MapIndex& MapIndex::operator=(const MapIndex& in) - { - IndexI::operator=(in); - RPackNum::copy(mIPack, in); - IB::mPos = RPackNum::makePos(mIPack); - return *this; - } - */ template template GenMapIndex::GenMapIndex(const std::shared_ptr& range) : IndexInterface,typename Op::value_type>(range, 0) { - RPackNum::construct(mIPack, *range); - IB::mPos = RPackNum::makePos(mIPack); std::get(mBlockSizes) = 1; - RPackNum::initBlockSizes(mBlockSizes, mIPack); // has one more element! + sfor_mn + ( [&](auto i) { + auto r = range->template getPtr(); + std::get(mIPack) = r->beginPtr(); + *std::get(mIPack) = 0; + + std::get(mBlockSizes) = sfor_p + ( [&](auto j) { return std::get(mIPack)->max(); } , + [&](auto a, auto b) { return a * b; }); + return 0; + }); + + IB::mPos = sfor_m + ( [&](auto i) { return std::get(mIPack); }, + [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); mOutIndex = std::make_shared ( std::dynamic_pointer_cast( IB::mRangePtr )->outRange()->begin() ); } @@ -185,7 +175,18 @@ namespace MultiArrayTools template GenMapIndex& GenMapIndex::operator()(const std::shared_ptr&... indices) { - RPackNum::swapIndices(mIPack, indices...); + //RPackNum::swapIndices(mIPack, indices...); + //RPackNum::setIndexPack(mIPack, IB::mPos); + return (*this)(std::make_tuple(indices...)); + //return *this; + } + + template + GenMapIndex& GenMapIndex::operator()(const std::tuple...>& indices) + { + sfor_pn<0,sizeof...(Indices)> + ( [&](auto i) { std::get(mIPack) = std::get(indices); return 0; } ); + //RPackNum::swapIndices(mIPack, indices...); RPackNum::setIndexPack(mIPack, IB::mPos); return *this; } @@ -245,17 +246,12 @@ namespace MultiArrayTools template typename GenMapIndex::MetaType GenMapIndex::meta() const { - //MetaType metaTuple; - //RPackNum::getMetaPos(metaTuple, mIPack); - //assert(0); return mOutIndex->meta(); } template GenMapIndex& GenMapIndex::at(const MetaType& metaPos) { - //RPackNum::setMeta(mIPack, metaPos); - //IB::mPos = RPackNum::makePos(mIPack); mOutIndex->at(metaPos); IB::mPos = mOutIndex->pos(); return *this; @@ -309,30 +305,9 @@ namespace MultiArrayTools return mBlockSizes[n+1]; } - template - std::string GenMapIndex::id() const - { - return std::string("mul") + std::to_string(IB::mId); - } - - template - void GenMapIndex::print(size_t offset) const - { - if(offset == 0){ - std::cout << " === " << std::endl; - } - for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; } - std::cout << id() << "[" << reinterpret_cast(this) - << "]" << "(" << IB::mRangePtr << "): " << meta() << std::endl; - RPackNum::printIndex(mIPack, offset+1); - } - template template auto GenMapIndex::ifor(size_t step, Exprs exs) const - -> decltype(RPackNum::mkForh - (step, mIPack, mBlockSizes, OpExpr,Exprs,XSTYPE> - ( range()->map(), this, step, exs ) ) ) { return RPackNum::mkForh (0, mIPack, mBlockSizes, OpExpr,Exprs,XSTYPE> @@ -342,7 +317,6 @@ namespace MultiArrayTools template template auto GenMapIndex::pifor(size_t step, Exprs exs) const - -> decltype(ifor(step, exs)) { return ifor(step, exs); } @@ -350,7 +324,6 @@ namespace MultiArrayTools template template auto GenMapIndex::iforh(size_t step, Exprs exs) const - -> decltype(ifor(step, exs)) { return ifor(step, exs); } @@ -600,7 +573,6 @@ namespace MultiArrayTools size_t GenMapRange::size() const { return mOutRange->size(); - //return RPackNum::getSize(mSpace); } template @@ -629,7 +601,6 @@ namespace MultiArrayTools //MetaType* xtarget = reinterpret_cast(target); assert(0); return 0; - //return RPackNum::getCMeta(xtarget,pos,mSpace,cmetaSize()); } template diff --git a/src/include/map_range.h b/src/include/map_range.h index 1181a70..6bd6e4d 100644 --- a/src/include/map_range.h +++ b/src/include/map_range.h @@ -164,6 +164,7 @@ namespace MultiArrayTools // NO foreign/external controll) // Do NOT share index instances between two or more MapIndex instances GenMapIndex& operator()(const std::shared_ptr&... indices); + GenMapIndex& operator()(const std::tuple...>& indices); // ==== >>>>> STATIC POLYMORPHISM <<<<< ==== @@ -192,23 +193,14 @@ namespace MultiArrayTools size_t getStepSize(size_t n) const; - std::string id() const; - void print(size_t offset) const; - template - auto ifor(size_t step, Exprs exs) const - -> decltype(RPackNum::mkForh - (step, mIPack, mBlockSizes, OpExpr( range()->map(), this, step, exs ) ) ); - // first step arg not used! + auto ifor(size_t step, Exprs exs) const; // first step arg not used! template - auto pifor(size_t step, Exprs exs) const - -> decltype(ifor(step, exs)); // NO MULTITHREADING - + auto pifor(size_t step, Exprs exs) const; // NO MULTITHREADING template - auto iforh(size_t step, Exprs exs) const - -> decltype(ifor(step, exs)); + auto iforh(size_t step, Exprs exs) const; }; @@ -261,11 +253,7 @@ namespace MultiArrayTools typedef RangeBase RB; typedef std::tuple...> Space; typedef GenMapIndex IndexType; - //typedef GenMapRange RangeType; - //typedef SingleRange ORType; - //typedef SingleRangeFactory ORFType; typedef typename Op::value_type MetaType; - //typedef typename RangeInterface >::IndexType IndexType; protected: GenMapRange() = delete; diff --git a/src/include/ranges/container_range.h b/src/include/ranges/container_range.h index d129cdb..a32898b 100644 --- a/src/include/ranges/container_range.h +++ b/src/include/ranges/container_range.h @@ -208,10 +208,22 @@ namespace MultiArrayTools IndexInterface,std::tuple >(range, 0), mObjPtrNum(objPtrNum) { - RPackNum::construct(mIPack, *range); std::get(mBlockSizes) = 1; - RPackNum::initBlockSizes(mBlockSizes, mIPack); - IB::mPos = RPackNum::makePos(mIPack); + sfor_mn + ( [&](auto i) { + auto r = range->template getPtr(); + std::get(mIPack) = r->beginPtr(); + *std::get(mIPack) = 0; + + std::get(mBlockSizes) = sfor_p + ( [&](auto j) { return std::get(mIPack)->max(); } , + [&](auto a, auto b) { return a * b; }); + return 0; + }); + + IB::mPos = sfor_m + ( [&](auto i) { return std::get(mIPack); }, + [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); mCPos = RPackNum::makePos(mIPack, mBlockSizes); } @@ -223,9 +235,16 @@ namespace MultiArrayTools IndexInterface,std::tuple >(range, 0), mObjPtrNum(objPtrNum) { - RPackNum::construct(mIPack, *range); - mBlockSizes = blockSizes; - IB::mPos = RPackNum::makePos(mIPack); + sfor_mn + ( [&](auto i) { + auto r = range->template getPtr(); + std::get(mIPack) = r->beginPtr(); + *std::get(mIPack) = 0; + return 0; + }); + IB::mPos = sfor_m + ( [&](auto i) { return std::get(mIPack); }, + [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); mCPos = RPackNum::makePos(mIPack, mBlockSizes); mNonTrivialBlocks = true; } @@ -244,7 +263,9 @@ namespace MultiArrayTools ContainerIndex& ContainerIndex::sync() { if(mExternControl){ - IB::mPos = RPackNum::makePos(mIPack); + IB::mPos = sfor_m + ( [&](auto i) { return std::get(mIPack); }, + [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); mCPos = RPackNum::makePos(mIPack, mBlockSizes); } return *this; @@ -267,15 +288,14 @@ namespace MultiArrayTools template ContainerIndex& ContainerIndex::operator()(const std::shared_ptr&... inds) { - RPackNum::swapIndices(mIPack, inds...); - mExternControl = true; - return sync(); + return (*this)(std::make_tuple(inds...)); } template ContainerIndex& ContainerIndex::operator()(const std::tuple...>& inds) { - RPackNum::swapIndices(mIPack, inds); + sfor_pn<0,sizeof...(Indices)> + ( [&](auto i) { std::get(mIPack) = std::get(inds); return 0; } ); mExternControl = true; return sync(); } @@ -293,7 +313,9 @@ namespace MultiArrayTools ContainerIndex& ContainerIndex::operator++() { if(mExternControl){ - IB::mPos = RPackNum::makePos(mIPack); + IB::mPos = sfor_m + ( [&](auto i) { return std::get(mIPack); }, + [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); } sfor_m ( [&](auto i) { @@ -311,7 +333,9 @@ namespace MultiArrayTools ContainerIndex& ContainerIndex::operator--() { if(mExternControl){ - IB::mPos = RPackNum::makePos(mIPack); + IB::mPos = sfor_m + ( [&](auto i) { return std::get(mIPack); }, + [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); } sfor_m ( [&](auto i) { @@ -361,14 +385,16 @@ namespace MultiArrayTools typename ContainerIndex::MetaType ContainerIndex::meta() const { MetaType metaTuple; - RPackNum::getMetaPos(metaTuple, mIPack); + sfor_pn<0,sizeof...(Indices)> + ( [&](auto i) { std::get(metaTuple) = std::get(mIPack)->meta(); return 0; } ); return metaTuple; } template ContainerIndex& ContainerIndex::at(const MetaType& metaPos) { - RPackNum::setMeta(mIPack, metaPos); + sfor_pn<0,sizeof...(Indices)> + ( [&](auto i) { std::get(mIPack)->at( std::get(metaPos) ); return 0; } ); IB::mPos = RPackNum::makePos(mIPack, mBlockSizes); return *this; } diff --git a/src/include/ranges/multi_range.h b/src/include/ranges/multi_range.h index 93739d3..8f05d2a 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -247,7 +247,7 @@ namespace MultiArrayTools { sfor_p<0,sizeof...(Indices)> ( [&](auto i) { std::get(mIPack) = ci.template getPtr(); return true; } ); - IB::mPos = sfor_p<0,sizeof...(Indices)> + IB::mPos = sfor_m ( [&](auto i) { return std::get(mIPack); }, [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); return *this; @@ -271,7 +271,7 @@ namespace MultiArrayTools return 0; }); - IB::mPos = sfor_p<0,sizeof...(Indices)> + IB::mPos = sfor_m ( [&](auto i) { return std::get(mIPack); }, [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); } @@ -329,15 +329,14 @@ namespace MultiArrayTools template MultiIndex& MultiIndex::operator()(std::shared_ptr&... indices) { - RPackNum::swapIndices(mIPack, indices...); - RPackNum::setIndexPack(mIPack, IB::mPos); - return *this; + return (*this)(std::make_tuple(indices...)); } template MultiIndex& MultiIndex::operator()(const std::tuple...>& indices) { - RPackNum::swapIndices(mIPack, indices); + sfor_pn<0,sizeof...(Indices)> + ( [&](auto i) { std::get(mIPack) = std::get(indices); return 0; } ); RPackNum::setIndexPack(mIPack, IB::mPos); return *this; } @@ -411,18 +410,19 @@ namespace MultiArrayTools typename MultiIndex::MetaType MultiIndex::meta() const { MetaType metaTuple; - RPackNum::getMetaPos(metaTuple, mIPack); + sfor_pn<0,sizeof...(Indices)> + ( [&](auto i) { std::get(metaTuple) = std::get(mIPack)->meta(); return 0; } ); return metaTuple; } template MultiIndex& MultiIndex::at(const MetaType& metaPos) { - RPackNum::setMeta(mIPack, metaPos); + sfor_pn<0,sizeof...(Indices)> + ( [&](auto i) { std::get(mIPack)->at( std::get(metaPos) ); return 0; } ); IB::mPos = sfor_m ( [&](auto i) { return std::get(mIPack); }, [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); - //IB::mPos = RPackNum::makePos(mIPack); return *this; } diff --git a/src/include/ranges/rpack_num.cc.h b/src/include/ranges/rpack_num.cc.h index 5a739d0..b8bbeb0 100644 --- a/src/include/ranges/rpack_num.cc.h +++ b/src/include/ranges/rpack_num.cc.h @@ -33,15 +33,6 @@ namespace MultiArrayHelper v.insert(v.begin(), r); } - template - template - void RPackNum::initBlockSizes(std::array& bs, - std::tuple...>& ip) - { - std::get(bs) = RPackNum::blockSize(ip); - RPackNum::initBlockSizes(bs, ip); - } - template template size_t RPackNum::getSize(const RangeTuple& rt) @@ -49,23 +40,6 @@ namespace MultiArrayHelper return std::get(rt)->size() * RPackNum::getSize(rt); } - template - template - void RPackNum::getMetaPos(MetaType& target, - const IndexPack& source) - { - std::get(target) = std::get(source)->meta(); - RPackNum::getMetaPos(target, source); - } - - template - template - void RPackNum::setMeta(IndexPack& target, const MetaType& source) - { - std::get(target)->at( std::get(source) ); - RPackNum::setMeta(target, source); - } - template template inline std::shared_ptr RPackNum::getSub(const SpaceClass& space, size_t num) @@ -88,24 +62,6 @@ namespace MultiArrayHelper RPackNum::setIndexPack(iPack, (pos - ownPos) / i.max() ); } - template - template - void RPackNum::construct(std::tuple...>& ip, - const MRange& range) - { - typedef typename std::remove_reference())>::type SubRangeType; - typedef typename SubRangeType::IndexType SubIndexType; - typedef typename std::remove_reference(ip).get())>::type TypeFromIndexPack; - - static_assert(std::is_same::value, - "inconsistent types"); - - std::get(ip) = std::shared_ptr( new SubIndexType( range.template getPtr() ) ); - *std::get(ip) = 0; - //VCHECK(std::get(ip)->max()); - RPackNum::construct(ip, range); - } - template template void RPackNum::copyInst(std::tuple...>& ip, @@ -125,14 +81,6 @@ namespace MultiArrayHelper RPackNum::copyIndex(ip, ind); } - template - template - inline size_t RPackNum::makePos(const std::tuple...>& iPtrTup) - { - //const auto& idx = *std::get(iPtrTup); - return std::get(iPtrTup)->pos() + RPackNum::makePos(iPtrTup) * std::get(iPtrTup)->max(); - } - template template inline size_t RPackNum::makePos(const std::tuple...>& iPtrTup, @@ -337,32 +285,12 @@ namespace MultiArrayHelper - template - void RPackNum<0>::initBlockSizes(std::array& bs, - std::tuple...>& ip) - { - std::get<0>(bs) = RPackNum::blockSize(ip); - } - template size_t RPackNum<0>::getSize(const RangeTuple& rt) { return std::get<0>(rt)->size(); } - template - void RPackNum<0>::getMetaPos(MetaType& target, - const IndexPack& source) - { - std::get<0>(target) = std::get<0>(source)->meta(); - } - - template - void RPackNum<0>::setMeta(IndexPack& target, const MetaType& source) - { - std::get<0>(target)->at( std::get<0>( source ) ); - } - template inline std::shared_ptr RPackNum<0>::getSub(const SpaceClass& space, size_t num) { @@ -383,21 +311,6 @@ namespace MultiArrayHelper i = ownPos; } - template - void RPackNum<0>::construct(std::tuple...>& ip, - const MRange& range) - { - typedef typename std::remove_reference())>::type SubRangeType; - typedef typename SubRangeType::IndexType SubIndexType; - typedef typename std::remove_reference(ip).get())>::type TypeFromIndexPack; - - static_assert(std::is_same::value, - "inconsistent types"); - - std::get<0>(ip) = std::shared_ptr( new SubIndexType( range.template getPtr<0>() ) ); - *std::get<0>(ip) = 0; - } - template void RPackNum<0>::copyInst(std::tuple...>& ip, const IndexType& ind) @@ -413,12 +326,6 @@ namespace MultiArrayHelper std::get<0>(ip) = std::make_shared( ind.template get<0>() ) ; } - template - inline size_t RPackNum<0>::makePos(const std::tuple...>& iPtrTup) - { - return std::get<0>(iPtrTup)->pos(); - } - template inline size_t RPackNum<0>::makePos(const std::tuple...>& iPtrTup, const std::array& blockSize) diff --git a/src/include/ranges/rpack_num.h b/src/include/ranges/rpack_num.h index b324688..e37b759 100644 --- a/src/include/ranges/rpack_num.h +++ b/src/include/ranges/rpack_num.h @@ -101,30 +101,16 @@ namespace MultiArrayHelper template struct RPackNum { - template - static void initBlockSizes(std::array& bs, - std::tuple...>& ip); template static size_t getSize(const RangeTuple& rt); - template - static void getMetaPos(MetaType& target, - const IndexPack& source); - - template - static void setMeta(IndexPack& target, const MetaType& source); - template inline static std::shared_ptr getSub(const SpaceClass& space, size_t num); template static void setIndexPack(IndexPack& iPack, size_t pos); - template - static void construct(std::tuple...>& ip, - const MRange& range); - template static void copyInst(std::tuple...>& ip, const IndexType& ind); @@ -133,9 +119,6 @@ namespace MultiArrayHelper static void copyIndex(std::tuple...>& ip, const IndexType& ind); - template - static inline size_t makePos(const std::tuple...>& iPtrTup); - template static inline size_t makePos(const std::tuple...>& iPtrTup, const std::array& blockSize); @@ -222,30 +205,15 @@ namespace MultiArrayHelper struct RPackNum<0> { - template - static void initBlockSizes(std::array& bs, - std::tuple...>& ip); - template static size_t getSize(const RangeTuple& rt); - template - static void getMetaPos(MetaType& target, - const IndexPack& source); - - template - static void setMeta(IndexPack& target, const MetaType& source); - template inline static std::shared_ptr getSub(const SpaceClass& space, size_t num); template static void setIndexPack(IndexPack& iPack, size_t pos); - template - static void construct(std::tuple...>& ip, - const MRange& range); - template static void copyInst(std::tuple...>& ip, const IndexType& ind); @@ -254,9 +222,6 @@ namespace MultiArrayHelper static void copyIndex(std::tuple...>& ip, const IndexType& ind); - template - static inline size_t makePos(const std::tuple...>& iPtrTup); - template static inline size_t makePos(const std::tuple...>& iPtrTup, const std::array& blockSize);