From 49dd9ef548116b697bda259489ad661a1366bad4 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 17 Sep 2019 14:24:01 +0200 Subject: [PATCH] map range: enable creation on arbitrary target range (of same type with real target space as sub-space) --- src/include/helper_tools.cc.h | 17 ++++++++++ src/include/helper_tools.h | 13 ++++++++ src/include/map_range.cc.h | 58 ++++++++++++++++++++++++++++++++++- src/include/map_range.h | 17 ++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/src/include/helper_tools.cc.h b/src/include/helper_tools.cc.h index 5b1fa72..d3285d8 100644 --- a/src/include/helper_tools.cc.h +++ b/src/include/helper_tools.cc.h @@ -53,6 +53,15 @@ namespace MultiArrayTools return createExplicit( mrf ); } + template + auto mkGenMapRwith(const std::shared_ptr>& outr, const std::tuple& f, + std::shared_ptr... ranges) + -> std::shared_ptr > + { + GenMapRangeFactory mrf(outr, f, ranges... ); + return createExplicit( mrf ); + } + template auto mkGenMapI(const std::tuple& f, std::shared_ptr... indices) -> decltype( getIndex( mkGenMapR( f, indices->range()... ) ) ) @@ -69,6 +78,14 @@ namespace MultiArrayTools return mkGenMapR(f, ranges... ); } + template + auto mkMapRwith(const std::shared_ptr>& outr, const std::tuple& f, + std::shared_ptr... ranges) + -> decltype( mkGenMapRwith(outr, f, ranges... ) ) + { + return mkGenMapRwith(outr, f, ranges... ); + } + template auto mkMapI(const std::tuple& f, std::shared_ptr... indices) -> decltype( mkGenMapI(f, indices... ) ) diff --git a/src/include/helper_tools.h b/src/include/helper_tools.h index 2c66148..fb7512f 100644 --- a/src/include/helper_tools.h +++ b/src/include/helper_tools.h @@ -32,6 +32,14 @@ namespace MultiArrayTools auto mkGenMapR(const std::tuple& f, std::shared_ptr... ranges) -> std::shared_ptr >; + template + using MapORType = SingleRange; + + template + auto mkGenMapRwith(const std::shared_ptr>& outr, const std::tuple& f, + std::shared_ptr... ranges) + -> std::shared_ptr >; + template auto mkGenMapI(const std::tuple& f, std::shared_ptr... indices) -> decltype( getIndex( mkGenMapR( f, indices->range()... ) ) ); @@ -40,6 +48,11 @@ namespace MultiArrayTools auto mkMapR(const std::tuple& f, std::shared_ptr... ranges) -> decltype( mkGenMapR(f, ranges... ) ); + template + auto mkMapRwith(const std::shared_ptr>& outr, const std::tuple& f, + std::shared_ptr... ranges) + -> decltype( mkGenMapRwith(outr, f, ranges... ) ); + template auto mkMapI(const std::tuple& f, std::shared_ptr... indices) -> decltype( mkGenMapI(f, indices... ) ); diff --git a/src/include/map_range.cc.h b/src/include/map_range.cc.h index 51e5e92..da601a9 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -327,6 +327,26 @@ namespace MultiArrayTools * MapRangeFactory * *************************/ + template + template + GenMapRangeFactory::GenMapRangeFactory(const std::shared_ptr& outr, + const std::tuple& mapf, + const std::shared_ptr&... rs) + { + mProd = std::shared_ptr< GenMapRange > + ( new GenMapRange( outr, mapf, rs... ) ); + } + + template + template + GenMapRangeFactory::GenMapRangeFactory(const std::shared_ptr& outr, + const std::tuple& mapf, + const typename GenMapRange::Space& st) + { + mProd = std::shared_ptr< GenMapRange > + ( new GenMapRange( outr, mapf, st ) ); + } + template template GenMapRangeFactory::GenMapRangeFactory(const std::tuple& mapf, @@ -456,7 +476,43 @@ namespace MultiArrayTools } } - + + template + template + GenMapRange::GenMapRange(const std::shared_ptr& outr, const std::tuple& mapf, + const std::shared_ptr&... rs) : + mSpace(std::make_tuple(rs...)), + mMapf(std::get<0>(mapf)), + mOutRange(outr), + mMapMult(mOutRange,0), + mMapPos(std::get<1>(mapf).size(),mOutRange->size()) + { + auto& ma = std::get<1>(mapf); + auto jj = mMapMult.begin(); + for(auto ii = ma.begin(); ii.pos() != ii.max(); ++ii){ + ++mMapMult[jj.at(ma[ii])]; + mMapPos[ii.pos()] = jj.pos(); + } + } + + template + template + GenMapRange::GenMapRange(const std::shared_ptr& outr, const std::tuple& mapf, + const Space& space) : + mSpace(space), + mMapf(std::get<0>(mapf)), + mOutRange(outr), + mMapMult(mOutRange,0), + mMapPos(std::get<1>(mapf).size(),mOutRange->size()) + { + auto& ma = std::get<1>(mapf); + auto jj = mMapMult.begin(); + for(auto ii = ma.begin(); ii.pos() != ii.max(); ++ii){ + ++mMapMult[jj.at(ma[ii])]; + mMapPos[ii.pos()] = jj.pos(); + } + } + template template GenMapRange::GenMapRange(const std::tuple& mapf, diff --git a/src/include/map_range.h b/src/include/map_range.h index 6fa38c8..a22f326 100644 --- a/src/include/map_range.h +++ b/src/include/map_range.h @@ -211,10 +211,19 @@ namespace MultiArrayTools class GenMapRangeFactory : public RangeFactoryBase { public: + typedef SingleRange ORType; typedef GenMapRange oType; GenMapRangeFactory() = delete; + template + GenMapRangeFactory(const std::shared_ptr& outr, const std::tuple& mapf, + const std::shared_ptr&... rs); + + template + GenMapRangeFactory(const std::shared_ptr& outr, const std::tuple& mapf, + const typename GenMapRange::Space& st); + template GenMapRangeFactory(const std::tuple& mapf, const std::shared_ptr&... rs); @@ -252,6 +261,14 @@ namespace MultiArrayTools GenMapRange(const GenMapRange& in) = delete; GenMapRange& operator=(const GenMapRange& in) = delete; + template + GenMapRange(const std::shared_ptr& outr, const std::tuple& mapf, + const std::shared_ptr&... rs); + + template + GenMapRange(const std::shared_ptr& outr, const std::tuple& mapf, + const Space& space); + template GenMapRange(const std::tuple& mapf, const Space& space);