plus operation with foreign index

This commit is contained in:
Christian Zimmermann 2019-11-13 14:08:15 +01:00
parent 388440764e
commit 4a5a413a47
2 changed files with 48 additions and 20 deletions

View file

@ -155,20 +155,22 @@ namespace MultiArrayTools
return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) );
}
template <typename T, class OpClass>
AddExpr<T,OpClass>::AddExpr(T* dataPtr, const OpClass& sec) :
mSec(sec), mDataPtr(dataPtr) {}
template <typename T, class Target, class OpClass>
AddExpr<T,Target,OpClass>::AddExpr(T* dataPtr, const Target& tar, const OpClass& sec) :
mTar(tar), mSec(sec), mDataPtr(dataPtr) {}
template <typename T, class OpClass>
inline void AddExpr<T,OpClass>::operator()(size_t start, ExtType last)
template <typename T, class Target, class OpClass>
inline void AddExpr<T,Target,OpClass>::operator()(size_t start, ExtType last)
{
mDataPtr[start] += mSec.template get<ExtType>(last);
mDataPtr[last.val()] += mSec.get(last.next());
//mDataPtr[start] += mSec.template get<ExtType>(last);
}
template <typename T, class OpClass>
typename AddExpr<T,OpClass>::ExtType AddExpr<T,OpClass>::rootSteps(std::intptr_t iPtrNum) const
template <typename T, class Target, class OpClass>
typename AddExpr<T,Target,OpClass>::ExtType AddExpr<T,Target,OpClass>::rootSteps(std::intptr_t iPtrNum) const
{
return mSec.rootSteps(iPtrNum);
return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) );
//return mSec.rootSteps(iPtrNum);
}
@ -396,12 +398,23 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
template <class OpClass>
auto OperationRoot<T,Ranges...>::plus(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OpClass>(mOrigDataPtr,in))))
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in))))
{
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return mIndex.ifor(1,in.loop(AddExpr<T,OpClass>(mOrigDataPtr,in)));
return mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)));
}
template <typename T, class... Ranges>
template <class OpClass, class Index>
auto OperationRoot<T,Ranges...>::plus(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))))
{
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return i->ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)));
}
template <typename T, class... Ranges>
template <class OpClass>
OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::operator=(const OpClass& in)
@ -518,9 +531,11 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
template <class OpClass>
auto ParallelOperationRoot<T,Ranges...>::plus(const OpClass& in)
-> decltype(mIndex.pifor(1,in.loop(AddExpr<T,OpClass>(mOrigDataPtr,in))))
-> decltype(mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))))
{
return mIndex.pifor(1,in.loop(AddExpr<T,OpClass>(mOrigDataPtr,in)));
return mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)));
}
template <typename T, class... Ranges>

View file

@ -130,22 +130,28 @@ namespace MultiArrayTools
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
};
template <typename T, class OpClass>
//template <typename T, class OpClass>
template <typename T, class Target, class OpClass>
class AddExpr
{
private:
AddExpr() = default;
Target mTar;
OpClass mSec;
T* mDataPtr;
public:
static constexpr size_t LAYER = 0;
static constexpr size_t SIZE = OpClass::SIZE;
typedef decltype(mSec.rootSteps()) ExtType;
static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE;
typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType;
// static constexpr size_t LAYER = 0;
//static constexpr size_t SIZE = OpClass::SIZE;
//typedef decltype(mSec.rootSteps()) ExtType;
AddExpr(T* dataPtr, const OpClass& sec);
//AddExpr(T* dataPtr, const OpClass& sec);
AddExpr(T* dataPtr, const Target& tar, const OpClass& sec);
AddExpr(const AddExpr& in) = default;
AddExpr(AddExpr&& in) = default;
@ -307,8 +313,14 @@ namespace MultiArrayTools
template <class OpClass>
auto plus(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OpClass>(mOrigDataPtr,in))));
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))));
template <class OpClass, class Index>
auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))));
template <class OpClass>
OperationRoot& operator=(const OpClass& in);
@ -370,7 +382,8 @@ namespace MultiArrayTools
template <class OpClass>
auto plus(const OpClass& in)
-> decltype(mIndex.pifor(1,in.loop(AddExpr<T,OpClass>(mOrigDataPtr,in))));
-> decltype(mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))));
template <class OpClass>
ParallelOperationRoot& operator=(const OpClass& in);