From d2e7cb3a63b40b638753299d15a80f7c7ff171e8 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 24 Aug 2020 16:35:14 +0200 Subject: [PATCH] op4utest works --- src/include/dynamic_operation.cc.h | 9 ++++-- src/include/dynamic_operation.h | 18 ++++++----- src/include/multi_array_operation.cc.h | 1 + src/include/xfor/exttype.h | 21 ++++++++++++- src/include/xfor/xfor.h | 41 +++++++++++++++++++------- 5 files changed, 69 insertions(+), 21 deletions(-) diff --git a/src/include/dynamic_operation.cc.h b/src/include/dynamic_operation.cc.h index 39aa818..020ad4e 100644 --- a/src/include/dynamic_operation.cc.h +++ b/src/include/dynamic_operation.cc.h @@ -6,7 +6,6 @@ namespace MultiArrayTools template const T& DynamicOperation::get(const DExtT& pos) const { - VCHECK(pos.expl().val()); return mOp.get(pos.expl()); } @@ -20,7 +19,7 @@ namespace MultiArrayTools template DExtT DynamicOperation::rootSteps(std::intptr_t iPtrNum) const { - return mOp.rootSteps(iPtrNum); + return DExtT(mkDExt(mkExtT(mOp.rootSteps(iPtrNum))),None(0)); } template @@ -35,5 +34,11 @@ namespace MultiArrayTools return mOp.data(); } + template + std::shared_ptr> DynamicOperation::deepCopy() const + { + return std::make_shared>(*this); + } + } // namespace MultiArrayTools diff --git a/src/include/dynamic_operation.h b/src/include/dynamic_operation.h index a8f2738..4982333 100644 --- a/src/include/dynamic_operation.h +++ b/src/include/dynamic_operation.h @@ -29,6 +29,7 @@ namespace MultiArrayTools virtual DExtT rootSteps(std::intptr_t iPtrNum = 0) const = 0; virtual DynamicExpression loop(const DynamicExpression& exp) const = 0; virtual const T* data() const = 0; + virtual std::shared_ptr> deepCopy() const = 0; }; @@ -38,7 +39,8 @@ namespace MultiArrayTools private: Operation mOp; public: - typedef decltype(std::declval().rootSteps()) ET; + typedef decltype(mOp.rootSteps()) ET; + //typedef decltype(std::declval().rootSteps()) ET; DynamicOperation() = default; DynamicOperation(const DynamicOperation& in) = default; @@ -53,6 +55,7 @@ namespace MultiArrayTools virtual DExtT rootSteps(std::intptr_t iPtrNum = 0) const override final; virtual DynamicExpression loop(const DynamicExpression& exp) const override final; virtual const T* data() const override final; + virtual std::shared_ptr> deepCopy() const override final; }; template @@ -69,15 +72,16 @@ namespace MultiArrayTools static constexpr bool CONT = true; DynamicO() = default; - DynamicO(const DynamicO& in) = default; - DynamicO(DynamicO&& in) = default; - DynamicO& operator=(const DynamicO& in) = default; - DynamicO& operator=(DynamicO&& in) = default; + DynamicO(const DynamicO& in) : mOp(in.mOp->deepCopy()) {} + DynamicO(DynamicO&& in) : mOp(in.mOp->deepCopy()) {} + DynamicO& operator=(const DynamicO& in) { mOp = in.mOp->deepCopy(); } + DynamicO& operator=(DynamicO&& in) { mOp = in.mOp->deepCopy(); } template DynamicO(const Op& op) : mOp(std::make_shared>(op)) {} - - inline const T& get(const DExtT& pos) const { return mOp->get(pos); } + + template + inline const T& get(const DExtTX& pos) const { return mOp->get(pos.reduce()); } inline DynamicO& set(const DExtT& pos) { return mOp->set(pos); } inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return mOp->rootSteps(iPtrNum); } inline DynamicExpression loop(const DynamicExpression& exp) const { return mOp->loop(exp); } diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 66c76d1..5e1199c 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -181,6 +181,7 @@ namespace MultiArrayTools template inline void AssignmentExpr2::operator()(size_t start, ExtType last) { + //CHECK; mDataPtr[OpIndexResolve::get(start,last)] = mSec.get(last.next()); } diff --git a/src/include/xfor/exttype.h b/src/include/xfor/exttype.h index ebb84e1..f612c5c 100644 --- a/src/include/xfor/exttype.h +++ b/src/include/xfor/exttype.h @@ -41,6 +41,7 @@ namespace MultiArrayHelper } }; + struct None; template class MExt @@ -86,12 +87,14 @@ namespace MultiArrayHelper { return Getter::getX(*this); } inline MExt operator+(const MExt& in) const; + inline MExt operator+(const None& in) const; inline MExt operator*(size_t in) const; template auto extend(const Y& y) const -> MExt { return MExt(mExt, mNext.extend(y)); } - + + std::string stype() const { return std::string("E[") + mNext.stype() + "]"; } }; struct None @@ -117,6 +120,8 @@ namespace MultiArrayHelper template Y extend(const Y& y) const { return y; } + + std::string stype() const { return std::string("N"); } }; template <> @@ -164,12 +169,15 @@ namespace MultiArrayHelper { return Getter::getX(*this); } inline MExt operator+(const MExt& in) const; + inline MExt operator+(const None& in) const; inline MExt operator*(size_t in) const; template auto extend(const Y& y) const -> MExt { return MExt(mExt,y); } + std::string stype() const { return std::string("E[N]"); } + }; @@ -231,6 +239,12 @@ namespace MultiArrayHelper return MExt(mExt + in.val(), mNext + in.next()); } + template + inline MExt MExt::operator+(const None& in) const + { + return *this; + } + template inline MExt MExt::operator*(size_t in) const { @@ -279,6 +293,11 @@ namespace MultiArrayHelper return MExt(mExt + in.val()); } + inline MExt MExt::operator+(const None& in) const + { + return *this; + } + //template <> inline MExt MExt::operator*(size_t in) const { diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index 9beb278..f8b3e34 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -44,6 +44,7 @@ namespace MultiArrayHelper template const ExtType& expl() const; + virtual std::string stype() const = 0; }; typedef std::shared_ptr DExt; @@ -75,12 +76,26 @@ namespace MultiArrayHelper 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 ); } + { return std::make_shared>( mExt + dynamic_cast&>(in).mExt ); } virtual DExt operator*(size_t in) const override final - { return std::make_shared( mExt * in ); } + { return std::make_shared>( mExt * in ); } + + virtual std::string stype() const override final { return std::string("T[") + mExt.stype() + "]"; } }; //class DExtT; + template + DExt mkDExt(const ExtT& in) + { + return std::make_shared>(in); + } + + template + ExtT mkExtT(const ExtType& in) + { + return ExtT(in); + } + template class DExtTX { @@ -96,24 +111,26 @@ namespace MultiArrayHelper 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) {} - + explicit DExtTX(const DExt& in) : mDExt(in) {} + /* template DExtTX& operator=(const Y& y) { mDExt = std::make_shared>(y); return *this; } template DExtTX(const Y& y) : mDExt(std::make_shared>(y)) {} - - DExtTX(const DExt& y, const X& x) : mDExt(y), - mNext(x) {} + */ + explicit DExtTX(const DExt& y, const X& x) : mDExt(y->deepCopy()), + mNext(x) {} virtual size_t size() const { return mDExt->size(); } inline const DExt& get() const { return mDExt; } + + inline DExtTX reduce() const { return DExtTX(mDExt,None(0)); } inline DExtTX operator+(const DExtTX& in) const - { if (not mDExt) return in; else return DExtTX( (*mDExt) + (*in.mDExt) ) ; } + { if (not mDExt) return in; else return DExtTX( (*mDExt) + (*in.mDExt), mNext + in.mNext ); } inline DExtTX operator*(size_t in) const - { if (not mDExt) return *this; else return DExtTX( (*mDExt) * in ) ; } + { if (not mDExt) return *this; else return DExtTX((*mDExt) * in, mNext * in); } template inline const ExtType& expl() const @@ -131,6 +148,8 @@ namespace MultiArrayHelper template inline auto nn() const -> decltype(Getter::getX(*this)) { return Getter::getX(*this); } + + std::string stype() const { return std::string("D[") + mDExt->stype() + "," + mNext.stype() + "]"; } }; typedef DExtTX DExtT; @@ -438,8 +457,8 @@ namespace MultiArrayHelper inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; inline DExt dExtension() const override final; - inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return dRootSteps(iPtrNum); } - inline DExtT extension() const { return dExtension(); } + inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return DExtT(dRootSteps(iPtrNum)); } + inline DExtT extension() const { return DExtT(dExtension()); } };