distinguish target object call depending on the controll index owner

This commit is contained in:
Christian Zimmermann 2020-07-09 11:52:40 +02:00
parent e24e7dddec
commit 354a275c12
2 changed files with 87 additions and 50 deletions

View file

@ -138,88 +138,117 @@ namespace MultiArrayTools
* AssignmentExpr * * AssignmentExpr *
************************/ ************************/
template <typename T, class Target, class OpClass> template <OpIndexAff OIA>
AssignmentExpr2<T,Target,OpClass>::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) : struct OpIndexResolve
{};
template <>
struct OpIndexResolve<OpIndexAff::EXTERN>
{
template <class ExtType>
static inline size_t get(size_t start, ExtType last)
{
return last.val();
}
};
template <>
struct OpIndexResolve<OpIndexAff::TARGET>
{
template <class ExtType>
static inline size_t get(size_t start, ExtType last)
{
return start;
}
};
template <typename T, class Target, class OpClass, OpIndexAff OIA>
AssignmentExpr2<T,Target,OpClass,OIA>::AssignmentExpr2(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> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr2<T,Target,OpClass>::operator()(size_t start) inline void AssignmentExpr2<T,Target,OpClass,OIA>::operator()(size_t start)
{ {
ExtType last; ExtType last;
mDataPtr[last.val()] = mSec.get(last.next()); mDataPtr[OpIndexResolve<OIA>::get(start,last)] = mSec.get(last.next());
//mDataPtr[last.val()] = mSec.get(last.next());
} }
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr2<T,Target,OpClass>::operator()(size_t start, ExtType last) inline void AssignmentExpr2<T,Target,OpClass,OIA>::operator()(size_t start, ExtType last)
{ {
mDataPtr[last.val()] = mSec.get(last.next()); mDataPtr[OpIndexResolve<OIA>::get(start,last)] = mSec.get(last.next());
} }
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass, OpIndexAff OIA>
typename AssignmentExpr2<T,Target,OpClass>::ExtType typename AssignmentExpr2<T,Target,OpClass,OIA>::ExtType
AssignmentExpr2<T,Target,OpClass>::rootSteps(std::intptr_t iPtrNum) const AssignmentExpr2<T,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> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr2<T,Target,OpClass>::operator()(size_t mlast, DExt last) inline void AssignmentExpr2<T,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> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline DExt AssignmentExpr2<T,Target,OpClass>::dRootSteps(std::intptr_t iPtrNum) const inline DExt AssignmentExpr2<T,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> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline DExt AssignmentExpr2<T,Target,OpClass>::dExtension() const inline DExt AssignmentExpr2<T,Target,OpClass,OIA>::dExtension() const
{ {
CHECK; CHECK;
return nullptr; //???!!! return nullptr; //???!!!
} }
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass, OpIndexAff OIA>
AddExpr<T,Target,OpClass>::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) {}
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline void AddExpr<T,Target,OpClass>::operator()(size_t start, ExtType last) inline void AddExpr<T,Target,OpClass,OIA>::operator()(size_t start, ExtType last)
{ {
mDataPtr[last.val()] += mSec.get(last.next()); mDataPtr[OpIndexResolve<OIA>::get(start,last)] += mSec.get(last.next());
//mDataPtr[start] += mSec.get(last.next());
//mDataPtr[start] += mSec.template get<ExtType>(last); //mDataPtr[start] += mSec.template get<ExtType>(last);
} }
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline void AddExpr<T,Target,OpClass>::operator()(size_t start) inline void AddExpr<T,Target,OpClass,OIA>::operator()(size_t start)
{ {
ExtType last; ExtType last;
mDataPtr[last.val()] += mSec.get(last.next()); mDataPtr[OpIndexResolve<OIA>::get(start,last)] += mSec.get(last.next());
} }
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass, OpIndexAff OIA>
typename AddExpr<T,Target,OpClass>::ExtType AddExpr<T,Target,OpClass>::rootSteps(std::intptr_t iPtrNum) const typename AddExpr<T,Target,OpClass,OIA>::ExtType AddExpr<T,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) );
//return mSec.rootSteps(iPtrNum); //return mSec.rootSteps(iPtrNum);
} }
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline void AddExpr<T,Target,OpClass>::operator()(size_t mlast, DExt last) inline void AddExpr<T,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> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline DExt AddExpr<T,Target,OpClass>::dRootSteps(std::intptr_t iPtrNum) const inline DExt AddExpr<T,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> template <typename T, class Target, class OpClass, OpIndexAff OIA>
inline DExt AddExpr<T,Target,OpClass>::dExtension() const inline DExt AddExpr<T,Target,OpClass,OIA>::dExtension() const
{ {
CHECK; CHECK;
return nullptr; //???!!! return nullptr; //???!!!
@ -368,7 +397,6 @@ namespace MultiArrayTools
template <class ET> template <class ET>
inline MetaOperationRoot<Range>& MetaOperationRoot<Range>::set(ET pos) inline MetaOperationRoot<Range>& MetaOperationRoot<Range>::set(ET pos)
{ {
assert(0);
//(*mIndex) = pos.val(); //(*mIndex) = pos.val();
return *this; return *this;
} }
@ -417,22 +445,24 @@ 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(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)))) (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(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass> return mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))); (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(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,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(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)); return in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -449,10 +479,12 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto OperationRoot<T,Ranges...>::plus(const OpClass& in) const auto OperationRoot<T,Ranges...>::plus(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)))) -> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(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(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in))); return mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -571,21 +603,21 @@ 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(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass> -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)))) (mOrigDataPtr,*this,in))))
{ {
return mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass> return mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))); (mOrigDataPtr,*this,in)));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto ParallelOperationRoot<T,Ranges...>::plus(const OpClass& in) auto ParallelOperationRoot<T,Ranges...>::plus(const OpClass& in)
-> decltype(mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass> -> decltype(mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)))) (mOrigDataPtr,*this,in))))
{ {
return mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass> return mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))); (mOrigDataPtr,*this,in)));
} }

View file

@ -107,7 +107,12 @@ namespace MultiArrayTools
} }
}; };
template <typename T, class Target, class OpClass> enum class OpIndexAff {
EXTERN = 0,
TARGET = 1
};
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
class AssignmentExpr2 : public ExpressionBase class AssignmentExpr2 : public ExpressionBase
{ {
private: private:
@ -138,7 +143,7 @@ namespace MultiArrayTools
}; };
//template <typename T, class OpClass> //template <typename T, class OpClass>
template <typename T, class Target, class OpClass> template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
class AddExpr : public ExpressionBase class AddExpr : public ExpressionBase
{ {
private: private:
@ -311,7 +316,7 @@ 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(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)))); (mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>
@ -325,7 +330,7 @@ namespace MultiArrayTools
template <class OpClass> template <class OpClass>
auto plus(const OpClass& in) const auto plus(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass> -> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)))); (mOrigDataPtr,*this,in))));
template <class OpClass, class Index> template <class OpClass, class Index>
@ -389,12 +394,12 @@ namespace MultiArrayTools
template <class OpClass> template <class OpClass>
auto assign(const OpClass& in) auto assign(const OpClass& in)
-> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass> -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)))); (mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>
auto plus(const OpClass& in) auto plus(const OpClass& in)
-> decltype(mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass> -> decltype(mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in)))); (mOrigDataPtr,*this,in))));
template <class OpClass> template <class OpClass>