From 740004d16001ed3783c9dc1cd94b27bf8dffe835 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sat, 13 Jan 2018 18:07:52 +0100 Subject: [PATCH] start fixing compile errors... (NOT FINISHED) --- src/multi_array_operation.h | 65 ++++++++++++++++----- src/ranges/container_range.h | 14 ++--- src/ranges/index_base.h | 6 +- src/ranges/multi_range.h | 14 ++--- src/ranges/rpack_num.h | 22 +++---- src/ranges/single_range.h | 16 ++--- src/xfor/for_utils.h | 14 ++--- src/xfor/xfor.h | 110 ++++++++++++++++------------------- 8 files changed, 143 insertions(+), 118 deletions(-) diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index e293f7d..af12a96 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -83,21 +83,31 @@ namespace MultiArrayTools class AssignmentExpr { + private: + AssignmentExpr() = default; + //AssignmentExpr(const AssignmentExpr& in) = default; + //AssignmentExpr& operator=(const AssignmentExpr& in) = default; + + OperationMaster* mMPtr; + const OpClass* mSecPtr; + public: static size_t layer() { return 0; } + + static const size_t LAYER = 0; + static const size_t SIZE = OpClass::SIZE; + typedef decltype(mSecPtr->rootSteps()) ETuple; AssignmentExpr(OperationMaster* mPtr, const OpClass* secPtr); AssignmentExpr(AssignmentExpr&& in) = default; - AssignmentExpr& operator=(AssignmentExpr&& in) = default; + //AssignmentExpr& operator=(const AssignmentExpr&& in) = default; inline void operator()(size_t start = 0); + inline void operator()(size_t start, const ETuple& last); - private: - AssignmentExpr() = default; + ETuple rootSteps(std::intptr_t iPtrNum = 0); - OperationMaster* mMPtr; - const OpClass* mSecPtr; }; typedef T value_type; @@ -147,6 +157,7 @@ namespace MultiArrayTools typedef Block bType; static size_t rootNum() { return 1; } + static const size_t SIZE = 1; ConstOperationRoot(const MultiArrayBase& ma, const std::shared_ptr&... indices); @@ -183,6 +194,7 @@ namespace MultiArrayTools typedef MBlock bType; static size_t rootNum() { return 1; } + static const size_t SIZE = 1; OperationRoot(MutableMultiArrayBase& ma, const std::shared_ptr&... indices); @@ -223,6 +235,34 @@ namespace MultiArrayTools { return typename Op1::rootNum() + sumRootNum(); } + + template + struct RootSumN + { + template + struct rs + { + static const size_t SIZE = Op1::SIZE + RootSumN::template rs::SIZE; + }; + }; + + template <> + struct RootSumN<0> + { + template + struct rs + { + static const size_t SIZE = Op1::SIZE; + }; + }; + + + template + struct RootSum + { + static const size_t SIZE = RootSumN::template rs::SIZE; + }; + template class Operation : public OperationTemplate > @@ -236,6 +276,7 @@ namespace MultiArrayTools typedef BlockResult bType; static size_t rootNum() { return sumRootNum(); } + static const size_t SIZE = RootSum::SIZE; private: std::tuple mOps; @@ -264,7 +305,8 @@ namespace MultiArrayTools typedef BlockResult bType; static size_t rootNum() { return typename Op::rootNum(); } - + static const size_t SIZE = Op::SIZE; + private: const Op& mOp; @@ -437,18 +479,11 @@ namespace MultiArrayTools template void OperationMaster::performAssignment(std::intptr_t blockIndexNum) { +#define XX_USE_NEW_LOOP_ROUTINE_XX #ifdef XX_USE_NEW_LOOP_ROUTINE_XX // === N E W === - static const size_t TDIM = IndexType::totalDim() - typedef std::array IAT; - typedef decltype(mSecond.rootSteps()) RootStepType; - AssignmentExpr ae(this, &mSecond); - - IAT siar = mIndex->getSIndexTuple(); - std::array ee; - PackNum::mkExt(ee, siar, mSecond); - auto loop = mIndex->ifor(ee, ae); + const auto loop = mIndex->ifor(ae); loop(); #else // === O L D === diff --git a/src/ranges/container_range.h b/src/ranges/container_range.h index 9d1498b..249b512 100644 --- a/src/ranges/container_range.h +++ b/src/ranges/container_range.h @@ -89,9 +89,9 @@ namespace MultiArrayTools std::string id(); void print(size_t offset); - template - auto ifor(const Ext& ext, Exprs&& exs) const - -> decltype(RPackNum::mkFor(mIPack, ext, exs)); + template + auto ifor(Exprs&& exs) const + -> decltype(RPackNum::mkFor(mIPack, exs)); }; @@ -372,11 +372,11 @@ namespace MultiArrayTools } template - template - auto ContainerIndex::ifor(const Ext& ext, Exprs&& exs) const - -> decltype(RPackNum::mkFor(mIPack, ext, exs)) + template + auto ContainerIndex::ifor(Exprs&& exs) const + -> decltype(RPackNum::mkFor(mIPack, exs)) { - return RPackNum::mkFor(mIPack, ext, exs); + return RPackNum::mkFor(mIPack, exs); } diff --git a/src/ranges/index_base.h b/src/ranges/index_base.h index 30a392a..b5287d1 100644 --- a/src/ranges/index_base.h +++ b/src/ranges/index_base.h @@ -74,9 +74,9 @@ namespace MultiArrayTools void print(size_t offset = 0) const { THIS().print(offset); } // CHECK / IMPLEMENT !!!!!! - template - auto ifor(const Args&... args) const -> decltype(THIS().template ifor(args...)) - { return THIS().template ifor(args...); } + template + auto ifor(const Expr&& ex) const -> decltype(THIS().template ifor(ex)) + { return THIS().template ifor(ex); } private: diff --git a/src/ranges/multi_range.h b/src/ranges/multi_range.h index 9ca449d..8be899c 100644 --- a/src/ranges/multi_range.h +++ b/src/ranges/multi_range.h @@ -105,9 +105,9 @@ namespace MultiArrayTools std::string id(); void print(size_t offset); - template - auto ifor(const Ext& ext, Exprs&& exs) const - -> decltype(RPackNum::mkFor(mIPack, ext, exs)); + template + auto ifor(Exprs&& exs) const + -> decltype(RPackNum::mkFor(mIPack, exs)); }; /************************* @@ -416,11 +416,11 @@ namespace MultiArrayTools } template - template - auto MultiIndex::ifor(const Ext& ext, Exprs&& exs) const - -> decltype(RPackNum::mkFor(mIPack, ext, exs)) + template + auto MultiIndex::ifor(Exprs&& exs) const + -> decltype(RPackNum::mkFor(mIPack, exs)) { - return RPackNum::mkFor(mIPack, ext, exs); + return RPackNum::mkFor(mIPack, exs); } /************************* diff --git a/src/ranges/rpack_num.h b/src/ranges/rpack_num.h index 86a9a27..617fb75 100644 --- a/src/ranges/rpack_num.h +++ b/src/ranges/rpack_num.h @@ -14,13 +14,13 @@ namespace MultiArrayHelper template size_t mkTotalDim() { - return typename Index1::totalDim(); + return Index1::totalDim(); } template size_t mkTotalDim() { - return typename Index1::totalDim() * mkTotalDim(); + return Index1::totalDim() * mkTotalDim(); } @@ -233,13 +233,13 @@ namespace MultiArrayHelper RPackNum::buildInfoVec(out, ip, bs); } - template - static auto mkFor(const IndexPack& ipack, const Ext& ext, Exprs&& exs) + template + static auto mkFor(const IndexPack& ipack, Exprs&& exs) -> decltype(std::get::value-N>(ipack) - ->ifor(ext, RPackNum::mkFor(ipack, ext, exs) ) ) + ->ifor( RPackNum::mkFor(ipack, exs) ) ) { return std::get::value-N>(ipack) - ->ifor( ext, RPackNum::mkFor(ipack, ext, exs) ); + ->ifor( RPackNum::mkFor(ipack, exs) ); } }; @@ -405,12 +405,12 @@ namespace MultiArrayHelper out.emplace_back(*std::get(ip), std::get(bs)); } - template - static auto mkFor(const IndexPack& ipack, const Ext& ext, Exprs&& exs) - -> decltype(std::get::value-1>(ipack, ext) - ->ifor(ext, exs) ) + template + static auto mkFor(const IndexPack& ipack, Exprs&& exs) + -> decltype(std::get::value-1>(ipack) + ->ifor(exs) ) { - return std::get::value-1>(ipack)->ifor(ext, exs); + return std::get::value-1>(ipack)->ifor(exs); } }; diff --git a/src/ranges/single_range.h b/src/ranges/single_range.h index 186b9a3..24e4604 100644 --- a/src/ranges/single_range.h +++ b/src/ranges/single_range.h @@ -65,9 +65,9 @@ namespace MultiArrayTools std::string id(); void print(size_t offset); - template - auto ifor(const std::array...>,DIM>& ee, Expr&& ex) const - -> For,Expr,Ops...>; + template + auto ifor(Expr&& ex) const + -> For,Expr>; }; template @@ -249,12 +249,12 @@ namespace MultiArrayTools } template - template - auto SingleIndex::ifor(const std::array...>,DIM>& ee, Expr&& ex) const - -> For,Expr,Ops...> + template + auto SingleIndex::ifor(Expr&& ex) const + -> For,Expr> { - static const size_t layer = typename Expr::layer(); - return For,Expr,Ops...>( this, ex, std::get( ee ) ); + //static const size_t LAYER = typename Expr::LAYER; + return For,Expr>(this, ex); } diff --git a/src/xfor/for_utils.h b/src/xfor/for_utils.h index 05f577d..eb1d569 100644 --- a/src/xfor/for_utils.h +++ b/src/xfor/for_utils.h @@ -16,22 +16,20 @@ namespace MultiArrayHelper template struct XFPackNum { - template - static auto mkPos(const IndexClass& ind, const ExtTuple& et, const LastTuple& lt, const Args&... args) - -> decltype(XFPackNum::mkPos(et, lt, 0ul, args...)) + template + static ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args) { - return XFPackNum::mkPos(et, lt, std::get(lt) + ind.pos() * std::get(et), args...); + return std::move( XFPackNum::mkPos(pos, et, lt, std::get(lt) + pos * std::get(et), args...) ); } }; template <> struct XFPackNum<0> { - template - static auto mkPos(const IndexClass& ind, const ExtTuple& et, const LastTuple& lt, const Args&... args) - -> std::tuple...> + template + static ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args) { - return std::tuple...>(std::get<0>(lt) + ind.pos() * std::get<0>(et), 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 fb90c29..59cb09d 100644 --- a/src/xfor/xfor.h +++ b/src/xfor/xfor.h @@ -10,40 +10,41 @@ namespace MultiArrayHelper { - template + template class For { + private: + For() = default; + //For(const For& in) = default; + //For& operator=(const For& in) = default; + + const IndexClass* mIndPtr; + Expr mExpr; + decltype(mExpr.rootSteps()) mExt; + public: - static size_t layer() { return typename Expr::layer() + 1; } + 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; - template For(const std::shared_ptr& indPtr, - std::tuple...>&& ext, const Args&... args); + Expr&& expr); - For(const std::shared_ptr& indPtr, - Expr&& expr, std::tuple...>&& ext); - - template - For(IndexClass* indPtr, - std::tuple...>&& ext, const Args&... args); - - For(IndexClass* indPtr, - Expr&& expr, std::tuple...>&& ext); + For(const IndexClass* indPtr, + Expr&& expr); - inline void operator()(size_t mlast, const std::tuple...>& last) const; + inline void operator()(size_t mlast, const ETuple& last) const; inline void operator()(size_t mlast = 0) const; - - private: - For() = default; - - IndexClass* mIndPtr; - const Expr mExpr; - const std::tuple...> mExt; + + ETuple rootSteps(std::intptr_t iPtrNum = 0) const; + }; template @@ -62,58 +63,49 @@ namespace MultiArrayHelper namespace MultiArrayHelper { - template - template - For::For(const std::shared_ptr& indPtr, - std::tuple...>&& ext, - const Args&... args) : - mIndPtr(indPtr.get()), mExpr(args...), mExt(ext) {} + template + For::For(const std::shared_ptr& indPtr, + Expr&& expr) : + mIndPtr(indPtr.get()), mExpr(expr), mExt(expr.rootSteps( static_cast( mIndPtr.get() ))) {} - template - For::For(const std::shared_ptr& indPtr, - Expr&& expr, std::tuple...>&& ext) : - mIndPtr(indPtr.get()), mExpr(expr), mExt(ext) {} - - template - template - For::For(IndexClass* indPtr, - std::tuple...>&& ext, - const Args&... args) : - mIndPtr(indPtr), mExpr(args...), mExt(ext) {} + template + For::For(const IndexClass* indPtr, + Expr&& expr) : + mIndPtr(indPtr), mExpr(expr), mExt(expr.rootSteps( static_cast( mIndPtr ) )) {} - template - For::For(IndexClass* indPtr, - Expr&& expr, std::tuple...>&& ext) : - mIndPtr(indPtr), mExpr(expr), mExt(ext) {} - - template - inline void For::operator()(size_t mlast, - const std::tuple...>& last) const + template + inline void For::operator()(size_t mlast, + const ETuple& last) const { - static const size_t opNum = sizeof...(Ops); auto& ind = *mIndPtr; - const size_t max = exceptMax::layer()>( ind.max() ); // blocking - for(ind = 0; ind.pos() != max; ++ind){ - const size_t mnpos = mlast * max + ind.pos(); - const std::tuple...> npos = std::move( XFPackNum::mkPos(ind, mExt, last) ); + const size_t max = ind.max(); // blocking + for(size_t pos = ind.pos(); pos != max; ++pos){ + const size_t mnpos = mlast * max + pos; + const ETuple npos = std::move( XFPackNum::mkPos(pos, mExt, last) ); mExpr(mnpos, npos); } } - template - inline void For::operator()(size_t mlast) const + template + inline void For::operator()(size_t mlast) const { - static const size_t opNum = sizeof...(Ops); - std::tuple...> last(to_size_t(0)...); + const ETuple last; auto& ind = *mIndPtr; - const size_t max = exceptMax::layer()>( ind.max() ); // blocking - for(ind = 0; ind.pos() != max; ++ind){ - const size_t mnpos = mlast * max + ind.pos(); - const std::tuple...> npos = std::move( XFPackNum::mkPos(ind, mExt, last) ); + const size_t max = ind.max(); // blocking + for(size_t pos = ind.pos(); pos != max; ++pos){ + const size_t mnpos = mlast * max + pos; + const ETuple npos = std::move( XFPackNum::mkPos(pos, mExt, last) ); mExpr(mnpos, npos); } } + template + typename For::ETuple For::rootSteps(std::intptr_t iPtrNum) const + { + return mExpr.rootSteps(iPtrNum); + } + + } // namespace MultiArrayHelper #endif