diff --git a/src/include/operation/cxz_operation.cc.h b/src/include/operation/cxz_operation.cc.h index 97b5909..731d97c 100644 --- a/src/include/operation/cxz_operation.cc.h +++ b/src/include/operation/cxz_operation.cc.h @@ -46,390 +46,124 @@ namespace CNORXZ } - /**************************** - * ConstOperationRoot * - ****************************/ + /*************** + * COpRoot * + ***************/ - template - ConstOperationRoot:: - ConstOperationRoot(const ArrayBase& ma, - const std::shared_ptr&... indices) : - mDataPtr(ma.data()), - mOrigDataPtr(ma.data()), - mIndex( ma.begin() ) + template + constexpr COpRoot::COpRoot(const DArrayBase& a, const Sptr& ind) : + mData(a.data()), + mIndex(ind) + {} + + template + constexpr COpRoot::COpRoot(const T* data, const Sptr& ind) : + mData(data), + mIndex(ind) + {} + + template + template + constexpr decltype(auto) COpRoot::get(const PosT& pos) const { - mIndex(indices...); - mDataPtr = mOrigDataPtr + mIndex.pos(); + if constexpr(is_epos_type::value){ + return vreg(mData,pos); // distinguish between consecutive/non-consecutive + } + else { + return mData[pos.val()]; + } } - template - ConstOperationRoot:: - ConstOperationRoot(std::shared_ptr > maptr, - const std::shared_ptr&... indices) : - mDataPtr(maptr->data()), - mOrigDataPtr(maptr->data()), - mIndex(maptr->begin()), - mMaPtr(maptr) + template + template + constexpr decltype(auto) COpRoot::rootSteps(const IndexId& id) const { - mIndex(indices...); - mDataPtr = mOrigDataPtr + mIndex.pos(); + return mIndex->stepSize(id); } - template - ConstOperationRoot:: - ConstOperationRoot(const T* data, const IndexType& ind) : - mDataPtr(data), - mOrigDataPtr(data), - mIndex( ind ) - { - mDataPtr = mOrigDataPtr + mIndex.pos(); - } - - template - template - inline const T& ConstOperationRoot::get(ET pos) const - { - return mDataPtr[pos.val()]; - } - - template - template - inline const V& ConstOperationRoot::vget(ET pos) const - { - return *(reinterpret_cast(mDataPtr+pos.val())); - } - - template - template - inline ConstOperationRoot& ConstOperationRoot::set(ET pos) - { - mDataPtr = mOrigDataPtr + pos.val(); - return *this; - } - - template - const T* ConstOperationRoot::data() const - { - return mDataPtr; - } - - template - MExt ConstOperationRoot::rootSteps(std::intptr_t iPtrNum) const - { - return MExt(RangeHelper::getStepSize( mIndex, iPtrNum )); - } - - - template + template template - Expr ConstOperationRoot::loop(Expr exp) const + constexpr decltype(auto) COpRoot::loop(Xpr&& xpr) const { - return exp; + return xpr; } - /******************** - * StaticCast * - ********************/ - - template - StaticCast::StaticCast(const Op& op) : mOp(op) {} - - template - template - inline T StaticCast::get(ET pos) const + template + const T* COpRoot::data() const { - return static_cast( mOp.get(pos) ); - } - - template - template - inline V StaticCast::vget(ET pos) const - { - assert(0); // !!! - return V(); - } - - template - template - inline StaticCast& StaticCast::set(ET pos) - { - mOp.set(pos); - return *this; + return mData; } - template - auto StaticCast::rootSteps(std::intptr_t iPtrNum) const - -> decltype(mOp.rootSteps(iPtrNum)) - { - return mOp.rootSteps(iPtrNum); - } - template - template - Expr StaticCast::loop(Expr exp) const - { - return mOp.loop(exp); - } + /**************** + * OpRoot * + ****************/ + template + constexpr OpRoot::OpRoot(MDArrayBase& a, const Sptr& ind); + mData(a.data()), + mIndex(ind) + {} + + template + constexpr OpRoot::OpRoot(T* data, const Sptr& ind) : + mData(data), + mIndex(ind) + {} - /**************************** - * MetaOperationRoot * - ****************************/ - - template - MetaOperationRoot:: - MetaOperationRoot(const std::shared_ptr& ind) : - mWorkIndex(*ind), mIndex( ind ) {} - - - template - template - inline typename MetaOperationRoot::value_type - MetaOperationRoot::get(ET pos) const + template + template + constexpr OpRoot& OpRoot::operator=(const Op& o) { - return (mWorkIndex = pos.val()).meta(); - } - - template - template - inline V - MetaOperationRoot::vget(ET pos) const - { - assert(0); // !!! - return V(); - } - - template - template - inline MetaOperationRoot& MetaOperationRoot::set(ET pos) - { - return *this; - } - - template - MExt MetaOperationRoot::rootSteps(std::intptr_t iPtrNum) const - { - return MExt(RangeHelper::getStepSize( *mIndex, iPtrNum )); - } - - - template - template - Expr MetaOperationRoot::loop(Expr exp) const - { - return exp; - } - - /*********************** - * OperationRoot * - ***********************/ - - template - OperationRoot:: - OperationRoot(MutableArrayBase& ma, - const std::shared_ptr&... indices) : - mDataPtr(ma.data()), - mOrigDataPtr(ma.data()), - mDataAcc( ma.data(), ma.data() ), - mIndex( ma.begin() ) - { - mIndex(indices...); - mDataAcc.set( mIndex.pos() ); - mDataPtr = mOrigDataPtr + mIndex.pos(); - } - - template - OperationRoot:: - OperationRoot(MutableArrayBase& ma, - const std::tuple...>& indices) : - mDataPtr(ma.data()), - mOrigDataPtr(ma.data()), - mDataAcc( ma.data(), ma.data() ), - mIndex( ma.begin() ) - { - mIndex(indices); - mDataAcc.set( mIndex.pos() ); - mDataPtr = mOrigDataPtr + mIndex.pos(); - } - - template - OperationRoot:: - OperationRoot(T* data, const IndexType& ind) : - mDataPtr(data), - mOrigDataPtr(data), - mDataAcc( data, data ), - mIndex( ind ) - { - mDataAcc.set( mIndex.pos() ); - mDataPtr = mOrigDataPtr + mIndex.pos(); - } - - template - template - auto OperationRoot::asx(const OpClass& in) const - { - static_assert(Access::VSIZE > 0, "Access::VSIZE failed"); - return mIndex.ifor(1,this->template asxExpr(in)).template vec(); - } - - template - template - auto OperationRoot::asxExpr(const OpClass& in) const - { - static_assert( OpClass::SIZE == decltype(in.rootSteps())::SIZE, "Ext Size mismatch" ); - return in.loop(AssignmentExpr,OpClass> - (Access(mDataAcc),*this,in)); - } - - template - template - auto OperationRoot::asx(const OpClass& in, const std::shared_ptr& i) const - { - static_assert(Access::VSIZE > 0, "Access::VSIZE failed"); - return i->ifor(1,this->template asxExpr(in)).template vec(); - } - - template - template - auto OperationRoot::assign(const OpClass& in) const - { - return this->template asx,PointerAccess>(in); - } - - template - template - auto OperationRoot::assignExpr(const OpClass& in) const - { - return this->template asxExpr,PointerAccess>(in); - } - - template - template - auto OperationRoot::assign(const OpClass& in, const std::shared_ptr& i) const - { - return this->template asx,PointerAccess>(in,i); - } - - template - using xplus = plus; - - template - template - auto OperationRoot::plus(const OpClass& in) const - { - return this->template asx,PointerAccess>(in); - } - - template - template - auto OperationRoot::plus(const OpClass& in, const std::shared_ptr& i) const - { - return this->template asx,PointerAccess>(in,i); - } - - template - inline void vexec(TarOp& th, const OpClass& in) - { - // VECTORIZATION!!! - // PARALLEL!!! - if constexpr(VABLE){ - CHECK; - typedef typename TarOp::value_type T; - auto x = th.template asx,VPointerAccess>(in); - if(x.rootSteps(x.vI()) == 1){ - //if(0){ - CHECK; - x(); - } - else { - th.template asx>(in)(); - } - } - else { - typedef typename TarOp::value_type T; - //IAccess> tmp; - th.template asx>(in)(); - } - } - - template - template - OperationRoot& OperationRoot::operator=(const OpClass& in) - { - vexec>(*this,in); + a(mInd, [](auto& a, const auto& b) { a = b; }, o) return *this; } - template - template - OperationRoot& OperationRoot::operator+=(const OpClass& in) + template + template + constexpr OpRoot& OpRoot::operator+=(const Op& o) { - vexec>(*this,in); + a(mInd, [](auto& a, const auto& b) { a += b; }, o) return *this; } - template - OperationRoot& OperationRoot::operator=(const OperationRoot& in) + template + constexpr OpRoot& OpRoot::operator=(const OpRoot& in) { - return operator= >(in); - } - /* - template - ParallelOperationRoot OperationRoot::par() - { - return ParallelOperationRoot(mOrigDataPtr, mIndex); - } - */ - template - template - inline T& OperationRoot::get(ET pos) const - { - return *mDataAcc.get(pos.val()); - } - - template - template - inline V& OperationRoot::vget(ET pos) const - { - return *(reinterpret_cast(mDataAcc.get(pos.val()))); - } - - template - template - inline OperationRoot& OperationRoot::set(ET pos) - { - mDataAcc.set(pos.val()); - mDataPtr = mOrigDataPtr + pos.val(); + a(mInd, [](auto& a, const auto& b) { a = b; }, o) return *this; } - template - MExt OperationRoot::rootSteps(std::intptr_t iPtrNum) const + template + template + constexpr decltype(auto) OpRoot::get(const PosT& pos) const { - return MExt(RangeHelper::getStepSize( mIndex, iPtrNum )); + if constexpr(is_epos_type::value){ + return vreg(mData,pos); // distinguish between consecutive/non-consecutive + } + else { + return mData[pos.val()]; + } } - template + template + template + constexpr decltype(auto) OpRoot::rootSteps(const IndexId& id) const + { + return mIndex->stepSize(id); + } + + template template - Expr OperationRoot::loop(Expr exp) const + constexpr decltype(auto) OpRoot::loop(Xpr&& xpr) const; { - return exp; + return xpr; } - template - T* OperationRoot::data() const + template + T* OpRoot::data() const { - return mDataAcc.get(0); - } - - template - template - auto OperationRoot::sl(const std::shared_ptr&... inds) - -> Slice - { - Slice out(inds->range()...); - out.define(inds...) = *this; - return out; + return mData; } diff --git a/src/include/operation/cxz_operation.h b/src/include/operation/cxz_operation.h index 3b2f882..f67d762 100644 --- a/src/include/operation/cxz_operation.h +++ b/src/include/operation/cxz_operation.h @@ -68,7 +68,7 @@ namespace CNORXZ { static constexpr bool value = std::is_base_of::value }; template - class COpRoot : public COpInterface> + class COpRoot : public COpInterface> { public: @@ -85,192 +85,81 @@ namespace CNORXZ constexpr decltype(auto) rootSteps(const IndexId& id) const; template - constexpr decltype(auto) loop(Xpr&& exp) const; + constexpr decltype(auto) loop(Xpr&& xpr) const; const T* data() const; private: - const T* mData; + const T* mData = nullptr; Sptr mIndex; }; - - template - class MetaOperationRoot : public OperationTemplate > + template + class OpCont : public OpInterface> { - public: - - typedef typename Range::IndexType IndexType; - typedef typename IndexType::MetaType value_type; - typedef OperationBase > OT; - - static constexpr size_t SIZE = 1; - static constexpr bool CONT = false; - static constexpr bool VABLE = false; - - MetaOperationRoot(const std::shared_ptr& ind); - - template - inline value_type get(ET pos) const; - - template - inline V vget(ET pos) const; - - template - inline MetaOperationRoot& set(ET pos); - - MExt rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype - - template - Expr loop(Expr exp) const; - - private: - - mutable IndexType mWorkIndex; - std::shared_ptr mIndex; + // operation container (intermediate operation results) + // TO BE IMPLEMENTED!!! }; - - template - class OperationRoot : public OperationTemplate > + + + template + class OpRoot : public OpInterface> { public: - typedef T value_type; - typedef OperationBase > OT; - typedef ContainerRange CRange; - typedef ConstContainerIndex IndexType; + typedef OpInterface> OI; - static constexpr size_t SIZE = 1; - static constexpr bool CONT = true; - static constexpr bool VABLE = true; - - private: - - T* mDataPtr; - T* mOrigDataPtr; - PointerAccess mDataAcc; - IndexType mIndex; - - public: - OperationRoot(MutableArrayBase& ma, - const std::shared_ptr&... indices); - - OperationRoot(MutableArrayBase& ma, - const std::tuple...>& indices); - - OperationRoot(T* data, const IndexType& ind); - - template - auto asx(const OpClass& in) const; - - template - auto asxExpr(const OpClass& in) const; + constexpr OpRoot(MDArrayBase& a, const Sptr& ind); + constexpr OpRoot(T* data, const Sptr& ind); - template - auto asx(const OpClass& in, const std::shared_ptr& i) const; - - template - auto assign(const OpClass& in) const; + template + constexpr OpRoot& operator=(const Op& in); - template - auto assignExpr(const OpClass& in) const; - - template - auto assign(const OpClass& in, const std::shared_ptr& i) const; - - template - auto plus(const OpClass& in) const; + template + constexpr OpRoot& operator+=(const Op& in); - template - auto plus(const OpClass& in, const std::shared_ptr& i) const; - - template - OperationRoot& operator=(const OpClass& in); - - template - OperationRoot& operator+=(const OpClass& in); - - OperationRoot& operator=(const OperationRoot& in); + constexpr OpRoot& operator=(const OpRoot& in); - auto par() { return *this; } - - template - inline T& get(ET pos) const; + template + constexpr decltype(auto) get(const PosT& pos) const; - template - inline V& vget(ET pos) const; - - template - inline OperationRoot& set(ET pos); + template + constexpr decltype(auto) rootSteps(const IndexId& id) const; - MExt rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype - - template - Expr loop(Expr exp) const; + template + constexpr decltype(auto) loop(Xpr&& exp) const; T* data() const; - - template - auto sl(const std::shared_ptr&... inds) - -> Slice; - - }; - - template - class Operation : public OperationTemplate > - { - public: - - typedef T value_type; - typedef OperationBase > OT; - typedef OpFunction F; - - static constexpr size_t SIZE = (... + Ops::SIZE); - static constexpr bool FISSTATIC = OpFunction::FISSTATIC; - static constexpr bool CONT = false; - static constexpr bool VABLE = - (... and (Ops::VABLE and std::is_same::value)); private: - OperationTuple mOps; - std::shared_ptr mF; // only if non-static - typedef decltype(mOps.rootSteps(0)) ExtType; + T* mData = nullptr; + Sptr mIndex; - public: - - Operation(const Ops&... ops); - Operation(std::shared_ptr ff, const Ops&... ops); - - template - inline auto get(ET pos) const; - - template - inline auto vget(ET pos) const; - - template - inline Operation& set(ET pos); - - auto rootSteps(std::intptr_t iPtrNum = 0) const - -> ExtType; // nullptr for simple usage with decltype - - template - auto loop(Expr exp) const; - - T* data() const { assert(0); return nullptr; } }; - template - auto mkOperation(const std::shared_ptr& f, const Ops&... ops) - -> Operation + + template + class Operation : public OpInterface> { - if constexpr(OpFunction::FISSTATIC){ - return Operation(ops...); - } - else { - return Operation(f,ops...); - } - } + public: + typedef OpInterface> OI; + + constexpr Operation(F&& f, Ops&&... ops); + + template + constexpr decltype(auto) get(const PosT& pos) const; + + template + constexpr decltype(auto) rootSteps(const IndexId& id) const + + template + constexpr decltype(auto) loop(Xpr&& xpr) const; + + private: + Tuple mOps; + F mF; + + }; template class Contraction : public OperationTemplate > @@ -316,7 +205,4 @@ namespace CNORXZ }; } - -#include "type_operations.h" - #endif