From 89eb03ab7fa43ca7ce734a6b2f195431277a5a33 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 7 Aug 2018 23:15:31 +0200 Subject: [PATCH] im com (single expression) --- src/include/multi_array_base.h | 4 +- src/include/ranges/map_range.h | 6 ++- src/include/xfor/xfor.h | 93 ++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/src/include/multi_array_base.h b/src/include/multi_array_base.h index 15a8e2f..37a8a57 100644 --- a/src/include/multi_array_base.h +++ b/src/include/multi_array_base.h @@ -208,6 +208,7 @@ namespace MultiArrayTools return ConstOperationRoot(*this, inds...); } + template template ConstOperationRoot MultiArrayBase::operator()(const std::shared_ptr&... inds) const @@ -278,9 +279,10 @@ namespace MultiArrayTools return ConstOperationRoot(*this, inds...); } + template template ConstOperationRoot - MultiArrayBase::operator()(const std::shared_ptr&... inds) + MutableMultiArrayBase::operator()(const std::shared_ptr&... inds) { static_assert(sizeof...(SRanges) == sizeof...(MappedRanges), "number of mapped ranges must be equal to number of original ranges"); diff --git a/src/include/ranges/map_range.h b/src/include/ranges/map_range.h index 59ee61e..ca9d473 100644 --- a/src/include/ranges/map_range.h +++ b/src/include/ranges/map_range.h @@ -17,6 +17,8 @@ #include "ranges/x_to_string.h" #include "ranges/type_map.h" +#include "xfor/xfor.h" + namespace MultiArrayTools { namespace @@ -115,7 +117,7 @@ namespace MultiArrayTools template auto ifor(Exprs exs) const - -> decltype(RPackNum::mkFors(mIPack, mOutIndex, exs)); + -> decltype(RPackNum::mkFor(mIPack, SinleExpression( mOutIndex, exs ) )); /* template @@ -236,7 +238,7 @@ namespace MultiArrayTools } // -> define in range_base.cc - std::shared_ptr mkMULTI(const char** dp); + //std::shared_ptr mkMULTI(const char** dp); /****************** * MapIndex * diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index 6936da2..cb64be5 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -52,6 +52,44 @@ namespace MultiArrayHelper return BOUND; } }; + + template + class SingleExpression + { + private: + SingleExpression() = default; + + const IndexClass* mIndPtr; + size_t mSPos; + size_t mMax; + Expr mExpr; + + typedef decltype(mExpr.rootSteps()) ExtType; + ExtType mExt; + + public: + + static constexpr size_t LAYER = Expr::LAYER + 1; + static constexpr size_t SIZE = Expr::SIZE; + + SingleExpression(const SingleExpression& in) = default; + SingleExpression& operator=(const SingleExpression& in) = default; + SingleExpression(SingleExpression&& in) = default; + SingleExpression& operator=(SingleExpression&& in) = default; + + SingleExpression(const std::shared_ptr& indPtr, + Expr expr); + + SingleExpression(const IndexClass* indPtr, + Expr expr); + + + inline void operator()(size_t mlast, ExtType last) const; + inline void operator()(size_t mlast = 0) const; + + auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; + + }; template class For @@ -166,6 +204,61 @@ namespace MultiArrayHelper return mExpr.rootSteps(iPtrNum); } + + + + template + SingleExpression::SingleExpression(const std::shared_ptr& indPtr, + Expr expr) : + mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr), + mExt(expr.rootSteps( reinterpret_cast( mIndPtr.get() ))) + { + assert(mIndPtr != nullptr); + //VCHECK(mIndPtr->id()); + //VCHECK(mIndPtr->max()); + } + + template + SingleExpression::SingleExpression(const IndexClass* indPtr, + Expr expr) : + mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), + mExpr(std::forward( expr )), + mExt(expr.rootSteps( reinterpret_cast( mIndPtr ) )) + { + assert(mIndPtr != nullptr); + //VCHECK(mIndPtr->id()); + //VCHECK(mIndPtr->max()); + } + + template + inline void SingleExpression::operator()(size_t mlast, + ExtType last) const + { + //typedef typename IndexClass::RangeType RangeType; + const size_t pos = mIndPtr->pos(); + const size_t mnpos = PosForward::value(mlast, mMax, pos); + const ExtType npos = last + mExt*pos; + mExpr(mnpos, npos); + } + + template + inline void SingleExpression::operator()(size_t mlast) const + { + //typedef typename IndexClass::RangeType RangeType; + const ExtType last; + const size_t pos = mIndPtr->pos(); + const size_t mnpos = PosForward::value(mlast, mMax, pos); + const ExtType npos = last + mExt*pos; + mExpr(mlast, last); + } + + template + auto SingleExpression::rootSteps(std::intptr_t iPtrNum) const + -> ExtType + { + return mExpr.rootSteps(iPtrNum); + } + } // namespace MultiArrayHelper