unify AssigmentExpr2 and AddExpr

This commit is contained in:
Christian Zimmermann 2021-01-14 19:20:46 +01:00
parent fdb1bb6833
commit 29b1502e60
3 changed files with 69 additions and 32 deletions

View file

@ -165,50 +165,50 @@ namespace MultiArrayTools
}; };
template <typename T, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA>
AssignmentExpr2<T,Target,OpClass,OIA>::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) : AssignmentExpr<T,IOp,Target,OpClass,OIA>::AssignmentExpr(T* dataPtr, const Target& tar, const OpClass& sec) :
mTar(tar), mSec(sec), mDataPtr(dataPtr) {} mTar(tar), mSec(sec), mDataPtr(dataPtr) {}
template <typename T, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr2<T,Target,OpClass,OIA>::operator()(size_t start) inline void AssignmentExpr<T,IOp,Target,OpClass,OIA>::operator()(size_t start)
{ {
ExtType last = rootSteps(); ExtType last = rootSteps();
last.zero(); last.zero();
//mDataPtr[OpIndexResolve<OIA>::get(start,last)] = mSec.get(last.next()); //mDataPtr[OpIndexResolve<OIA>::get(start,last)] = mSec.get(last.next());
IAssign::f(mDataPtr,OpIndexResolve<OIA>::get(start,last),mSec,last.next()); IOp::f(mDataPtr,OpIndexResolve<OIA>::get(start,last),mSec,last.next());
//mDataPtr[last.val()] = mSec.get(last.next()); //mDataPtr[last.val()] = mSec.get(last.next());
} }
template <typename T, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr2<T,Target,OpClass,OIA>::operator()(size_t start, ExtType last) inline void AssignmentExpr<T,IOp,Target,OpClass,OIA>::operator()(size_t start, ExtType last)
{ {
//CHECK; //CHECK;
//mDataPtr[OpIndexResolve<OIA>::get(start,last)] = mSec.get(last.next()); //mDataPtr[OpIndexResolve<OIA>::get(start,last)] = mSec.get(last.next());
IAssign::f(mDataPtr,OpIndexResolve<OIA>::get(start,last),mSec,last.next()); IOp::f(mDataPtr,OpIndexResolve<OIA>::get(start,last),mSec,last.next());
} }
template <typename T, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA>
typename AssignmentExpr2<T,Target,OpClass,OIA>::ExtType typename AssignmentExpr<T,IOp,Target,OpClass,OIA>::ExtType
AssignmentExpr2<T,Target,OpClass,OIA>::rootSteps(std::intptr_t iPtrNum) const AssignmentExpr<T,IOp,Target,OpClass,OIA>::rootSteps(std::intptr_t iPtrNum) const
{ {
return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) ); return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) );
} }
template <typename T, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr2<T,Target,OpClass,OIA>::operator()(size_t mlast, DExt last) inline void AssignmentExpr<T,IOp,Target,OpClass,OIA>::operator()(size_t mlast, DExt last)
{ {
(*this)(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext()); (*this)(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
} }
template <typename T, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA>
inline DExt AssignmentExpr2<T,Target,OpClass,OIA>::dRootSteps(std::intptr_t iPtrNum) const inline DExt AssignmentExpr<T,IOp,Target,OpClass,OIA>::dRootSteps(std::intptr_t iPtrNum) const
{ {
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum)); return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
} }
template <typename T, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA>
inline DExt AssignmentExpr2<T,Target,OpClass,OIA>::dExtension() const inline DExt AssignmentExpr<T,IOp,Target,OpClass,OIA>::dExtension() const
{ {
CHECK; CHECK;
return nullptr; //???!!! return nullptr; //???!!!
@ -298,7 +298,7 @@ namespace MultiArrayTools
CHECK; CHECK;
return nullptr; //???!!! return nullptr; //???!!!
} }
/*
template <typename T, class Target, class OpClass, OpIndexAff OIA> template <typename T, class Target, class OpClass, OpIndexAff OIA>
AddExpr<T,Target,OpClass,OIA>::AddExpr(T* dataPtr, const Target& tar, const OpClass& sec) : AddExpr<T,Target,OpClass,OIA>::AddExpr(T* dataPtr, const Target& tar, const OpClass& sec) :
mTar(tar), mSec(sec), mDataPtr(dataPtr) {} mTar(tar), mSec(sec), mDataPtr(dataPtr) {}
@ -348,7 +348,7 @@ namespace MultiArrayTools
CHECK; CHECK;
return nullptr; //???!!! return nullptr; //???!!!
} }
*/
/**************************** /****************************
* ConstOperationRoot * * ConstOperationRoot *
****************************/ ****************************/

