From d1c4372825e47f7baaa98f417fc86b2662556415 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 13 Sep 2019 15:08:33 +0200 Subject: [PATCH] AbstractIW: add function duplicate + Operations: completely replace AssignmentExpr by AssignmentExpr2 --- src/include/expressions.h | 24 +++++++++--------- src/include/multi_array_operation.cc.h | 35 +++++++++----------------- src/include/multi_array_operation.h | 34 +++++-------------------- src/include/ranges/dynamic_range.h | 8 ++++++ 4 files changed, 38 insertions(+), 63 deletions(-) diff --git a/src/include/expressions.h b/src/include/expressions.h index 6d9bda2..b54a0e2 100644 --- a/src/include/expressions.h +++ b/src/include/expressions.h @@ -29,32 +29,32 @@ namespace MultiArrayTools template class OpF, class... MAs> using OX = Operation,oo...>; - template - using AEXT = AssignmentExpr; + template + using AEXT = AssignmentExpr2; - template - using AEXT_P = AssignmentExpr; + template + using AEXT_P = AssignmentExpr2; - template class OpF, class... MAs> - using AEX = AEXT>; + template class OpF, class... MAs> + using AEX = AEXT>; template - using AEX_M = AEXT>>; + using AEX_M = AEXT>,oo>>; template - using AEX_C = AEXT>>; + using AEX_C = AEXT>,oo>>; template class OpF> - using AEX_B_MM = AEX,DDMMA>; + using AEX_B_MM = AEX>,OpF,DDMMA,DDMMA>; template class OpF> - using AEX_B_MC = AEX,DDMA>; + using AEX_B_MC = AEX>,OpF,DDMMA,DDMA>; template class OpF> - using AEX_B_CM = AEX,DDMMA>; + using AEX_B_CM = AEX>,OpF,DDMA,DDMMA>; template class OpF> - using AEX_B_CC = AEX,DDMA>; + using AEX_B_CC = AEX>,OpF,DDMA,DDMA>; /* template diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index b9cf164..3f9bfcf 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -138,22 +138,6 @@ namespace MultiArrayTools * AssignmentExpr * ************************/ - template - AssignmentExpr::AssignmentExpr(T* dataPtr, const OpClass& sec) : - mSec(sec), mDataPtr(dataPtr) {} - - template - inline void AssignmentExpr::operator()(size_t start, ExtType last) - { - mDataPtr[start] = mSec.template get(last); - } - - template - typename AssignmentExpr::ExtType AssignmentExpr::rootSteps(std::intptr_t iPtrNum) const - { - return mSec.rootSteps(iPtrNum); - } - template AssignmentExpr2::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) : mTar(tar), mSec(sec), mDataPtr(dataPtr) {} @@ -380,19 +364,22 @@ namespace MultiArrayTools template template auto OperationRoot::assign(const OpClass& in) const - -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr(mOrigDataPtr,in)))) + -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass> + (mOrigDataPtr,*this,in)))) + { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return mIndex.ifor(1,in.loop(AssignmentExpr(mOrigDataPtr,in))); + return mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass> + (mOrigDataPtr,*this,in))); } template template auto OperationRoot::assignExpr(const OpClass& in) const - -> decltype(in.loop(AssignmentExpr(mOrigDataPtr,in))) + -> decltype(in.loop(AssignmentExpr2,OpClass>(mOrigDataPtr,*this,in))) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return in.loop(AssignmentExpr(mOrigDataPtr,in)); + return in.loop(AssignmentExpr2,OpClass>(mOrigDataPtr,*this,in)); } template @@ -404,7 +391,6 @@ namespace MultiArrayTools static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); return i->ifor(1,in.loop(AssignmentExpr2,OpClass> (mOrigDataPtr,*this,in))); - //return mIndex.ifor(1,in.loop(AssignmentExpr(mOrigDataPtr,in))); } template @@ -521,9 +507,12 @@ namespace MultiArrayTools template template auto ParallelOperationRoot::assign(const OpClass& in) - -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr(mOrigDataPtr,in)))) + -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass> + (mOrigDataPtr,*this,in)))) + { - return mIndex.pifor(1,in.loop(AssignmentExpr(mOrigDataPtr,in))); + return mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass> + (mOrigDataPtr,*this,in))); } template diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index f688756..a2441e5 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -105,30 +105,6 @@ namespace MultiArrayTools } }; - template - class AssignmentExpr - { - private: - AssignmentExpr() = default; - - OpClass mSec; - T* mDataPtr; - - public: - - static constexpr size_t LAYER = 0; - static constexpr size_t SIZE = OpClass::SIZE; - typedef decltype(mSec.rootSteps()) ExtType; - - AssignmentExpr(T* dataPtr, const OpClass& sec); - AssignmentExpr(const AssignmentExpr& in) = default; - AssignmentExpr(AssignmentExpr&& in) = default; - - inline void operator()(size_t start = 0); - inline void operator()(size_t start, ExtType last); - auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; - }; - template class AssignmentExpr2 { @@ -317,12 +293,13 @@ namespace MultiArrayTools template auto assign(const OpClass& in) const - -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr(mOrigDataPtr,in)))); + -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2,OpClass> + (mOrigDataPtr,*this,in)))); template auto assignExpr(const OpClass& in) const - -> decltype(in.loop(AssignmentExpr(mOrigDataPtr,in))); - + -> decltype(in.loop(AssignmentExpr2,OpClass>(mOrigDataPtr,*this,in))); + template auto assign(const OpClass& in, const std::shared_ptr& i) const -> decltype(i->ifor(1,in.loop(AssignmentExpr2,OpClass> @@ -388,7 +365,8 @@ namespace MultiArrayTools template auto assign(const OpClass& in) - -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr(mOrigDataPtr,in)))); + -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2,OpClass> + (mOrigDataPtr,*this,in)))); template auto plus(const OpClass& in) diff --git a/src/include/ranges/dynamic_range.h b/src/include/ranges/dynamic_range.h index f909d5b..8902f25 100644 --- a/src/include/ranges/dynamic_range.h +++ b/src/include/ranges/dynamic_range.h @@ -61,6 +61,8 @@ namespace MultiArrayTools virtual std::intptr_t get() const = 0; virtual std::intptr_t ptrNum() const = 0; + virtual std::shared_ptr duplicate() const = 0; + //virtual DynamicMetaT meta() const = 0; //virtual const DynamicMetaT* metaPtr() const = 0; //virtual AbstractIW& at(const U& metaPos) = 0; @@ -105,6 +107,9 @@ namespace MultiArrayTools template ExpressionHolder iforhi(size_t step, Expr ex) const; + std::shared_ptr duplicateI() const + { return std::dynamic_pointer_cast( this->duplicate() ); } + }; template @@ -165,6 +170,9 @@ namespace MultiArrayTools virtual std::intptr_t get() const override final { return reinterpret_cast(mI.get()); } virtual std::intptr_t ptrNum() const override final { return mI->ptrNum(); } + + virtual std::shared_ptr duplicate() const override final + { return std::make_shared( std::make_shared( *mI ) ); } };