From 5c96e47f6971c3268aecf5c7fedb08aaf3fac074 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 18 Jan 2018 23:14:49 +0100 Subject: [PATCH] +ForParam

; does not compile... --- src/xfor/for_params.h | 63 +++++++++++++++++++++++++++++++++++++++++++ src/xfor/for_utils.h | 4 +-- src/xfor/xfor.h | 44 +++++++++++++++--------------- 3 files changed, 87 insertions(+), 24 deletions(-) create mode 100644 src/xfor/for_params.h diff --git a/src/xfor/for_params.h b/src/xfor/for_params.h new file mode 100644 index 0000000..5da04b9 --- /dev/null +++ b/src/xfor/for_params.h @@ -0,0 +1,63 @@ + +#ifndef __for_params_h__ +#define __for_params_h__ + +namespace MultiArrayHelper +{ + + template + class ForParam + { + private: + size_t mVal; + P mNext; + + public: + ForParam(const ForParam& last, const ForParam& ext, size_t pos); + inline const P& next() const; + inline const size_t& val() const; + + }; + + template <> + class ForParam + { + private: + size_t mVal; + + public: + ForParam(const ForParam& last, const ForParam& ext, size_t pos); + inline const size_t& val() const; + }; + + template + ForParam

::ForParam(const ForParam& last, const ForParam& ext, size_t pos) : + mVal(last.val() + pos * ext.val()), mNext(last.next(), ext.next(), pos) {} + + template <> + ForParam::ForParam(const ForParam& last, const ForParam& ext, size_t pos) : + mVal(last.val() + pos * ext.val()) {} + + template + inline const P& ForParam

::next() const + { + return mNext; + } + + template + inline const size_t& ForParam

::val() const + { + return mVal; + } + + template <> + inline const size_t& ForParam::val() const + { + return mVal; + } + + +} // end namespace MultiArrayHelper + + +#endif diff --git a/src/xfor/for_utils.h b/src/xfor/for_utils.h index eb1d569..b706c97 100644 --- a/src/xfor/for_utils.h +++ b/src/xfor/for_utils.h @@ -17,7 +17,7 @@ namespace MultiArrayHelper struct XFPackNum { template - static ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args) + static inline ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args) { return std::move( XFPackNum::mkPos(pos, et, lt, std::get(lt) + pos * std::get(et), args...) ); } @@ -27,7 +27,7 @@ namespace MultiArrayHelper struct XFPackNum<0> { template - static ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args) + static inline ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args) { return ETuple(std::get<0>(lt) + pos * std::get<0>(et), args...); } diff --git a/src/xfor/xfor.h b/src/xfor/xfor.h index d8d4fa0..af59b1c 100644 --- a/src/xfor/xfor.h +++ b/src/xfor/xfor.h @@ -7,6 +7,7 @@ #include #include "xfor/for_utils.h" #include "xfor/for_type.h" +#include "xfor/for_params.h" namespace MultiArrayHelper { @@ -41,16 +42,18 @@ namespace MultiArrayHelper //For& operator=(const For& in) = default; const IndexClass* mIndPtr; + size_t mSPos; + size_t mMax; Expr mExpr; - decltype(mExpr.rootSteps()) mExt; + + typedef decltype(mExpr.rootSteps()) FParType; + FParType mExt; public: static size_t layer() { return Expr::layer() + 1; } static const size_t LAYER = Expr::LAYER + 1; static const size_t SIZE = std::remove_reference::type::SIZE; - - typedef decltype(mExpr.rootSteps()) ETuple; For(For&& in) = default; For& operator=(For&& in) = default; @@ -62,10 +65,10 @@ namespace MultiArrayHelper Expr&& expr); - inline void operator()(size_t mlast, const ETuple& last) const; + inline void operator()(size_t mlast, const FParType& last) const; inline void operator()(size_t mlast = 0) const; - ETuple rootSteps(std::intptr_t iPtrNum = 0) const; + FParType rootSteps(std::intptr_t iPtrNum = 0) const; }; @@ -90,7 +93,7 @@ namespace MultiArrayHelper template For::For(const std::shared_ptr& indPtr, Expr&& expr) : - mIndPtr(indPtr.get()), mExpr(expr), + mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr), mExt(expr.rootSteps( reinterpret_cast( mIndPtr.get() ))) { assert(mIndPtr != nullptr); @@ -101,7 +104,8 @@ namespace MultiArrayHelper template For::For(const IndexClass* indPtr, Expr&& expr) : - mIndPtr(indPtr), mExpr(std::forward( expr )), + mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), + mExpr(std::forward( expr )), mExt(expr.rootSteps( reinterpret_cast( mIndPtr ) )) { assert(mIndPtr != nullptr); @@ -111,15 +115,13 @@ namespace MultiArrayHelper template inline void For::operator()(size_t mlast, - const ETuple& last) const + const FParType& last) const { - auto& ind = *mIndPtr; - //std::cout << mIndPtr << std::endl; - const size_t max = ind.max(); // blocking - for(size_t pos = ind.pos(); pos != max; ++pos){ + for(size_t pos = mSPos; pos != mMax; ++pos){ //const size_t mnpos = mlast * max + pos; - const size_t mnpos = PosForward::value(mlast, max, pos); - const ETuple npos = std::move( XFPackNum::mkPos(pos, mExt, last) ); + const size_t mnpos = PosForward::value(mlast, mMax, pos); + //const FParType npos = std::move( XFPackNum::mkPos(pos, mExt, last) ); + const FParType npos(mlast, mExt, pos); mExpr(mnpos, npos); } } @@ -127,20 +129,18 @@ namespace MultiArrayHelper template inline void For::operator()(size_t mlast) const { - const ETuple last; - auto& ind = *mIndPtr; - //std::cout << mIndPtr << std::endl; - const size_t max = ind.max(); // blocking - for(size_t pos = ind.pos(); pos != max; ++pos){ + const FParType last; + for(size_t pos = mSPos; pos != mMax; ++pos){ //const size_t mnpos = mlast * max + pos; - const size_t mnpos = PosForward::value(mlast, max, pos); - const ETuple npos = std::move( XFPackNum::mkPos(pos, mExt, last) ); + const size_t mnpos = PosForward::value(mlast, mMax, pos); + //const FParType npos = std::move( XFPackNum::mkPos(pos, mExt, last) ); + const FParType npos(mlast, mExt, pos); mExpr(mnpos, npos); } } template - typename For::ETuple For::rootSteps(std::intptr_t iPtrNum) const + typename For::FParType For::rootSteps(std::intptr_t iPtrNum) const { return mExpr.rootSteps(iPtrNum); }