From 9a4f6e7386b8c5e1c63eb2529e95341dc08acd4f Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 21 Dec 2018 23:02:35 +0100 Subject: [PATCH] ...fixed --- src/include/ranges/subrange.h | 4 +++- src/include/xfor/xfor.h | 36 +++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/include/ranges/subrange.h b/src/include/ranges/subrange.h index 24cbb4c..5a850dc 100644 --- a/src/include/ranges/subrange.h +++ b/src/include/ranges/subrange.h @@ -317,7 +317,9 @@ namespace MultiArrayTools -> For,SubExpr> { return For,SubExpr> - (this, 1, SubExpr( mFullIndex, &mExplicitRangePtr->subset(), step, ex ) ); + (this, 1, SubExpr + ( mFullIndex, reinterpret_cast(this), + &mExplicitRangePtr->subset(), step, ex ) ); } /************************ diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index c8a8b4f..b9d6fe0 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -19,6 +19,8 @@ namespace MultiArrayHelper // (NO COUNTING OF MASTER POSITION !!!!!) typedef std::pair DExt; + + inline MExt mkExt(size_t s) { return MExt(s); } class ExpressionBase { @@ -140,11 +142,12 @@ namespace MultiArrayHelper SubExpr() = default; const IndexClass* mIndPtr; + std::intptr_t mSIPtr; size_t mSPos; size_t mMax; Expr mExpr; - typedef decltype(mExpr.rootSteps()) ExtType; + typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType; ExtType mExt; const std::vector* mSubSet; @@ -164,10 +167,12 @@ namespace MultiArrayHelper SubExpr& operator=(SubExpr&& in) = default; SubExpr(const std::shared_ptr& indPtr, + std::intptr_t siptr, const std::vector* subset, size_t step, Expr expr); SubExpr(const IndexClass* indPtr, + std::intptr_t siptr, const std::vector* subset, size_t step, Expr expr); @@ -485,14 +490,16 @@ namespace MultiArrayHelper /**************** * SubExpr * ****************/ - + template SubExpr::SubExpr(const std::shared_ptr& indPtr, + std::intptr_t siptr, const std::vector* subset, size_t step, Expr expr) : - mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), - mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast( mIndPtr ))), + mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), + mExpr(expr), + mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast( mIndPtr )) ) ), mSubSet(subset), mStep(step) { assert(mIndPtr != nullptr); @@ -500,11 +507,13 @@ namespace MultiArrayHelper template SubExpr::SubExpr(const IndexClass* indPtr, + std::intptr_t siptr, const std::vector* subset, size_t step, Expr expr) : - mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), - mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast( mIndPtr ))), + mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), + mExpr(expr), + mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast( mIndPtr )) ) ), mSubSet(subset), mStep(step) { assert(mIndPtr != nullptr); @@ -521,25 +530,20 @@ namespace MultiArrayHelper ExtType last) const { // INCLUDE FOR LOOP HERE AGIAN !!!! - const size_t pos = (*mSubSet)[mlast]; + const size_t pos = (*mSubSet)[last.val()]; const size_t mnpos = mlast * mStep; - VCHECK(mlast); - VCHECK(pos); - VCHECK(mnpos); const ExtType npos = last + mExt*pos; - VCHECK(npos.val()); - VCHECK(npos.next().val()); - mExpr(mnpos, npos); + mExpr(mnpos, Getter<1>::template getX( npos )); } template inline void SubExpr::operator()(size_t mlast) const { const ExtType last; - const size_t pos = (*mSubSet)[mlast]; + const size_t pos = (*mSubSet)[last.val()]; const size_t mnpos = mlast * mStep; const ExtType npos = last + mExt*pos; - mExpr(mnpos, npos); + mExpr(mnpos, Getter<1>::template getX( npos )); } @@ -547,7 +551,7 @@ namespace MultiArrayHelper auto SubExpr::rootSteps(std::intptr_t iPtrNum) const -> ExtType { - return mExpr.rootSteps(iPtrNum); + return mkExt(iPtrNum == mSIPtr ? 1 : 0).extend(mExpr.rootSteps(iPtrNum)); } template