AbstractIW: add function duplicate + Operations: completely replace AssignmentExpr by AssignmentExpr2

This commit is contained in:
Christian Zimmermann 2019-09-13 15:08:33 +02:00
parent 73a9d5b120
commit d1c4372825
4 changed files with 38 additions and 63 deletions

View file

@ -29,32 +29,32 @@ namespace MultiArrayTools
template <class EC, template <class> class OpF, class... MAs> template <class EC, template <class> class OpF, class... MAs>
using OX = Operation<double,OpF<double>,oo<EC,MAs>...>; using OX = Operation<double,OpF<double>,oo<EC,MAs>...>;
template <class EC, class Second> template <class EC, class Tar, class Second>
using AEXT = AssignmentExpr<double,Second>; using AEXT = AssignmentExpr2<double,Tar,Second>;
template <class EC, class Second> template <class EC, class Tar, class Second>
using AEXT_P = AssignmentExpr<double,Second>; using AEXT_P = AssignmentExpr2<double,Tar,Second>;
template <class EC, template <class> class OpF, class... MAs> template <class EC, class Tar, template <class> class OpF, class... MAs>
using AEX = AEXT<EC,OX<EC,OpF,MAs...>>; using AEX = AEXT<EC,Tar,OX<EC,OpF,MAs...>>;
template <class EC> template <class EC>
using AEX_M = AEXT<EC,oo<EC,DDMMA<EC>>>; using AEX_M = AEXT<EC,oo<EC,DDMMA<EC>>,oo<EC,DDMMA<EC>>>;
template <class EC> template <class EC>
using AEX_C = AEXT<EC,oo<EC,DDMA<EC>>>; using AEX_C = AEXT<EC,oo<EC,DDMMA<EC>>,oo<EC,DDMA<EC>>>;
template <class EC, template <class> class OpF> template <class EC, template <class> class OpF>
using AEX_B_MM = AEX<EC,OpF,DDMMA<EC>,DDMMA<EC>>; using AEX_B_MM = AEX<EC,oo<EC,DDMMA<EC>>,OpF,DDMMA<EC>,DDMMA<EC>>;
template <class EC, template <class> class OpF> template <class EC, template <class> class OpF>
using AEX_B_MC = AEX<EC,OpF,DDMMA<EC>,DDMA<EC>>; using AEX_B_MC = AEX<EC,oo<EC,DDMMA<EC>>,OpF,DDMMA<EC>,DDMA<EC>>;
template <class EC, template <class> class OpF> template <class EC, template <class> class OpF>
using AEX_B_CM = AEX<EC,OpF,DDMA<EC>,DDMMA<EC>>; using AEX_B_CM = AEX<EC,oo<EC,DDMMA<EC>>,OpF,DDMA<EC>,DDMMA<EC>>;
template <class EC, template <class> class OpF> template <class EC, template <class> class OpF>
using AEX_B_CC = AEX<EC,OpF,DDMA<EC>,DDMA<EC>>; using AEX_B_CC = AEX<EC,oo<EC,DDMMA<EC>>,OpF,DDMA<EC>,DDMA<EC>>;
/* /*
template <class EC> template <class EC>

View file

@ -138,22 +138,6 @@ namespace MultiArrayTools
* AssignmentExpr * * AssignmentExpr *
************************/ ************************/
template <typename T, class OpClass>
AssignmentExpr<T,OpClass>::AssignmentExpr(T* dataPtr, const OpClass& sec) :
mSec(sec), mDataPtr(dataPtr) {}
template <typename T, class OpClass>
inline void AssignmentExpr<T,OpClass>::operator()(size_t start, ExtType last)
{
mDataPtr[start] = mSec.template get<ExtType>(last);
}
template <typename T, class OpClass>
typename AssignmentExpr<T,OpClass>::ExtType AssignmentExpr<T,OpClass>::rootSteps(std::intptr_t iPtrNum) const
{
return mSec.rootSteps(iPtrNum);
}
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass>
AssignmentExpr2<T,Target,OpClass>::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) : AssignmentExpr2<T,Target,OpClass>::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) :
mTar(tar), mSec(sec), mDataPtr(dataPtr) {} mTar(tar), mSec(sec), mDataPtr(dataPtr) {}
@ -380,19 +364,22 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto OperationRoot<T,Ranges...>::assign(const OpClass& in) const auto OperationRoot<T,Ranges...>::assign(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in)))) -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))))
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return mIndex.ifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in))); return mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto OperationRoot<T,Ranges...>::assignExpr(const OpClass& in) const auto OperationRoot<T,Ranges...>::assignExpr(const OpClass& in) const
-> decltype(in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in))) -> decltype(in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)))
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in)); return in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -404,7 +391,6 @@ namespace MultiArrayTools
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass> return i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))); (mOrigDataPtr,*this,in)));
//return mIndex.ifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in)));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -521,9 +507,12 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto ParallelOperationRoot<T,Ranges...>::assign(const OpClass& in) auto ParallelOperationRoot<T,Ranges...>::assign(const OpClass& in)
-> decltype(mIndex.pifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in)))) -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))))
{ {
return mIndex.pifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in))); return mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>

