From bf4633054dadc5d18e1013d8b36ac5228a1e4455 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 9 Jul 2021 16:54:30 +0200 Subject: [PATCH] im com (some weird runtime errors -> PointerAccess) --- src/include/multi_array_operation.cc.h | 132 +++++++++++++------------ src/include/multi_array_operation.h | 97 +++++++++--------- 2 files changed, 119 insertions(+), 110 deletions(-) diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 2ccd7af..79a3568 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -152,6 +152,12 @@ namespace MultiArrayTools return THIS().get(pos); } + template + auto AccessTemplate::oget(size_t pos) const + { + return THIS().oget(pos); + } + template template void AccessTemplate::exec(size_t pos, const Op& op, ExtType e) const @@ -174,47 +180,63 @@ namespace MultiArrayTools } return 0; } - + /* template AssignmentExpr::AssignmentExpr(T* dataPtr, const Target& tar, const OpClass& sec) : mTar(tar), mSec(sec), mDataPtr(dataPtr) {} - - template - inline void AssignmentExpr::operator()(size_t start) + */ + template + AssignmentExpr::AssignmentExpr(T* dataPtr, const AccessTemplate& dataAcc, const Target& tar, const OpClass& sec) : + mTar(tar), mSec(sec), mDataAcc(dataAcc), mDataPtr(dataPtr) {} + + template + inline void AssignmentExpr::operator()(size_t start) { ExtType last = rootSteps(); last.zero(); // TODO: ask MA container for data (ptr)!!! - IOp::f(mDataPtr,opIndexResolve(start,last),mSec,last.next()); + //mDataAcc.template exec(opIndexResolve(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(start,last),mSec,last.next()); + //IOp::f(mDataPtr,opIndexResolve(start,last),mSec,last.next()); } - template - inline void AssignmentExpr::operator()(size_t start, ExtType last) + template + inline void AssignmentExpr::operator()(size_t start, ExtType last) { - IOp::f(mDataPtr,opIndexResolve(start,last),mSec,last.next()); + //PointerAccess pa(mDataPtr, mDataPtr); + //pa.template exec(opIndexResolve(start,last),mSec,last.next()); + //mDataAcc.template exec(opIndexResolve(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(start,last),mSec,last.next()); + //IOp::f(mDataPtr,opIndexResolve(start,last),mSec,last.next()); } - template - typename AssignmentExpr::ExtType - AssignmentExpr::rootSteps(std::intptr_t iPtrNum) const + template + typename AssignmentExpr::ExtType + AssignmentExpr::rootSteps(std::intptr_t iPtrNum) const { return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) ); } - template - inline void AssignmentExpr::operator()(size_t mlast, DExt last) + template + inline void AssignmentExpr::operator()(size_t mlast, DExt last) { (*this)(mlast, std::dynamic_pointer_cast>(last)->ext()); } - template - inline DExt AssignmentExpr::dRootSteps(std::intptr_t iPtrNum) const + template + inline DExt AssignmentExpr::dRootSteps(std::intptr_t iPtrNum) const { return std::make_shared>(rootSteps(iPtrNum)); } - template - inline DExt AssignmentExpr::dExtension() const + template + inline DExt AssignmentExpr::dExtension() const { return nullptr; //???!!! } @@ -513,78 +535,72 @@ namespace MultiArrayTools OperationRoot:: OperationRoot(MutableMultiArrayBase& ma, const std::shared_ptr&... indices) : - //mDataPtr(ma.data()), - //mOrigDataPtr(ma.data()), + mDataPtr(ma.data()), + mOrigDataPtr(ma.data()), mDataAcc( ma.data(), ma.data() ), mIndex( ma.begin() ) { mIndex(indices...); mDataAcc.set( mIndex.pos() ); - //mDataPtr = mOrigDataPtr + mIndex.pos(); + mDataPtr = mOrigDataPtr + mIndex.pos(); } template OperationRoot:: OperationRoot(MutableMultiArrayBase& ma, const std::tuple...>& indices) : - //mDataPtr(ma.data()), - //mOrigDataPtr(ma.data()), + mDataPtr(ma.data()), + mOrigDataPtr(ma.data()), + mDataAcc( ma.data(), ma.data() ), mIndex( ma.begin() ) { mIndex(indices); mDataAcc.set( mIndex.pos() ); - //mDataPtr = mOrigDataPtr + mIndex.pos(); + mDataPtr = mOrigDataPtr + mIndex.pos(); } template OperationRoot:: OperationRoot(T* data, const IndexType& ind) : - //mDataPtr(data), - //mOrigDataPtr(data), + mDataPtr(data), + mOrigDataPtr(data), + mDataAcc( data, data ), mIndex( ind ) { mDataAcc.set( mIndex.pos() ); - //mDataPtr = mOrigDataPtr + mIndex.pos(); + mDataPtr = mOrigDataPtr + mIndex.pos(); } template template auto OperationRoot::asx(const OpClass& in) const - -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in))).template vec()) - { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return mIndex.ifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in))).template vec(); + return mIndex.ifor(1,in.loop(AssignmentExpr,OperationRoot,OpClass,OpIndexAff::TARGET> + (mOrigDataPtr,mDataAcc,*this,in))).template vec(); } template template auto OperationRoot::asxExpr(const OpClass& in) const - -> decltype(in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in)); + return in.loop(AssignmentExpr,OperationRoot,OpClass> + (mOrigDataPtr,mDataAcc,*this,in)); } template template auto OperationRoot::asx(const OpClass& in, const std::shared_ptr& i) const - -> decltype(i->ifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))).template vec()) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return i->ifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))).template vec(); + return i->ifor(1,in.loop(AssignmentExpr,OperationRoot,OpClass> + (mOrigDataPtr,mDataAcc,*this,in))).template vec(); } template template auto OperationRoot::assign(const OpClass& in) const - -> decltype(this->template asx>(in)) { return this->template asx>(in); } @@ -592,7 +608,6 @@ namespace MultiArrayTools template template auto OperationRoot::assignExpr(const OpClass& in) const - -> decltype(this->template asxExpr>(in)) { return this->template asxExpr>(in); } @@ -600,7 +615,6 @@ namespace MultiArrayTools template template auto OperationRoot::assign(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx>(in,i)) { return this->template asx>(in,i); } @@ -608,7 +622,6 @@ namespace MultiArrayTools template template auto OperationRoot::plus(const OpClass& in) const - -> decltype(this->template asx>(in)) { return this->template asx>(in); } @@ -616,7 +629,6 @@ namespace MultiArrayTools template template auto OperationRoot::plus(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx>(in,i)) { return this->template asx>(in,i); } @@ -676,6 +688,7 @@ namespace MultiArrayTools template inline T& OperationRoot::get(ET pos) const { + assert(mDataAcc.get(pos.val()) == mDataPtr+pos.val()); return *mDataAcc.get(pos.val()); //return mDataPtr[pos.val()]; } @@ -684,6 +697,7 @@ namespace MultiArrayTools template inline V& OperationRoot::vget(ET pos) const { + assert(mDataAcc.get(pos.val()) == mDataPtr+pos.val()); return *(reinterpret_cast(mDataAcc.get(pos.val()))); //return *(reinterpret_cast(mDataPtr+pos.val())); } @@ -693,7 +707,8 @@ namespace MultiArrayTools inline OperationRoot& OperationRoot::set(ET pos) { mDataAcc.set(pos.val()); - //mDataPtr = mOrigDataPtr + pos.val(); + mDataPtr = mOrigDataPtr + pos.val(); + assert(mDataAcc.get(0) == mDataPtr); return *this; } @@ -713,6 +728,7 @@ namespace MultiArrayTools template T* OperationRoot::data() const { + assert(mDataAcc.get(0) == mDataPtr); return mDataAcc.get(0); //return mDataPtr; } @@ -737,6 +753,7 @@ namespace MultiArrayTools const std::shared_ptr&... indices) : mDataPtr(ma.data()), mOrigDataPtr(ma.data()), + mDataAcc( ma.data(), ma.data() ), mIndex( ma.begin() ) { mIndex(indices...); @@ -748,6 +765,7 @@ namespace MultiArrayTools ParallelOperationRoot(T* data, const IndexType& ind) : mDataPtr(data), mOrigDataPtr(data), + mDataAcc( data, data ), mIndex( ind ) { mDataPtr = mOrigDataPtr + mIndex.pos(); @@ -756,41 +774,33 @@ namespace MultiArrayTools template template auto ParallelOperationRoot::asx(const OpClass& in) const - -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in))).template vec()) - { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return mIndex.pifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in))).template vec(); + return mIndex.pifor(1,in.loop(AssignmentExpr,ParallelOperationRoot,OpClass,OpIndexAff::TARGET> + (mOrigDataPtr,mDataAcc,*this,in))).template vec(); } template template auto ParallelOperationRoot::asxExpr(const OpClass& in) const - -> decltype(in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in)); + return in.loop(AssignmentExpr,ParallelOperationRoot,OpClass> + (mOrigDataPtr,mDataAcc,*this,in)); } template template auto ParallelOperationRoot::asx(const OpClass& in, const std::shared_ptr& i) const - -> decltype(i->pifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))).template vec()) { static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return i->pifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))).template vec(); + return i->pifor(1,in.loop(AssignmentExpr,ParallelOperationRoot,OpClass> + (mOrigDataPtr,mDataAcc,*this,in))).template vec(); } template template auto ParallelOperationRoot::assign(const OpClass& in) const - -> decltype(this->template asx>(in)) { return this->template asx>(in); } @@ -798,7 +808,6 @@ namespace MultiArrayTools template template auto ParallelOperationRoot::assignExpr(const OpClass& in) const - -> decltype(this->template asxExpr>(in)) { return this->template asxExpr>(in); } @@ -806,7 +815,6 @@ namespace MultiArrayTools template template auto ParallelOperationRoot::assign(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx>(in,i)) { return this->template asx>(in,i); } @@ -814,7 +822,6 @@ namespace MultiArrayTools template template auto ParallelOperationRoot::plus(const OpClass& in) const - -> decltype(this->template asx>(in)) { return this->template asx>(in); } @@ -822,7 +829,6 @@ namespace MultiArrayTools template template auto ParallelOperationRoot::plus(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx>(in,i)) { return this->template asx>(in,i); } diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index a206c14..70115b5 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -133,9 +133,12 @@ namespace MultiArrayTools // empty, implement corresponding constructors...!!! } + /* template using VFunc = decltype(mkVFunc(std::declval())); - + */ + template + using VFunc = F; template class OpAccess @@ -164,21 +167,26 @@ namespace MultiArrayTools static constexpr bool ISSTATIC = true; typedef T value_type; typedef T in_type; + typedef F Func; static constexpr size_t VSIZE = sizeof(value_type) / sizeof(in_type); template - 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)); } }; + template + using IVAccess = IAccess; + /* template struct IVAccess { static constexpr bool ISSTATIC = true; typedef typename VType::type value_type; typedef T in_type; + typedef VFunc Func; static constexpr size_t VSIZE = sizeof(value_type) / sizeof(in_type); template @@ -188,6 +196,7 @@ namespace MultiArrayTools VFunc::selfApply(*reinterpret_cast(t+pos),op.template vget(e)); } }; + */ template using xxxplus = plus; @@ -216,9 +225,13 @@ namespace MultiArrayTools inline auto get(size_t pos); inline auto get(size_t pos) const; + inline auto oget(size_t pos) const; template inline void exec(size_t pos, const Op& op, ExtType e) const; + + protected: + AccessTemplate() = default; }; template @@ -228,15 +241,22 @@ namespace MultiArrayTools typedef T value_type; typedef T in_type; private: - T* mPtr; - T* mOrigPtr; + PointerAccess() = default; + + T* mPtr = nullptr; + T* mOrigPtr = nullptr; public: 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) const { return mPtr+pos; } PointerAccess& set(size_t pos) { mPtr = mOrigPtr + pos; return *this; } + T* oget(size_t pos) const { return mOrigPtr+pos; } template 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); } }; - template + template class AssignmentExpr : public ExpressionBase { private: @@ -272,6 +292,7 @@ namespace MultiArrayTools Target mTar; OpClass mSec; + AccessTemplate mDataAcc; T* mDataPtr; public: @@ -281,7 +302,8 @@ namespace MultiArrayTools static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE; 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& dataAcc, const Target& tar, const OpClass& sec); AssignmentExpr(const AssignmentExpr& in) = default; AssignmentExpr(AssignmentExpr&& in) = default; AssignmentExpr& operator=(const AssignmentExpr& in) = default; @@ -289,7 +311,7 @@ namespace MultiArrayTools virtual std::shared_ptr deepCopy() const override final { - return std::make_shared>(*this); + return std::make_shared,Target,OpClass,OIA>>(*this); } inline void operator()(size_t start = 0); @@ -303,10 +325,10 @@ namespace MultiArrayTools }; template - using AssignmentExpr2 = AssignmentExpr,Target,OpClass,OIA>; + using AssignmentExpr2 = AssignmentExpr,PointerAccess,Target,OpClass,OIA>; template - using AddExpr = AssignmentExpr,Target,OpClass,OIA>; + using AddExpr = AssignmentExpr,PointerAccess,Target,OpClass,OIA>; template struct OperationTuple @@ -554,8 +576,8 @@ namespace MultiArrayTools private: - //T* mDataPtr; - //T* mOrigDataPtr; + T* mDataPtr; + T* mOrigDataPtr; PointerAccess mDataAcc; IndexType mIndex; @@ -569,38 +591,28 @@ namespace MultiArrayTools OperationRoot(T* data, const IndexType& ind); template - auto asx(const OpClass& in) const - -> decltype(mIndex.ifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in))).template vec()); + auto asx(const OpClass& in) const; template - auto asxExpr(const OpClass& in) const - -> decltype(in.loop(AssignmentExpr,OpClass>(mOrigDataPtr,*this,in))); + auto asxExpr(const OpClass& in) const; template - auto asx(const OpClass& in, const std::shared_ptr& i) const - -> decltype(i->ifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))).template vec()); + auto asx(const OpClass& in, const std::shared_ptr& i) const; template - auto assign(const OpClass& in) const - -> decltype(this->template asx>(in)); + auto assign(const OpClass& in) const; template - auto assignExpr(const OpClass& in) const - -> decltype(this->template asxExpr>(in)); + auto assignExpr(const OpClass& in) const; template - auto assign(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx>(in,i)); + auto assign(const OpClass& in, const std::shared_ptr& i) const; template - auto plus(const OpClass& in) const - -> decltype(this->template asx>(in)); + auto plus(const OpClass& in) const; template - auto plus(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx>(in,i)); + auto plus(const OpClass& in, const std::shared_ptr& i) const; template OperationRoot& operator=(const OpClass& in); @@ -652,6 +664,7 @@ namespace MultiArrayTools T* mDataPtr; T* mOrigDataPtr; + PointerAccess mDataAcc; IndexType mIndex; public: @@ -661,38 +674,28 @@ namespace MultiArrayTools ParallelOperationRoot(T* data, const IndexType& ind); template - auto asx(const OpClass& in) const - -> decltype(mIndex.pifor(1,in.loop(AssignmentExpr,OpClass,OpIndexAff::TARGET> - (mOrigDataPtr,*this,in))).template vec()); + auto asx(const OpClass& in) const; template - auto asxExpr(const OpClass& in) const - -> decltype(in.loop(AssignmentExpr,OpClass>(mOrigDataPtr,*this,in))); + auto asxExpr(const OpClass& in) const; template - auto asx(const OpClass& in, const std::shared_ptr& i) const - -> decltype(i->pifor(1,in.loop(AssignmentExpr,OpClass> - (mOrigDataPtr,*this,in))).template vec()); + auto asx(const OpClass& in, const std::shared_ptr& i) const; template - auto assign(const OpClass& in) const - -> decltype(this->template asx>(in)); + auto assign(const OpClass& in) const; template - auto assignExpr(const OpClass& in) const - -> decltype(this->template asxExpr>(in)); + auto assignExpr(const OpClass& in) const; template - auto assign(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx>(in,i)); + auto assign(const OpClass& in, const std::shared_ptr& i) const; template - auto plus(const OpClass& in) const - -> decltype(this->template asx>(in)); + auto plus(const OpClass& in) const; template - auto plus(const OpClass& in, const std::shared_ptr& i) const - -> decltype(this->template asx>(in,i)); + auto plus(const OpClass& in, const std::shared_ptr& i) const; template ParallelOperationRoot& operator=(const OpClass& in);