From 69e4e4bf8efe527a4dc68650a1c4ad2570a253b4 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 2 Nov 2018 18:58:58 +0100 Subject: [PATCH] some fixes / utility extensions regarding extarnal usage/linking --- src/include/expressions.h | 48 +++++++++++++-------------- src/include/ranges/anonymous_range.h | 2 ++ src/include/ranges/dynamic_range.cc.h | 35 +++++++++++++++++++ src/include/ranges/dynamic_range.h | 7 ++++ src/lib/ranges/anonymous_range.cc | 7 +++- 5 files changed, 74 insertions(+), 25 deletions(-) diff --git a/src/include/expressions.h b/src/include/expressions.h index d79d6f6..dd8ba3c 100644 --- a/src/include/expressions.h +++ b/src/include/expressions.h @@ -75,10 +75,10 @@ namespace MultiArrayTools std::shared_ptr makeec(const std::shared_ptr& i); #define V_IFOR_X(Expr) \ - virtual ExpressionHolder iforx(size_t step, ExpressionHolder ex) const = 0; \ - virtual ExpressionHolder iforhx(size_t step, ExpressionHolder ex) const = 0; \ - virtual ExpressionHolder iforxi(size_t step, Expr ex) const = 0; \ - virtual ExpressionHolder iforhxi(size_t step, Expr ex) const = 0 + virtual MultiArrayTools::ExpressionHolder iforx(size_t step, MultiArrayTools::ExpressionHolder ex) const = 0; \ + virtual MultiArrayTools::ExpressionHolder iforhx(size_t step, MultiArrayTools::ExpressionHolder ex) const = 0; \ + virtual MultiArrayTools::ExpressionHolder iforxi(size_t step, Expr ex) const = 0; \ + virtual MultiArrayTools::ExpressionHolder iforhxi(size_t step, Expr ex) const = 0 #define V_IFOR_A(EC,OpF) \ V_IFOR_X(AEX_B_MM); \ @@ -103,36 +103,36 @@ namespace MultiArrayTools } private: - V_IFOR_A(EX,plus); - V_IFOR_A(EX,minus); - V_IFOR_A(EX,multiplies); - V_IFOR_A(EX,divides); + V_IFOR_A(EX,MultiArrayTools::plus); + V_IFOR_A(EX,MultiArrayTools::minus); + V_IFOR_A(EX,MultiArrayTools::multiplies); + V_IFOR_A(EX,MultiArrayTools::divides); public: template - inline ExpressionHolder ifor(size_t step, ExpressionHolder ex) const; + inline MultiArrayTools::ExpressionHolder ifor(size_t step, MultiArrayTools::ExpressionHolder ex) const; template - inline ExpressionHolder iforh(size_t step, ExpressionHolder ex) const; + inline MultiArrayTools::ExpressionHolder iforh(size_t step, MultiArrayTools::ExpressionHolder ex) const; template - inline ExpressionHolder ifori(size_t step, Expr ex) const; + inline MultiArrayTools::ExpressionHolder ifori(size_t step, Expr ex) const; template - inline ExpressionHolder iforhi(size_t step, Expr ex) const; + inline MultiArrayTools::ExpressionHolder iforhi(size_t step, Expr ex) const; }; #define D_IFOR_X(Expr,Ind) \ - ExpressionHolder iforx(size_t step, ExpressionHolder ex) const \ - { return ExpressionHolder(Ind->ifor(step, ex)); } \ - ExpressionHolder iforhx(size_t step, ExpressionHolder ex) const \ - { return ExpressionHolder(Ind->iforh(step, ex)); } \ - ExpressionHolder iforxi(size_t step, Expr ex) const \ - { return ExpressionHolder(Ind->ifor(step, ex)); } \ - ExpressionHolder iforhxi(size_t step, Expr ex) const \ - { return ExpressionHolder(Ind->iforh(step, ex)); } + MultiArrayTools::ExpressionHolder iforx(size_t step, MultiArrayTools::ExpressionHolder ex) const \ + { return MultiArrayTools::ExpressionHolder(Ind->ifor(step, ex)); } \ + MultiArrayTools::ExpressionHolder iforhx(size_t step, MultiArrayTools::ExpressionHolder ex) const \ + { return MultiArrayTools::ExpressionHolder(Ind->iforh(step, ex)); } \ + MultiArrayTools::ExpressionHolder iforxi(size_t step, Expr ex) const \ + { return MultiArrayTools::ExpressionHolder(Ind->ifor(step, ex)); } \ + MultiArrayTools::ExpressionHolder iforhxi(size_t step, Expr ex) const \ + { return MultiArrayTools::ExpressionHolder(Ind->iforh(step, ex)); } #define D_IFOR_A(EC,OpF,Ind) \ D_IFOR_X(AEX_B_MM,Ind); \ @@ -151,10 +151,10 @@ namespace MultiArrayTools std::shared_ptr mI; - D_IFOR_A(EX,plus,mI); - D_IFOR_A(EX,minus,mI); - D_IFOR_A(EX,multiplies,mI); - D_IFOR_A(EX,divides,mI); + D_IFOR_A(EX,MultiArrayTools::plus,mI); + D_IFOR_A(EX,MultiArrayTools::minus,mI); + D_IFOR_A(EX,MultiArrayTools::multiplies,mI); + D_IFOR_A(EX,MultiArrayTools::divides,mI); public: E1(const E1& in) = default; diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index ca18f9f..39e7144 100644 --- a/src/include/ranges/anonymous_range.h +++ b/src/include/ranges/anonymous_range.h @@ -88,6 +88,8 @@ namespace MultiArrayTools template std::shared_ptr > scast(SIZET... sizes) const; // save cast + const std::vector >& orig() const; + void sreplace(const std::shared_ptr in, size_t num); bool isEmpty() const; diff --git a/src/include/ranges/dynamic_range.cc.h b/src/include/ranges/dynamic_range.cc.h index 2a33be5..7e749fd 100644 --- a/src/include/ranges/dynamic_range.cc.h +++ b/src/include/ranges/dynamic_range.cc.h @@ -71,6 +71,12 @@ namespace MultiArrayTools mProd = std::shared_ptr( new DynamicRange( origs... ) ); } + template + DynamicRangeFactory::DynamicRangeFactory(const std::vector>& origs) + { + mProd = std::shared_ptr( new DynamicRange( origs ) ); + } + template template void DynamicRangeFactory::append(std::shared_ptr r) @@ -202,6 +208,16 @@ namespace MultiArrayTools return *this; } + template + DynamicIndex& DynamicIndex::operator()(const std::vector>>& ivec) + { + assert(mIVec.size() == ivec.size()); + for(size_t i = 0; i != mIVec.size(); ++i){ + mIVec[i].first = ivec[i]; + } + return *this; + } + template template DynamicIndex& DynamicIndex::operator()(const std::shared_ptr&... is) @@ -515,6 +531,20 @@ namespace MultiArrayTools } } + template + DynamicRange::DynamicRange(const std::vector>& origs) : + RangeInterface>(), + mOrig(origs) + { + mSize = 1; + for(auto& x: mOrig){ + mSize *= x->size(); + } + if(mOrig.size()){ + mEmpty = false; + } + } + template template std::shared_ptr DynamicRange::fullsub(size_t num) const @@ -532,5 +562,10 @@ namespace MultiArrayTools return std::dynamic_pointer_cast >( mrf.create() ); } + template + const std::vector >& DynamicRange::orig() const + { + return mOrig; + } } // end namespace MultiArrayTools diff --git a/src/include/ranges/dynamic_range.h b/src/include/ranges/dynamic_range.h index 8c14db9..c2413b6 100644 --- a/src/include/ranges/dynamic_range.h +++ b/src/include/ranges/dynamic_range.h @@ -177,6 +177,7 @@ namespace MultiArrayTools DynamicIndex& operator--(); DynamicIndex& operator()(const IVecT& ivec); + DynamicIndex& operator()(const std::vector>>& ivec); template DynamicIndex& operator()(const std::shared_ptr&... is); @@ -233,6 +234,8 @@ namespace MultiArrayTools template DynamicRangeFactory(std::shared_ptr... origs); + DynamicRangeFactory(const std::vector>& origs); + template void append(std::shared_ptr r); @@ -271,6 +274,8 @@ namespace MultiArrayTools template DynamicRange(std::shared_ptr... origs); + DynamicRange(const std::vector>& origs); + size_t mSize = 1; bool mEmpty = true; @@ -299,6 +304,8 @@ namespace MultiArrayTools template std::shared_ptr > scast(SIZET... sizes) const; // save cast + const std::vector >& orig() const; + void sreplace(const std::shared_ptr in, size_t num); bool isEmpty() const; diff --git a/src/lib/ranges/anonymous_range.cc b/src/lib/ranges/anonymous_range.cc index b3a06ba..2d3b368 100644 --- a/src/lib/ranges/anonymous_range.cc +++ b/src/lib/ranges/anonymous_range.cc @@ -152,7 +152,12 @@ namespace MultiArrayTools assert(mOrig[num]->size() == in->size()); mOrig[num] = in; } - + + const std::vector >& AnonymousRange::orig() const + { + return mOrig; + } + /***************** * Functions * *****************/