diff --git a/src/include/dynamic_operation.cc.h b/src/include/dynamic_operation.cc.h index 4ecd774..0810f4d 100644 --- a/src/include/dynamic_operation.cc.h +++ b/src/include/dynamic_operation.cc.h @@ -6,9 +6,6 @@ namespace MultiArrayTools template const T& DynamicOperation::get(const DExtT& pos) const { - VCHECK(pos.size()); - VCHECK(sizeof(ET)/sizeof(size_t)); - assert(0); return mOp.get(pos.expl()); } diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 7262cd0..66c76d1 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -172,7 +172,8 @@ namespace MultiArrayTools template inline void AssignmentExpr2::operator()(size_t start) { - ExtType last; + ExtType last = rootSteps(); + last.zero(); mDataPtr[OpIndexResolve::get(start,last)] = mSec.get(last.next()); //mDataPtr[last.val()] = mSec.get(last.next()); } @@ -224,7 +225,8 @@ namespace MultiArrayTools template inline void AddExpr::operator()(size_t start) { - ExtType last; + ExtType last = rootSteps(); + last.zero(); mDataPtr[OpIndexResolve::get(start,last)] += mSec.get(last.next()); } diff --git a/src/include/xfor/exttype.h b/src/include/xfor/exttype.h index 5744983..8877ddd 100644 --- a/src/include/xfor/exttype.h +++ b/src/include/xfor/exttype.h @@ -60,7 +60,7 @@ namespace MultiArrayHelper MExt& operator=(const MExt& in) = default; MExt(MExt&& in) = default; MExt& operator=(MExt&& in) = default; - + inline MExt(size_t ext, X next); template @@ -74,7 +74,9 @@ namespace MultiArrayHelper template inline MExt(const MExt& y); - + + inline void zero(); + inline const size_t& val() const; inline const X& next() const; @@ -107,7 +109,9 @@ namespace MultiArrayHelper inline None operator+(const None& in) const { return None(); } inline None operator*(size_t in) const { return None(); } - + + inline void zero() {} + template Y extend(const Y& y) const { return y; } @@ -150,6 +154,8 @@ namespace MultiArrayHelper inline const size_t& val() const; inline None next() const { return None(); } + inline void zero(); + template inline auto nn() const -> decltype(Getter::getX(*this)) @@ -209,7 +215,14 @@ namespace MultiArrayHelper { return mNext; } - + + template + inline void MExt::zero() + { + mExt = 0u; + mNext.zero(); + } + template inline MExt MExt::operator+(const MExt& in) const { @@ -248,11 +261,16 @@ namespace MultiArrayHelper mExt(y.val()) {} //template <> + inline void MExt::zero() + { + mExt = 0u; + } + inline const size_t& MExt::val() const { return mExt; } - + //template <> inline MExt MExt::operator+(const MExt& in) const { diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index 53a1d20..1b6b07b 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -37,6 +37,9 @@ namespace MultiArrayHelper //virtual size_t rootSteps() const = 0; virtual std::shared_ptr operator+(const ExtBase& in) const = 0; virtual std::shared_ptr operator*(size_t in) const = 0; + virtual void zero() = 0; + + virtual std::shared_ptr deepCopy() const = 0; template const ExtType& expl() const; @@ -61,12 +64,15 @@ namespace MultiArrayHelper ExtT& operator=(ExtT&& in) = default; ExtT(const ExtType& in) : mExt(in) {} - + + virtual std::shared_ptr deepCopy() const override final { return std::make_shared>(mExt); } + virtual size_t size() const override final { return sizeof(ExtType)/sizeof(size_t); } //virtual size_t size() const override final { return ExtType::MExtSize(); } //virtual size_t rootSteps() const override final; const ExtType& ext() const { return mExt; } virtual const size_t& val() const override final { return mExt.val(); } + virtual void zero() override final { mExt.zero(); } virtual DExt operator+(const ExtBase& in) const override final { return std::make_shared( mExt + dynamic_cast(in).mExt ); } @@ -79,17 +85,17 @@ namespace MultiArrayHelper class DExtTX { private: - DExt mDExt = nullptr; + mutable DExt mDExt = nullptr; X mNext; public: static constexpr size_t NUM = X::SIZE; static constexpr size_t SIZE = NUM + 1; DExtTX() = default; - DExtTX(const DExtTX& in) = default; - DExtTX(DExtTX&& in) = default; - DExtTX& operator=(const DExtTX& in) = default; - DExtTX& operator=(DExtTX&& in) = default; + DExtTX(const DExtTX& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {} + DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {} + DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); } + DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); } DExtTX(const DExt& in) : mDExt(in) {} template @@ -110,7 +116,8 @@ namespace MultiArrayHelper { if (not mDExt) return *this; else return DExtTX( (*mDExt) * in ) ; } template - inline const ExtType& expl() const { return mDExt->expl(); } + inline const ExtType& expl() const + { if(mDExt == nullptr) mDExt = std::make_shared>(); assert(mDExt != nullptr); return mDExt->expl(); } template inline auto extend(const Y& y) const -> DExtTX @@ -119,6 +126,8 @@ namespace MultiArrayHelper inline const size_t& val() const { return mDExt->val(); } inline const X& next() const { return mNext; } + inline void zero() { mDExt->zero(); } + template inline auto nn() const -> decltype(Getter::getX(*this)) { return Getter::getX(*this); } @@ -533,7 +542,8 @@ namespace MultiArrayHelper inline void For::operator()(size_t mlast) { typedef typename IndexClass::RangeType RangeType; - const ExtType last; + ExtType last = rootSteps(); + last.zero(); for(size_t pos = 0u; pos != ForBound::template bound(mMax); ++pos){ const size_t mnpos = PosForward::valuex(mlast, mStep, pos); const ExtType npos = last + mExt*pos; @@ -635,10 +645,12 @@ namespace MultiArrayHelper { CHECK; typedef typename IndexClass::RangeType RangeType; - const ExtType last; + ExtType last = rootSteps(); + last.zero(); int pos = 0; size_t mnpos = 0; - ExtType npos; + ExtType npos = rootSteps(); + npos.zero(); #pragma omp parallel shared(mExpr) private(pos,mnpos,npos) { auto expr = mExpr; @@ -731,7 +743,8 @@ namespace MultiArrayHelper inline void SingleExpression::operator()(size_t mlast) { //typedef typename IndexClass::RangeType RangeType; - const ExtType last; + ExtType last = rootSteps(); + last.zero(); const size_t pos = mIndPtr->pos(); const size_t mnpos = PosForward::value(mlast, mMax, pos); const ExtType npos = last + mExt*pos; @@ -816,7 +829,8 @@ namespace MultiArrayHelper template inline void SubExpr::operator()(size_t mlast) { - const ExtType last; + ExtType last = rootSteps(); + last.zero(); const size_t pos = (*mSubSet)[last.val()]; const size_t mnpos = mlast; const ExtType npos = last + mExt*pos;