From bdabee1335e80815e9cafc953b5634e8a32358dc Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 2 Dec 2018 22:08:51 +0100 Subject: [PATCH] fixes in dynamic index (ForMaker) + set offset of operation by given index --- src/include/multi_array_operation.cc.h | 13 +++++-- src/include/ranges/dynamic_range.cc.h | 49 +++++++++++++++++++------- src/include/ranges/dynamic_range.h | 6 ++-- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 962157c..5387649 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -185,6 +185,7 @@ namespace MultiArrayTools { //VCHECK(ma.data()); mIndex(indices...); + mOff = mIndex.pos(); } template @@ -196,13 +197,17 @@ namespace MultiArrayTools mMaPtr(maptr) { mIndex(indices...); + mOff = mIndex.pos(); } template ConstOperationRoot:: ConstOperationRoot(const T* data, const IndexType& ind) : mDataPtr(data), - mIndex( ind ) { } + mIndex( ind ) + { + mOff = mIndex.pos(); + } template template @@ -335,13 +340,17 @@ namespace MultiArrayTools mIndex( ma.begin() ) { mIndex(indices...); + mOff = mIndex.pos(); } template OperationRoot:: OperationRoot(T* data, const IndexType& ind) : mDataPtr(data), - mIndex( ind ) { } + mIndex( ind ) + { + mOff = mIndex.pos(); + } template template diff --git a/src/include/ranges/dynamic_range.cc.h b/src/include/ranges/dynamic_range.cc.h index 67ed416..357625a 100644 --- a/src/include/ranges/dynamic_range.cc.h +++ b/src/include/ranges/dynamic_range.cc.h @@ -201,10 +201,24 @@ namespace MultiArrayTools return *this; } + template + DynamicIndex& DynamicIndex::sync() + { + size_t sv = 1; + IB::mPos = 0; + for(size_t i = 0; i != mIVec.size(); ++i){ + auto& x = mIVec[mIVec.size()-i-1]; + IB::mPos += x.first->pos() * sv; + sv *= x.first->max(); + } + return *this; + } + template DynamicIndex& DynamicIndex::operator()(const IVecT& ivec) { mIVec = ivec; + sync(); return *this; } @@ -215,6 +229,7 @@ namespace MultiArrayTools for(size_t i = 0; i != mIVec.size(); ++i){ mIVec[i].first = ivec[i]; } + sync(); return *this; } @@ -229,6 +244,7 @@ namespace MultiArrayTools for(size_t i = 0; i != mIVec.size(); ++i){ mIVec[i].first = tmp[i]; } + sync(); return *this; } @@ -349,18 +365,19 @@ namespace MultiArrayTools const IVecT& ivec, bool hidden = false) -> ExpressionHolder { - if(i != 0){ + if(i == 0) { + auto& ii = *ivec[0].first; + return hidden ? ii.iforh(step*ivec[i].second, ex) : + ii.ifor(step*ivec[i].second, ex); + } + else { auto& ii = *ivec[i].first; return mk(i-1, step, (hidden ? ii.iforh(step*ivec[i].second, ex) : ii.ifor(step*ivec[i].second, ex)), ivec, hidden); + } - else { - auto& ii = *ivec[0].first; - return hidden ? ii.iforh(step*ivec[i].second, ex) : - ii.ifor(step*ivec[i].second, ex); - } } }; @@ -386,20 +403,28 @@ namespace MultiArrayTools template ExpressionHolder DynamicIndex::ifor(size_t step, Expr ex) const { - return ForMaker::mk(mIVec.size()-2, step, mIVec.back().first->ifori(step,ex), - mIVec); + if(mIVec.size() == 1){ + return mIVec.back().first->ifori(step,ex); + } + else { + return ForMaker::mk(mIVec.size()-2, step, mIVec.back().first->ifori(step,ex), + mIVec); + } } template template ExpressionHolder DynamicIndex::iforh(size_t step, Expr ex) const { - return ForMaker::mk(mIVec.size()-2, step, mIVec.back().first->iforhi(step,ex), - mIVec, true); + if(mIVec.size() == 1){ + return mIVec.back().first->iforhi(step,ex); + } + else { + return ForMaker::mk(mIVec.size()-2, step, mIVec.back().first->iforhi(step,ex), + mIVec, true); + } } - - /*********************** * DynamicRange * ***********************/ diff --git a/src/include/ranges/dynamic_range.h b/src/include/ranges/dynamic_range.h index 057c091..ece62ed 100644 --- a/src/include/ranges/dynamic_range.h +++ b/src/include/ranges/dynamic_range.h @@ -198,10 +198,12 @@ namespace MultiArrayTools DynamicIndex& operator()(const IVecT& ivec); DynamicIndex& operator()(const std::vector>>& ivec); - + template DynamicIndex& operator()(const std::shared_ptr&... is); - + + DynamicIndex& sync(); + int pp(std::intptr_t idxPtrNum); int mm(std::intptr_t idxPtrNum);