View file

@ -244,11 +244,11 @@ namespace MultiArrayTools
}; };
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN> template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
class AssignmentExpr2 : public ExpressionBase class AssignmentExpr : public ExpressionBase
{ {
private: private:
AssignmentExpr2() = default; AssignmentExpr() = default;
Target mTar; Target mTar;
OpClass mSec; OpClass mSec;
@ -260,15 +260,15 @@ namespace MultiArrayTools
static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE; static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE;
typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType; typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType;
AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec); AssignmentExpr(T* dataPtr, const Target& tar, const OpClass& sec);
AssignmentExpr2(const AssignmentExpr2& in) = default; AssignmentExpr(const AssignmentExpr& in) = default;
AssignmentExpr2(AssignmentExpr2&& in) = default; AssignmentExpr(AssignmentExpr&& in) = default;
AssignmentExpr2& operator=(const AssignmentExpr2& in) = default; AssignmentExpr& operator=(const AssignmentExpr& in) = default;
AssignmentExpr2& operator=(AssignmentExpr2&& in) = default; AssignmentExpr& operator=(AssignmentExpr&& in) = default;
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
{ {
return std::make_shared<AssignmentExpr2<T,Target,OpClass,OIA>>(*this); return std::make_shared<AssignmentExpr<T,IOp,Target,OpClass,OIA>>(*this);
} }
inline void operator()(size_t start = 0); inline void operator()(size_t start = 0);
@ -281,6 +281,12 @@ namespace MultiArrayTools
inline DExt dExtension() const override final; inline DExt dExtension() const override final;
}; };
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
using AssignmentExpr2 = AssignmentExpr<T,IAssign,Target,OpClass,OIA>;
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
using AddExpr = AssignmentExpr<T,IPlus,Target,OpClass,OIA>;
template <typename T, class... Ops> template <typename T, class... Ops>
class MOp class MOp
{ {
@ -371,6 +377,7 @@ namespace MultiArrayTools
} }
//template <typename T, class OpClass> //template <typename T, class OpClass>
/*
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN> template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
class AddExpr : public ExpressionBase class AddExpr : public ExpressionBase
{ {
@ -411,7 +418,7 @@ namespace MultiArrayTools
inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
inline DExt dExtension() const override final; inline DExt dExtension() const override final;
}; };
*/
template <typename T, class... Ranges> template <typename T, class... Ranges>
class ConstOperationRoot : public OperationTemplate<T,ConstOperationRoot<T,Ranges...> > class ConstOperationRoot : public OperationTemplate<T,ConstOperationRoot<T,Ranges...> >
{ {

View file

@ -86,6 +86,16 @@ namespace MultiArrayHelper
-> decltype(Getter<N>::getX(*this)) -> decltype(Getter<N>::getX(*this))
{ return Getter<N>::getX(*this); } { return Getter<N>::getX(*this); }
inline bool operator==(const MExt& in) const
{
return mExt == in.mExt and mNext == in.mNext;
}
inline bool operator==(size_t in) const
{
return mExt == in and mNext == in;
}
inline MExt operator+(const MExt& in) const; inline MExt operator+(const MExt& in) const;
inline MExt operator+(const None& in) const; inline MExt operator+(const None& in) const;
inline MExt operator*(size_t in) const; inline MExt operator*(size_t in) const;
@ -111,6 +121,16 @@ namespace MultiArrayHelper
static constexpr size_t SIZE = 0; static constexpr size_t SIZE = 0;
inline bool operator==(const None& in) const
{
return true;
}
inline bool operator==(size_t in) const
{
return true; // CHECK!!!
}
inline None operator+(const None& in) const { return None(); } inline None operator+(const None& in) const { return None(); }
inline None operator*(size_t in) const { return None(); } inline None operator*(size_t in) const { return None(); }
@ -158,6 +178,16 @@ namespace MultiArrayHelper
template <class Y> template <class Y>
inline MExt(const MExt<Y>& y); inline MExt(const MExt<Y>& y);
inline bool operator==(const MExt& in) const
{
return mExt == in.mExt;
}
inline bool operator==(size_t in) const
{
return mExt == in;
}
inline const size_t& val() const; inline const size_t& val() const;
inline None next() const { return None(); } inline None next() const { return None(); }