im com (some weird runtime errors -> PointerAccess)

This commit is contained in:
Christian Zimmermann 2021-07-09 16:54:30 +02:00
parent 33b52c1a70
commit bf4633054d
2 changed files with 119 additions and 110 deletions

View file

@ -152,6 +152,12 @@ namespace MultiArrayTools
return THIS().get(pos); return THIS().get(pos);
} }
template <class AccessClass>
auto AccessTemplate<AccessClass>::oget(size_t pos) const
{
return THIS().oget(pos);
}
template <class AccessClass> template <class AccessClass>
template <class F, typename Op, class ExtType> template <class F, typename Op, class ExtType>
void AccessTemplate<AccessClass>::exec(size_t pos, const Op& op, ExtType e) const void AccessTemplate<AccessClass>::exec(size_t pos, const Op& op, ExtType e) const
@ -174,47 +180,63 @@ namespace MultiArrayTools
} }
return 0; return 0;
} }
/*
template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA> 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) : 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 IOp, class AT, class Target, class OpClass, OpIndexAff OIA>
AssignmentExpr<T,IOp,AT,Target,OpClass,OIA>::AssignmentExpr(T* dataPtr, const AccessTemplate<AT>& dataAcc, const Target& tar, const OpClass& sec) :
mTar(tar), mSec(sec), mDataAcc(dataAcc), mDataPtr(dataPtr) {}
template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class AT, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr<T,IOp,Target,OpClass,OIA>::operator()(size_t start) inline void AssignmentExpr<T,IOp,AT,Target,OpClass,OIA>::operator()(size_t start)
{ {
ExtType last = rootSteps(); ExtType last = rootSteps();
last.zero(); last.zero();
// TODO: ask MA container for data (ptr)!!! // TODO: ask MA container for data (ptr)!!!
IOp::f(mDataPtr,opIndexResolve<OIA>(start,last),mSec,last.next()); //mDataAcc.template exec<typename IOp::Func>(opIndexResolve<OIA>(start,last),mSec,last.next());
assert(mDataAcc.get(0) != nullptr);
assert(mDataAcc.oget(0) != nullptr);
assert(mDataPtr == mDataAcc.oget(0));
IOp::f(mDataAcc.oget(0),opIndexResolve<OIA>(start,last),mSec,last.next());
//IOp::f(mDataPtr,opIndexResolve<OIA>(start,last),mSec,last.next());
} }
template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class AT, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr<T,IOp,Target,OpClass,OIA>::operator()(size_t start, ExtType last) inline void AssignmentExpr<T,IOp,AT,Target,OpClass,OIA>::operator()(size_t start, ExtType last)
{ {
IOp::f(mDataPtr,opIndexResolve<OIA>(start,last),mSec,last.next()); //PointerAccess<T> pa(mDataPtr, mDataPtr);
//pa.template exec<IOp::Func>(opIndexResolve<OIA>(start,last),mSec,last.next());
//mDataAcc.template exec<typename IOp::Func>(opIndexResolve<OIA>(start,last),mSec,last.next());
assert(mDataAcc.get(0) != nullptr);
assert(mDataAcc.oget(0) != nullptr);
assert(mDataPtr == mDataAcc.oget(0));
IOp::f(mDataAcc.oget(0),opIndexResolve<OIA>(start,last),mSec,last.next());
//IOp::f(mDataPtr,opIndexResolve<OIA>(start,last),mSec,last.next());
} }
template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class AT, class Target, class OpClass, OpIndexAff OIA>
typename AssignmentExpr<T,IOp,Target,OpClass,OIA>::ExtType typename AssignmentExpr<T,IOp,AT,Target,OpClass,OIA>::ExtType
AssignmentExpr<T,IOp,Target,OpClass,OIA>::rootSteps(std::intptr_t iPtrNum) const AssignmentExpr<T,IOp,AT,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 IOp, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class AT, class Target, class OpClass, OpIndexAff OIA>
inline void AssignmentExpr<T,IOp,Target,OpClass,OIA>::operator()(size_t mlast, DExt last) inline void AssignmentExpr<T,IOp,AT,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 IOp, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class AT, class Target, class OpClass, OpIndexAff OIA>
inline DExt AssignmentExpr<T,IOp,Target,OpClass,OIA>::dRootSteps(std::intptr_t iPtrNum) const inline DExt AssignmentExpr<T,IOp,AT,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 IOp, class Target, class OpClass, OpIndexAff OIA> template <typename T, class IOp, class AT, class Target, class OpClass, OpIndexAff OIA>
inline DExt AssignmentExpr<T,IOp,Target,OpClass,OIA>::dExtension() const inline DExt AssignmentExpr<T,IOp,AT,Target,OpClass,OIA>::dExtension() const
{ {
return nullptr; //???!!! return nullptr; //???!!!
} }
@ -513,78 +535,72 @@ namespace MultiArrayTools
OperationRoot<T,Ranges...>:: OperationRoot<T,Ranges...>::
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma, OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) : const std::shared_ptr<typename Ranges::IndexType>&... indices) :
//mDataPtr(ma.data()), mDataPtr(ma.data()),
//mOrigDataPtr(ma.data()), mOrigDataPtr(ma.data()),
mDataAcc( ma.data(), ma.data() ), mDataAcc( ma.data(), ma.data() ),
mIndex( ma.begin() ) mIndex( ma.begin() )
{ {
mIndex(indices...); mIndex(indices...);
mDataAcc.set( mIndex.pos() ); mDataAcc.set( mIndex.pos() );
//mDataPtr = mOrigDataPtr + mIndex.pos(); mDataPtr = mOrigDataPtr + mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
OperationRoot<T,Ranges...>:: OperationRoot<T,Ranges...>::
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma, OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::tuple<std::shared_ptr<typename Ranges::IndexType>...>& indices) : const std::tuple<std::shared_ptr<typename Ranges::IndexType>...>& indices) :
//mDataPtr(ma.data()), mDataPtr(ma.data()),
//mOrigDataPtr(ma.data()), mOrigDataPtr(ma.data()),
mDataAcc( ma.data(), ma.data() ),
mIndex( ma.begin() ) mIndex( ma.begin() )
{ {
mIndex(indices); mIndex(indices);
mDataAcc.set( mIndex.pos() ); mDataAcc.set( mIndex.pos() );
//mDataPtr = mOrigDataPtr + mIndex.pos(); mDataPtr = mOrigDataPtr + mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
OperationRoot<T,Ranges...>:: OperationRoot<T,Ranges...>::
OperationRoot(T* data, const IndexType& ind) : OperationRoot(T* data, const IndexType& ind) :
//mDataPtr(data), mDataPtr(data),
//mOrigDataPtr(data), mOrigDataPtr(data),
mDataAcc( data, data ),
mIndex( ind ) mIndex( ind )
{ {
mDataAcc.set( mIndex.pos() ); mDataAcc.set( mIndex.pos() );
//mDataPtr = mOrigDataPtr + mIndex.pos(); mDataPtr = mOrigDataPtr + mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class IOp, class OpClass> template <class IOp, class OpClass>
auto OperationRoot<T,Ranges...>::asx(const OpClass& in) const auto OperationRoot<T,Ranges...>::asx(const OpClass& in) const
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>())
{ {
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,IOp,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET> return mIndex.ifor(1,in.loop(AssignmentExpr<T,IOp,PointerAccess<T>,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>(); (mOrigDataPtr,mDataAcc,*this,in))).template vec<IOp::VSIZE>();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class IOp, class OpClass> template <class IOp, class OpClass>
auto OperationRoot<T,Ranges...>::asxExpr(const OpClass& in) const auto OperationRoot<T,Ranges...>::asxExpr(const OpClass& in) const
-> decltype(in.loop(AssignmentExpr<T,IOp,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,IOp,OperationRoot<T,Ranges...>,OpClass> return in.loop(AssignmentExpr<T,IOp,PointerAccess<T>,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)); (mOrigDataPtr,mDataAcc,*this,in));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class IOp, class OpClass, class Index> template <class IOp, class OpClass, class Index>
auto OperationRoot<T,Ranges...>::asx(const OpClass& in, const std::shared_ptr<Index>& i) const auto OperationRoot<T,Ranges...>::asx(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>())
{ {
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(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass> return i->ifor(1,in.loop(AssignmentExpr<T,IOp,PointerAccess<T>,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>(); (mOrigDataPtr,mDataAcc,*this,in))).template vec<IOp::VSIZE>();
} }
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(this->template asx<IAssign<T>>(in))
{ {
return this->template asx<IAssign<T>>(in); return this->template asx<IAssign<T>>(in);
} }
@ -592,7 +608,6 @@ namespace MultiArrayTools
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(this->template asxExpr<IAssign<T>>(in))
{ {
return this->template asxExpr<IAssign<T>>(in); return this->template asxExpr<IAssign<T>>(in);
} }
@ -600,7 +615,6 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass, class Index> template <class OpClass, class Index>
auto OperationRoot<T,Ranges...>::assign(const OpClass& in, const std::shared_ptr<Index>& i) const auto OperationRoot<T,Ranges...>::assign(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(this->template asx<IAssign<T>>(in,i))
{ {
return this->template asx<IAssign<T>>(in,i); return this->template asx<IAssign<T>>(in,i);
} }
@ -608,7 +622,6 @@ 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(this->template asx<IPlus<T>>(in))
{ {
return this->template asx<IPlus<T>>(in); return this->template asx<IPlus<T>>(in);
} }
@ -616,7 +629,6 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass, class Index> template <class OpClass, class Index>
auto OperationRoot<T,Ranges...>::plus(const OpClass& in, const std::shared_ptr<Index>& i) const auto OperationRoot<T,Ranges...>::plus(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(this->template asx<IPlus<T>>(in,i))
{ {
return this->template asx<IPlus<T>>(in,i); return this->template asx<IPlus<T>>(in,i);
} }
@ -676,6 +688,7 @@ namespace MultiArrayTools
template <class ET> template <class ET>
inline T& OperationRoot<T,Ranges...>::get(ET pos) const inline T& OperationRoot<T,Ranges...>::get(ET pos) const
{ {
assert(mDataAcc.get(pos.val()) == mDataPtr+pos.val());
return *mDataAcc.get(pos.val()); return *mDataAcc.get(pos.val());
//return mDataPtr[pos.val()]; //return mDataPtr[pos.val()];
} }
@ -684,6 +697,7 @@ namespace MultiArrayTools
template <typename V, class ET> template <typename V, class ET>
inline V& OperationRoot<T,Ranges...>::vget(ET pos) const inline V& OperationRoot<T,Ranges...>::vget(ET pos) const
{ {
assert(mDataAcc.get(pos.val()) == mDataPtr+pos.val());
return *(reinterpret_cast<V*>(mDataAcc.get(pos.val()))); return *(reinterpret_cast<V*>(mDataAcc.get(pos.val())));
//return *(reinterpret_cast<V*>(mDataPtr+pos.val())); //return *(reinterpret_cast<V*>(mDataPtr+pos.val()));
} }
@ -693,7 +707,8 @@ namespace MultiArrayTools
inline OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::set(ET pos) inline OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::set(ET pos)
{ {
mDataAcc.set(pos.val()); mDataAcc.set(pos.val());
//mDataPtr = mOrigDataPtr + pos.val(); mDataPtr = mOrigDataPtr + pos.val();
assert(mDataAcc.get(0) == mDataPtr);
return *this; return *this;
} }
@ -713,6 +728,7 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
T* OperationRoot<T,Ranges...>::data() const T* OperationRoot<T,Ranges...>::data() const
{ {
assert(mDataAcc.get(0) == mDataPtr);
return mDataAcc.get(0); return mDataAcc.get(0);
//return mDataPtr; //return mDataPtr;
} }
@ -737,6 +753,7 @@ namespace MultiArrayTools
const std::shared_ptr<typename Ranges::IndexType>&... indices) : const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mDataPtr(ma.data()), mDataPtr(ma.data()),
mOrigDataPtr(ma.data()), mOrigDataPtr(ma.data()),
mDataAcc( ma.data(), ma.data() ),
mIndex( ma.begin() ) mIndex( ma.begin() )
{ {
mIndex(indices...); mIndex(indices...);
@ -748,6 +765,7 @@ namespace MultiArrayTools
ParallelOperationRoot(T* data, const IndexType& ind) : ParallelOperationRoot(T* data, const IndexType& ind) :
mDataPtr(data), mDataPtr(data),
mOrigDataPtr(data), mOrigDataPtr(data),
mDataAcc( data, data ),
mIndex( ind ) mIndex( ind )
{ {
mDataPtr = mOrigDataPtr + mIndex.pos(); mDataPtr = mOrigDataPtr + mIndex.pos();
@ -756,41 +774,33 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class IOp, class OpClass> template <class IOp, class OpClass>
auto ParallelOperationRoot<T,Ranges...>::asx(const OpClass& in) const auto ParallelOperationRoot<T,Ranges...>::asx(const OpClass& in) const
-> decltype(mIndex.pifor(1,in.loop(AssignmentExpr<T,IOp,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>())
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return mIndex.pifor(1,in.loop(AssignmentExpr<T,IOp,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET> return mIndex.pifor(1,in.loop(AssignmentExpr<T,IOp,PointerAccess<T>,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>(); (mOrigDataPtr,mDataAcc,*this,in))).template vec<IOp::VSIZE>();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class IOp, class OpClass> template <class IOp, class OpClass>
auto ParallelOperationRoot<T,Ranges...>::asxExpr(const OpClass& in) const auto ParallelOperationRoot<T,Ranges...>::asxExpr(const OpClass& in) const
-> decltype(in.loop(AssignmentExpr<T,IOp,ParallelOperationRoot<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,IOp,ParallelOperationRoot<T,Ranges...>,OpClass> return in.loop(AssignmentExpr<T,IOp,PointerAccess<T>,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in)); (mOrigDataPtr,mDataAcc,*this,in));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class IOp, class OpClass, class Index> template <class IOp, class OpClass, class Index>
auto ParallelOperationRoot<T,Ranges...>::asx(const OpClass& in, const std::shared_ptr<Index>& i) const auto ParallelOperationRoot<T,Ranges...>::asx(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(i->pifor(1,in.loop(AssignmentExpr<T,IOp,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>())
{ {
static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" );
return i->pifor(1,in.loop(AssignmentExpr<T,IOp,ParallelOperationRoot<T,Ranges...>,OpClass> return i->pifor(1,in.loop(AssignmentExpr<T,IOp,PointerAccess<T>,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>(); (mOrigDataPtr,mDataAcc,*this,in))).template vec<IOp::VSIZE>();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto ParallelOperationRoot<T,Ranges...>::assign(const OpClass& in) const auto ParallelOperationRoot<T,Ranges...>::assign(const OpClass& in) const
-> decltype(this->template asx<IAssign<T>>(in))
{ {
return this->template asx<IAssign<T>>(in); return this->template asx<IAssign<T>>(in);
} }
@ -798,7 +808,6 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto ParallelOperationRoot<T,Ranges...>::assignExpr(const OpClass& in) const auto ParallelOperationRoot<T,Ranges...>::assignExpr(const OpClass& in) const
-> decltype(this->template asxExpr<IAssign<T>>(in))
{ {
return this->template asxExpr<IAssign<T>>(in); return this->template asxExpr<IAssign<T>>(in);
} }
@ -806,7 +815,6 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass, class Index> template <class OpClass, class Index>
auto ParallelOperationRoot<T,Ranges...>::assign(const OpClass& in, const std::shared_ptr<Index>& i) const auto ParallelOperationRoot<T,Ranges...>::assign(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(this->template asx<IAssign<T>>(in,i))
{ {
return this->template asx<IAssign<T>>(in,i); return this->template asx<IAssign<T>>(in,i);
} }
@ -814,7 +822,6 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
auto ParallelOperationRoot<T,Ranges...>::plus(const OpClass& in) const auto ParallelOperationRoot<T,Ranges...>::plus(const OpClass& in) const
-> decltype(this->template asx<IPlus<T>>(in))
{ {
return this->template asx<IPlus<T>>(in); return this->template asx<IPlus<T>>(in);
} }
@ -822,7 +829,6 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass, class Index> template <class OpClass, class Index>
auto ParallelOperationRoot<T,Ranges...>::plus(const OpClass& in, const std::shared_ptr<Index>& i) const auto ParallelOperationRoot<T,Ranges...>::plus(const OpClass& in, const std::shared_ptr<Index>& i) const
-> decltype(this->template asx<IPlus<T>>(in,i))
{ {
return this->template asx<IPlus<T>>(in,i); return this->template asx<IPlus<T>>(in,i);
} }

View file

@ -133,9 +133,12 @@ namespace MultiArrayTools
// empty, implement corresponding constructors...!!! // empty, implement corresponding constructors...!!!
} }
/*
template <class F> template <class F>
using VFunc = decltype(mkVFunc(std::declval<F>())); using VFunc = decltype(mkVFunc(std::declval<F>()));
*/
template <class F>
using VFunc = F;
template <typename T, class F, class... Indices> template <typename T, class F, class... Indices>
class OpAccess class OpAccess
@ -164,21 +167,26 @@ namespace MultiArrayTools
static constexpr bool ISSTATIC = true; static constexpr bool ISSTATIC = true;
typedef T value_type; typedef T value_type;
typedef T in_type; typedef T in_type;
typedef F Func;
static constexpr size_t VSIZE = sizeof(value_type) / sizeof(in_type); static constexpr size_t VSIZE = sizeof(value_type) / sizeof(in_type);
template <typename Op, class ExtType> template <typename Op, class ExtType>
static inline void f(T*& t, size_t pos, const Op& op, ExtType e) static inline void f(T* t, size_t pos, const Op& op, ExtType e)
{ {
F::selfApply(t[pos],op.get(e)); F::selfApply(t[pos],op.get(e));
} }
}; };
template <typename T, class F>
using IVAccess = IAccess<T,F>;
/*
template <typename T, class F> template <typename T, class F>
struct IVAccess struct IVAccess
{ {
static constexpr bool ISSTATIC = true; static constexpr bool ISSTATIC = true;
typedef typename VType<T>::type value_type; typedef typename VType<T>::type value_type;
typedef T in_type; typedef T in_type;
typedef VFunc<F> Func;
static constexpr size_t VSIZE = sizeof(value_type) / sizeof(in_type); static constexpr size_t VSIZE = sizeof(value_type) / sizeof(in_type);
template <typename Op, class ExtType> template <typename Op, class ExtType>
@ -188,6 +196,7 @@ namespace MultiArrayTools
VFunc<F>::selfApply(*reinterpret_cast<value_type*>(t+pos),op.template vget<value_type>(e)); VFunc<F>::selfApply(*reinterpret_cast<value_type*>(t+pos),op.template vget<value_type>(e));
} }
}; };
*/
template <typename T> template <typename T>
using xxxplus = plus<T>; using xxxplus = plus<T>;
@ -216,9 +225,13 @@ namespace MultiArrayTools
inline auto get(size_t pos); inline auto get(size_t pos);
inline auto get(size_t pos) const; inline auto get(size_t pos) const;
inline auto oget(size_t pos) const;
template <class F, typename Op, class ExtType> template <class F, typename Op, class ExtType>
inline void exec(size_t pos, const Op& op, ExtType e) const; inline void exec(size_t pos, const Op& op, ExtType e) const;
protected:
AccessTemplate() = default;
}; };
template <typename T> template <typename T>
@ -228,15 +241,22 @@ namespace MultiArrayTools
typedef T value_type; typedef T value_type;
typedef T in_type; typedef T in_type;
private: private:
T* mPtr; PointerAccess() = default;
T* mOrigPtr;
T* mPtr = nullptr;
T* mOrigPtr = nullptr;
public: public:
PointerAccess(T* ptr, T* origPtr) : mPtr(ptr), mOrigPtr(origPtr) {} PointerAccess(T* ptr, T* origPtr) : mPtr(ptr), mOrigPtr(origPtr) {}
PointerAccess(const PointerAccess& in) = default;
PointerAccess(PointerAccess&& in) = default;
PointerAccess& operator=(const PointerAccess& in) = default;
PointerAccess& operator=(PointerAccess&& in) = default;
T* get(size_t pos) { return mPtr+pos; } T* get(size_t pos) { return mPtr+pos; }
T* get(size_t pos) const { return mPtr+pos; } T* get(size_t pos) const { return mPtr+pos; }
PointerAccess<T>& set(size_t pos) { mPtr = mOrigPtr + pos; return *this; } PointerAccess<T>& set(size_t pos) { mPtr = mOrigPtr + pos; return *this; }
T* oget(size_t pos) const { return mOrigPtr+pos; }
template <class F, typename Op, class ExtType> template <class F, typename Op, class ExtType>
inline void exec(size_t pos, const Op& op, ExtType e) const inline void exec(size_t pos, const Op& op, ExtType e) const
@ -264,7 +284,7 @@ namespace MultiArrayTools
inline void exec(size_t pos, const Op& op, ExtType e) const { assert(0); } inline void exec(size_t pos, const Op& op, ExtType e) const { assert(0); }
}; };
template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN> template <typename T, class IOp, class AT, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
class AssignmentExpr : public ExpressionBase class AssignmentExpr : public ExpressionBase
{ {
private: private:
@ -272,6 +292,7 @@ namespace MultiArrayTools
Target mTar; Target mTar;
OpClass mSec; OpClass mSec;
AccessTemplate<AT> mDataAcc;
T* mDataPtr; T* mDataPtr;
public: public:
@ -281,7 +302,8 @@ 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;
AssignmentExpr(T* dataPtr, const Target& tar, const OpClass& sec); //AssignmentExpr(T* dataPtr, const Target& tar, const OpClass& sec);
AssignmentExpr(T* dataPtr, const AccessTemplate<AT>& dataAcc, const Target& tar, const OpClass& sec);
AssignmentExpr(const AssignmentExpr& in) = default; AssignmentExpr(const AssignmentExpr& in) = default;
AssignmentExpr(AssignmentExpr&& in) = default; AssignmentExpr(AssignmentExpr&& in) = default;
AssignmentExpr& operator=(const AssignmentExpr& in) = default; AssignmentExpr& operator=(const AssignmentExpr& in) = default;
@ -289,7 +311,7 @@ namespace MultiArrayTools
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
{ {
return std::make_shared<AssignmentExpr<T,IOp,Target,OpClass,OIA>>(*this); return std::make_shared<AssignmentExpr<T,IOp,PointerAccess<T>,Target,OpClass,OIA>>(*this);
} }
inline void operator()(size_t start = 0); inline void operator()(size_t start = 0);
@ -303,10 +325,10 @@ namespace MultiArrayTools
}; };
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN> template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
using AssignmentExpr2 = AssignmentExpr<T,IAssign<T>,Target,OpClass,OIA>; using AssignmentExpr2 = AssignmentExpr<T,IAssign<T>,PointerAccess<T>,Target,OpClass,OIA>;
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN> template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
using AddExpr = AssignmentExpr<T,IPlus<T>,Target,OpClass,OIA>; using AddExpr = AssignmentExpr<T,IPlus<T>,PointerAccess<T>,Target,OpClass,OIA>;
template <class... Ops> template <class... Ops>
struct OperationTuple struct OperationTuple
@ -554,8 +576,8 @@ namespace MultiArrayTools
private: private:
//T* mDataPtr; T* mDataPtr;
//T* mOrigDataPtr; T* mOrigDataPtr;
PointerAccess<T> mDataAcc; PointerAccess<T> mDataAcc;
IndexType mIndex; IndexType mIndex;
@ -569,38 +591,28 @@ namespace MultiArrayTools
OperationRoot(T* data, const IndexType& ind); OperationRoot(T* data, const IndexType& ind);
template <class IOp, class OpClass> template <class IOp, class OpClass>
auto asx(const OpClass& in) const auto asx(const OpClass& in) const;
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>());
template <class IOp, class OpClass> template <class IOp, class OpClass>
auto asxExpr(const OpClass& in) const auto asxExpr(const OpClass& in) const;
-> decltype(in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)));
template <class IOp, class OpClass, class Index> template <class IOp, class OpClass, class Index>
auto asx(const OpClass& in, const std::shared_ptr<Index>& i) const auto asx(const OpClass& in, const std::shared_ptr<Index>& i) const;
-> decltype(i->ifor(1,in.loop(AssignmentExpr<T,IOp,OperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>());
template <class OpClass> template <class OpClass>
auto assign(const OpClass& in) const auto assign(const OpClass& in) const;
-> decltype(this->template asx<IAssign<T>>(in));
template <class OpClass> template <class OpClass>
auto assignExpr(const OpClass& in) const auto assignExpr(const OpClass& in) const;
-> decltype(this->template asxExpr<IAssign<T>>(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(this->template asx<IAssign<T>>(in,i));
template <class OpClass> template <class OpClass>
auto plus(const OpClass& in) const auto plus(const OpClass& in) const;
-> decltype(this->template asx<IPlus<T>>(in));
template <class OpClass, class Index> template <class OpClass, class Index>
auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const;
-> decltype(this->template asx<IPlus<T>>(in,i));
template <class OpClass> template <class OpClass>
OperationRoot& operator=(const OpClass& in); OperationRoot& operator=(const OpClass& in);
@ -652,6 +664,7 @@ namespace MultiArrayTools
T* mDataPtr; T* mDataPtr;
T* mOrigDataPtr; T* mOrigDataPtr;
PointerAccess<T> mDataAcc;
IndexType mIndex; IndexType mIndex;
public: public:
@ -661,38 +674,28 @@ namespace MultiArrayTools
ParallelOperationRoot(T* data, const IndexType& ind); ParallelOperationRoot(T* data, const IndexType& ind);
template <class IOp, class OpClass> template <class IOp, class OpClass>
auto asx(const OpClass& in) const auto asx(const OpClass& in) const;
-> decltype(mIndex.pifor(1,in.loop(AssignmentExpr<T,IOp,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>());
template <class IOp, class OpClass> template <class IOp, class OpClass>
auto asxExpr(const OpClass& in) const auto asxExpr(const OpClass& in) const;
-> decltype(in.loop(AssignmentExpr<T,IOp,ParallelOperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)));
template <class IOp, class OpClass, class Index> template <class IOp, class OpClass, class Index>
auto asx(const OpClass& in, const std::shared_ptr<Index>& i) const auto asx(const OpClass& in, const std::shared_ptr<Index>& i) const;
-> decltype(i->pifor(1,in.loop(AssignmentExpr<T,IOp,ParallelOperationRoot<T,Ranges...>,OpClass>
(mOrigDataPtr,*this,in))).template vec<IOp::VSIZE>());
template <class OpClass> template <class OpClass>
auto assign(const OpClass& in) const auto assign(const OpClass& in) const;
-> decltype(this->template asx<IAssign<T>>(in));
template <class OpClass> template <class OpClass>
auto assignExpr(const OpClass& in) const auto assignExpr(const OpClass& in) const;
-> decltype(this->template asxExpr<IAssign<T>>(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(this->template asx<IAssign<T>>(in,i));
template <class OpClass> template <class OpClass>
auto plus(const OpClass& in) const auto plus(const OpClass& in) const;
-> decltype(this->template asx<IPlus<T>>(in));
template <class OpClass, class Index> template <class OpClass, class Index>
auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const;
-> decltype(this->template asx<IPlus<T>>(in,i));
template <class OpClass> template <class OpClass>
ParallelOperationRoot& operator=(const OpClass& in); ParallelOperationRoot& operator=(const OpClass& in);