diff --git a/src/include/map_range.cc.h b/src/include/map_range.cc.h index 91d707c..9b28667 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -175,10 +175,7 @@ namespace MultiArrayTools template GenMapIndex& GenMapIndex::operator()(const std::shared_ptr&... indices) { - //RPackNum::swapIndices(mIPack, indices...); - //RPackNum::setIndexPack(mIPack, IB::mPos); return (*this)(std::make_tuple(indices...)); - //return *this; } template @@ -186,7 +183,6 @@ namespace MultiArrayTools { sfor_pn<0,sizeof...(Indices)> ( [&](auto i) { std::get(mIPack) = std::get(indices); return 0; } ); - //RPackNum::swapIndices(mIPack, indices...); RangeHelper::setIndexPack(mIPack, IB::mPos); return *this; } @@ -386,7 +382,9 @@ namespace MultiArrayTools bool check = false; for(auto& x: MapRangeFactoryProductMap::mAleadyCreated){ if(x.second.size() == sizeof...(Ranges)){ - check = RPackNum::checkIfCreated(ptp, x.second); + check = sfor_p<0,sizeof...(Ranges)> + ( [&](auto i) { return reinterpret_cast( std::get(ptp).get() ) == x.second[i]; }, + [&](auto a, auto b) { return a and b; } ); if(check){ out = x.first; break; @@ -395,7 +393,8 @@ namespace MultiArrayTools } if(not check){ vector pv(sizeof...(Ranges)); - RPackNum::RangesToVec(ptp, pv); + sfor_pn<0,sizeof...(Ranges)> + ( [&](auto i) { pv[i] = reinterpret_cast( std::get(ptp).get() ); return 0; } ); pv.push_back( reinterpret_cast ( &std::dynamic_pointer_cast( mProd )->mMapf ) ); MapRangeFactoryProductMap::mAleadyCreated[mProd] = pv; @@ -626,7 +625,13 @@ namespace MultiArrayTools //out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); - RPackNum::fillRangeDataVec(out, mSpace); + sfor_pn<0,sizeof...(Ranges)> + ( [&](auto i) { + vector part = std::get(mSpace)->data(); + out.insert(out.end(), part.begin(), part.end()); + return 0; + } ); + //RPackNum::fillRangeDataVec(out, mSpace); return out; } diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index 48a5a00..175c279 100644 --- a/src/include/ranges/anonymous_range.h +++ b/src/include/ranges/anonymous_range.h @@ -171,23 +171,28 @@ namespace MultiArrayTools std::shared_ptr defaultRange(size_t size = 0); } - +namespace MultiArrayTools +{ + namespace RangeHelper + { + template <> + inline void resolveSetRange(std::shared_ptr& rp, + const vector >& orig, + size_t origpos, size_t size) + { + AnonymousRangeFactory arf; + for(size_t op = origpos; op != origpos + size; ++op){ + //VCHECK(op); + arf.append(orig[op]); + } + rp = std::dynamic_pointer_cast( arf.create() ); + } + } +} namespace MultiArrayHelper { using namespace MultiArrayTools; - template <> - inline void resolveSetRange(std::shared_ptr& rp, - const vector >& orig, - size_t origpos, size_t size) - { - AnonymousRangeFactory arf; - for(size_t op = origpos; op != origpos + size; ++op){ - //VCHECK(op); - arf.append(orig[op]); - } - rp = std::dynamic_pointer_cast( arf.create() ); - } template <> inline void setRangeToVec(vector >& v, @@ -212,7 +217,9 @@ namespace MultiArrayTools GenSingleRange::GenSingleRange(const std::tuple...>& origs) : RangeInterface() { - RPackNum::RangesToVec( origs, mOrig ); + mOrig.resize(sizeof...(RangeTypes)); + sfor_pn<0,sizeof...(RangeTypes)> + ( [&](auto i) { mOrig[i] = std::get(origs); return 0; } ); mSize = sfor_p<0,sizeof...(RangeTypes)> ( [&](auto i) { return std::get(origs)->size(); }, [&](auto a, auto b) { return a * b; } ); @@ -226,7 +233,9 @@ namespace MultiArrayTools RangeInterface() { auto rst = std::make_tuple(origs...); - RPackNum::RangesToVec( rst, mOrig ); + mOrig.resize(sizeof...(RangeTypes)); + sfor_pn<0,sizeof...(RangeTypes)> + ( [&](auto i) { mOrig[i] = std::get(rst); return 0; } ); mSize = sfor_p<0,sizeof...(RangeTypes)> ( [&](auto i) { return std::get(rst)->size(); }, [&](auto a, auto b) { return a * b; } ); @@ -245,7 +254,8 @@ namespace MultiArrayTools std::shared_ptr > GenSingleRange::scast(SIZET... sizes) const { std::tuple...> rtp; - RPackNum::resolveRangeType(mOrig, rtp, 0, sizes...); + RangeHelper::resolveRangeType<0>(mOrig, rtp, 0, sizes...); + //RPackNum::resolveRangeType(mOrig, rtp, 0, sizes...); MultiRangeFactory mrf(rtp); return std::dynamic_pointer_cast >( mrf.create() ); } diff --git a/src/include/ranges/container_range.h b/src/include/ranges/container_range.h index de606dc..fb0d9ce 100644 --- a/src/include/ranges/container_range.h +++ b/src/include/ranges/container_range.h @@ -154,9 +154,6 @@ namespace MultiArrayTools size_t getStepSize(size_t n); - std::string id() const; - void print(size_t offset); - template auto ifor(size_t step, Exprs exs) const; @@ -457,24 +454,6 @@ namespace MultiArrayTools } return mBlockSizes[n+1]; } - - template - std::string ContainerIndex::id() const - { - return std::string("con") + std::to_string(IB::mId); - } - - template - void ContainerIndex::print(size_t offset) - { - 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 diff --git a/src/include/ranges/dynamic_range.cc.h b/src/include/ranges/dynamic_range.cc.h index e5ae01f..e9b491a 100644 --- a/src/include/ranges/dynamic_range.cc.h +++ b/src/include/ranges/dynamic_range.cc.h @@ -143,7 +143,9 @@ namespace MultiArrayTools DynamicRange::DynamicRange(const std::tuple...>& origs) : RangeInterface() { - RPackNum::RangesToVec( origs, mOrig ); + mOrig.resize(sizeof...(RangeTypes)); + sfor_pn<0,sizeof...(RangeTypes)> + ( [&](auto i) { mOrig[i] = std::get(origs); return 0; } ); mSize = sfor_p<0,sizeof...(RangeTypes)> ( [&](auto i) { return std::get(origs)->size(); }, [&](auto a, auto b) { return a * b; } ); @@ -158,7 +160,9 @@ namespace MultiArrayTools RangeInterface() { auto rst = std::make_tuple(origs...); - RPackNum::RangesToVec( rst, mOrig ); + mOrig.resize(sizeof...(RangeTypes)); + sfor_pn<0,sizeof...(RangeTypes)> + ( [&](auto i) { mOrig[i] = std::get(rst); return 0; } ); mSize = sfor_p<0,sizeof...(RangeTypes)> ( [&](auto i) { return std::get(rst)->size(); }, [&](auto a, auto b) { return a * b; } ); @@ -179,7 +183,8 @@ namespace MultiArrayTools std::shared_ptr > DynamicRange::scast(SIZET... sizes) const { std::tuple...> rtp; - RPackNum::resolveRangeType(mOrig, rtp, 0, sizes...); + RangeHelper::resolveRangeType<0>(mOrig, rtp, 0, sizes...); + //RPackNum::resolveRangeType(mOrig, rtp, 0, sizes...); MultiRangeFactory mrf(rtp); return std::dynamic_pointer_cast >( mrf.create() ); } @@ -187,25 +192,33 @@ namespace MultiArrayTools } // end namespace MultiArrayTools +namespace MultiArrayTools +{ + namespace RangeHelper + { + template <> + inline void resolveSetRange(std::shared_ptr& rp, + const vector >& orig, + size_t origpos, size_t size) + { + DynamicRangeFactory arf; + for(size_t op = origpos; op != origpos + size; ++op){ + //VCHECK(op); + arf.append(orig[op]); + } + rp = std::dynamic_pointer_cast( arf.create() ); + } + + } +} + namespace MultiArrayHelper { namespace { using namespace MultiArrayTools; } - - template <> - inline void resolveSetRange(std::shared_ptr& rp, - const vector >& orig, - size_t origpos, size_t size) - { - DynamicRangeFactory arf; - for(size_t op = origpos; op != origpos + size; ++op){ - //VCHECK(op); - arf.append(orig[op]); - } - rp = std::dynamic_pointer_cast( arf.create() ); - } + template <> inline void setRangeToVec(vector >& v, diff --git a/src/include/ranges/multi_range.h b/src/include/ranges/multi_range.h index cef2e02..dd62c87 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -528,7 +528,9 @@ namespace MultiArrayTools bool check = false; for(auto& x: MultiRangeFactoryProductMap::mAleadyCreated){ if(x.second.size() == sizeof...(Ranges)){ - check = RPackNum::checkIfCreated(ptp, x.second); + check = sfor_p<0,sizeof...(Ranges)> + ( [&](auto i) { return reinterpret_cast( std::get(ptp).get() ) == x.second[i]; }, + [&](auto a, auto b) { return a and b; } ); if(check){ out = x.first; break; @@ -537,7 +539,8 @@ namespace MultiArrayTools } if(not check){ vector pv(sizeof...(Ranges)); - RPackNum::RangesToVec(ptp, pv); + sfor_pn<0,sizeof...(Ranges)> + ( [&](auto i) { pv[i] = reinterpret_cast( std::get(ptp).get() ); return 0; } ); MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv; out = mProd; } @@ -647,7 +650,13 @@ namespace MultiArrayTools //out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); - RPackNum::fillRangeDataVec(out, mSpace); + sfor_pn<0,sizeof...(Ranges)> + ( [&](auto i) { + vector part = std::get(mSpace)->data(); + out.insert(out.end(), part.begin(), part.end()); + return 0; + } ); + //RPackNum::fillRangeDataVec(out, mSpace); return out; } diff --git a/src/include/ranges/range_helper.h b/src/include/ranges/range_helper.h index 40cebb1..6c196b2 100644 --- a/src/include/ranges/range_helper.h +++ b/src/include/ranges/range_helper.h @@ -6,6 +6,14 @@ namespace MultiArrayTools { namespace RangeHelper { + template + inline void resolveSetRange(std::shared_ptr& rp, const vector >& orig, + size_t origpos, size_t size) + { + assert(size == 1); + rp = std::dynamic_pointer_cast( orig[origpos] ); // catch bad cast here!! + } + template void setIndexPack(IndexPack& iPack, size_t pos) { @@ -80,6 +88,26 @@ namespace MultiArrayTools return std::get(ipack)->pifor( step*std::get(ba), exs); } } + + template + inline void resolveRangeType(const vector >& orig, + RangeTuple& rtp, size_t off, size_t size, SIZET... sizes) + { + constexpr size_t tps = std::tuple_size::value; + ::MultiArrayTools::RangeHelper::resolveSetRange(std::get(rtp), orig, off, size); + if constexpr(N < tps-1){ + resolveRangeType(orig, rtp, off+size, sizes...); + } + } + + template + inline void resolveRangeType(const vector >& orig, + RangeTuple& rtp, size_t off, size_t size) + { + constexpr size_t tps = std::tuple_size::value; + ::MultiArrayTools::RangeHelper::resolveSetRange(std::get(rtp), orig, off, size); + } + } // namespace RangeHelper } // namespace MultiArrayTools diff --git a/src/include/ranges/rpack_num.cc.h b/src/include/ranges/rpack_num.cc.h index c8ae94c..28c737e 100644 --- a/src/include/ranges/rpack_num.cc.h +++ b/src/include/ranges/rpack_num.cc.h @@ -1,5 +1,6 @@ #include "rpack_num.h" + namespace MultiArrayHelper { using namespace MultiArrayTools; @@ -17,7 +18,7 @@ namespace MultiArrayHelper } - + /* template inline void resolveSetRange(std::shared_ptr& rp, const vector >& orig, size_t origpos, size_t size) @@ -25,6 +26,7 @@ namespace MultiArrayHelper assert(size == 1); rp = std::dynamic_pointer_cast( orig[origpos] ); // catch bad cast here!! } + */ template inline void setRangeToVec(vector >& v, @@ -41,23 +43,6 @@ namespace MultiArrayHelper return RPackNum::makePos(iPtrTup, blockSize) + std::get(iPtrTup)->pos() * std::get(blockSize); } - template - template - void RPackNum::swapIndices(Pack& ipack, const std::shared_ptr& nind, - const std::shared_ptr&... ninds) - { - std::get::value-N-1>(ipack) = nind; - RPackNum::swapIndices(ipack, ninds...); - } - - template - template - void RPackNum::swapIndices(Pack& ipack, const std::tuple...>& ninds) - { - std::get(ipack) = std::get(ninds); - RPackNum::swapIndices(ipack, ninds); - } - template template size_t RPackNum::blockSize(const std::tuple...>& pack) @@ -65,26 +50,6 @@ namespace MultiArrayHelper return std::get(pack)->max() * RPackNum::blockSize(pack); } - - template - template - inline void RPackNum::RangesToVec(const std::tuple...>& rst, - vector >& v) - { - setRangeToVec(v, std::get(rst)); - RPackNum::RangesToVec(rst, v); - } - - template - template - inline void RPackNum::RangesToVec(const std::tuple...>& rst, - vector& v) - { - v[N] = reinterpret_cast( std::get(rst).get() ); - RPackNum::RangesToVec(rst, v); - } - - template template inline void RPackNum::getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx) @@ -99,25 +64,6 @@ namespace MultiArrayHelper RPackNum::getStepSizeX(ii, j, ss, sx); } - template - template - inline void RPackNum::resolveRangeType(const vector >& orig, - RangeTuple& rtp, size_t off, size_t size, SIZET... sizes) - { - constexpr size_t tps = std::tuple_size::value; - resolveSetRange(std::get(rtp), orig, off, size); - RPackNum::resolveRangeType(orig, rtp, off+size, sizes...); - } - - template - template - inline bool RPackNum::checkIfCreated(const std::tuple...>& p, - const vector& a) - { - return reinterpret_cast( std::get(p).get() ) == a[N] and - RPackNum::checkIfCreated(p,a); - } - template template inline std::string RPackNum::getStringMeta(const MIndex& mi) @@ -125,16 +71,6 @@ namespace MultiArrayHelper return RPackNum::getStringMeta(mi) + "," + mi.template getPtr()->stringMeta(); } - template - template - inline void RPackNum::fillRangeDataVec(vector& out, - const std::tuple...>& tp) - { - vector part = std::get(tp)->data(); - out.insert(out.end(), part.begin(), part.end()); - RPackNum::fillRangeDataVec(out, tp); - } - template template inline bool RPackNum::compareSpaceTypes(const vector >& rbvec) @@ -183,38 +119,12 @@ namespace MultiArrayHelper return std::get<0>(iPtrTup)->pos() * std::get<1>(blockSize); } - template - void RPackNum<0>::swapIndices(Pack& ipack, const std::shared_ptr& nind) - { - std::get::value-1>(ipack) = nind; - } - - template - void RPackNum<0>::swapIndices(Pack& ipack, const std::tuple...>& ninds) - { - std::get<0>(ipack) = std::get<0>(ninds); - } - template size_t RPackNum<0>::blockSize(const std::tuple...>& pack) { return 1; } - template - inline void RPackNum<0>::RangesToVec(const std::tuple...>& rst, - vector& v) - { - v[0] = reinterpret_cast( std::get<0>(rst).get() );; - } - - template - inline void RPackNum<0>::RangesToVec(const std::tuple...>& rst, - vector >& v) - { - setRangeToVec(v, std::get<0>(rst)); - } - template inline void RPackNum<0>::getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx) { @@ -227,35 +137,12 @@ namespace MultiArrayHelper sx *= max; } - template - inline void RPackNum<0>::resolveRangeType(const vector >& orig, - RangeTuple& rtp, size_t off, size_t size) - { - constexpr size_t tps = std::tuple_size::value; - resolveSetRange(std::get(rtp), orig, off, size); - } - - template - inline bool RPackNum<0>::checkIfCreated(const std::tuple...>& p, - const vector& a) - { - return reinterpret_cast( std::get<0>(p).get() ) == a[0]; - } - template inline std::string RPackNum<0>::getStringMeta(const MIndex& mi) { return mi.template getPtr<0>()->stringMeta(); } - template - inline void RPackNum<0>::fillRangeDataVec(vector& out, - const std::tuple...>& tp) - { - vector part = std::get(tp)->data(); - out.insert(out.end(), part.begin(), part.end()); - } - template inline bool RPackNum<0>::compareSpaceTypes(const vector >& rbvec) { diff --git a/src/include/ranges/rpack_num.h b/src/include/ranges/rpack_num.h index 9527116..c640aaa 100644 --- a/src/include/ranges/rpack_num.h +++ b/src/include/ranges/rpack_num.h @@ -106,43 +106,16 @@ namespace MultiArrayHelper static inline size_t makePos(const std::tuple...>& iPtrTup, const std::array& blockSize); - template - static void swapIndices(Pack& ipack, const std::shared_ptr& nind, - const std::shared_ptr&... ninds); - - template - static void swapIndices(Pack& ipack, const std::tuple...>& ninds); - template static size_t blockSize(const std::tuple...>& pack); - template - static inline void RangesToVec(const std::tuple...>& rst, - vector >& v); - - template - static inline void RangesToVec(const std::tuple...>& rst, - vector& v); - template static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx); - template - static inline void resolveRangeType(const vector >& orig, - RangeTuple& rtp, size_t off, size_t size, SIZET... sizes); - - template - static inline bool checkIfCreated(const std::tuple...>& p, - const vector& a); - template static inline std::string getStringMeta(const MIndex& mi); - template - static inline void fillRangeDataVec(vector& out, - const std::tuple...>& tp); - template static inline bool compareSpaceTypes(const vector >& rbvec); @@ -168,41 +141,15 @@ namespace MultiArrayHelper static inline size_t makePos(const std::tuple...>& iPtrTup, const std::array& blockSize); - template - static void swapIndices(Pack& ipack, const std::shared_ptr& nind); - - template - static void swapIndices(Pack& ipack, const std::tuple...>& ninds); - template static size_t blockSize(const std::tuple...>& pack); - template - static inline void RangesToVec(const std::tuple...>& rst, - vector& v); - - template - static inline void RangesToVec(const std::tuple...>& rst, - vector >& v); - template static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx); - template - static inline void resolveRangeType(const vector >& orig, - RangeTuple& rtp, size_t off, size_t size); - - template - static inline bool checkIfCreated(const std::tuple...>& p, - const vector& a); - template static inline std::string getStringMeta(const MIndex& mi); - template - static inline void fillRangeDataVec(vector& out, - const std::tuple...>& tp); - template static inline bool compareSpaceTypes(const vector >& rbvec);