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

View file

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

View file

@ -85,7 +85,17 @@ namespace MultiArrayHelper
inline auto nn() const
-> decltype(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 None& in) const;
inline MExt operator*(size_t in) const;
@ -110,7 +120,17 @@ namespace MultiArrayHelper
None(const Y& y) {}
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*(size_t in) const { return None(); }
@ -157,7 +177,17 @@ namespace MultiArrayHelper
template <class 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 None next() const { return None(); }