View file

@ -105,30 +105,6 @@ namespace MultiArrayTools
} }
}; };
template <typename T, class OpClass>
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 <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass>
class AssignmentExpr2 class AssignmentExpr2
{ {
@ -317,12 +293,13 @@ namespace MultiArrayTools
template <class OpClass> template <class OpClass>
auto assign(const OpClass& in) const auto assign(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in)))); -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>
auto assignExpr(const OpClass& in) const auto assignExpr(const OpClass& in) const
-> decltype(in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in))); -> decltype(in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)));
template <class OpClass, class Index> template <class OpClass, class Index>
auto assign(const OpClass& in, const std::shared_ptr<Index>& i) const auto assign(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
@ -388,7 +365,8 @@ namespace MultiArrayTools
template <class OpClass> template <class OpClass>
auto assign(const OpClass& in) auto assign(const OpClass& in)
-> decltype(mIndex.pifor(1,in.loop(AssignmentExpr<T,OpClass>(mOrigDataPtr,in)))); -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>
auto plus(const OpClass& in) auto plus(const OpClass& in)

View file

@ -61,6 +61,8 @@ namespace MultiArrayTools
virtual std::intptr_t get() const = 0; virtual std::intptr_t get() const = 0;
virtual std::intptr_t ptrNum() const = 0; virtual std::intptr_t ptrNum() const = 0;
virtual std::shared_ptr<AbstractIW> duplicate() const = 0;
//virtual DynamicMetaT meta() const = 0; //virtual DynamicMetaT meta() const = 0;
//virtual const DynamicMetaT* metaPtr() const = 0; //virtual const DynamicMetaT* metaPtr() const = 0;
//virtual AbstractIW& at(const U& metaPos) = 0; //virtual AbstractIW& at(const U& metaPos) = 0;
@ -105,6 +107,9 @@ namespace MultiArrayTools
template <class Expr> template <class Expr>
ExpressionHolder<Expr> iforhi(size_t step, Expr ex) const; ExpressionHolder<Expr> iforhi(size_t step, Expr ex) const;
std::shared_ptr<IndexWrapperBase> duplicateI() const
{ return std::dynamic_pointer_cast<IndexWrapperBase>( this->duplicate() ); }
}; };
template <class EC> template <class EC>
@ -165,6 +170,9 @@ namespace MultiArrayTools
virtual std::intptr_t get() const override final { return reinterpret_cast<std::intptr_t>(mI.get()); } virtual std::intptr_t get() const override final { return reinterpret_cast<std::intptr_t>(mI.get()); }
virtual std::intptr_t ptrNum() const override final { return mI->ptrNum(); } virtual std::intptr_t ptrNum() const override final { return mI->ptrNum(); }
virtual std::shared_ptr<AbstractIW> duplicate() const override final
{ return std::make_shared<IndexWrapper>( std::make_shared<Index>( *mI ) ); }
}; };