diff --git a/src/include/helper_tools.h b/src/include/helper_tools.h index 1932888..7a40a42 100644 --- a/src/include/helper_tools.h +++ b/src/include/helper_tools.h @@ -6,6 +6,7 @@ #include "slice.h" #include #include "pack_num.h" +#include namespace MultiArrayTools { @@ -48,6 +49,9 @@ namespace MultiArrayTools template auto prtr(const MArray& ma) -> decltype(ma.template getRangePtr()); + + template + inline void For(const std::shared_ptr& ind, const std::function& ll); } /* ========================= * @@ -139,6 +143,14 @@ namespace MultiArrayTools return ma.template getRangePtr(); } + template + inline void For(const std::shared_ptr& ind, const std::function& ll) + { + for((*ind) = 0; ind->pos() != ind->max(); ++(*ind)){ + ll(); + } + } + } #endif diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 337554e..d6f2de3 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -50,9 +50,13 @@ namespace MultiArrayTools -> Operation,OperationClass,Second>; template - auto c(std::shared_ptr& ind) const + auto c(const std::shared_ptr& ind) const -> Contraction; + template + auto sl(const std::shared_ptr&... inds) const + -> ConstSlice; + private: friend OperationClass; friend OperationTemplate; @@ -153,12 +157,14 @@ namespace MultiArrayTools template Expr loop(Expr exp) const; - + + const T* data() const; + private: //MultiArrayBase const& mArrayRef; const T* mDataPtr; - IndexType mIndex; + mutable IndexType mIndex; //std::shared_ptr > mMaPtr; }; @@ -257,11 +263,15 @@ namespace MultiArrayTools T* data() const; + template + auto sl(const std::shared_ptr&... inds) + -> Slice; + private: //MutableMultiArrayBase& mArrayRef; T* mDataPtr; - IndexType mIndex; + mutable IndexType mIndex; }; template @@ -454,12 +464,22 @@ namespace MultiArrayTools template template - auto OperationBase::c(std::shared_ptr& ind) const + auto OperationBase::c(const std::shared_ptr& ind) const -> Contraction { return Contraction(THIS(), ind); } + template + template + auto OperationBase::sl(const std::shared_ptr&... inds) const + -> ConstSlice + { + ConstSlice out(inds->range()...); + out.define(inds...) = *this; + return out; + } + /***************************************** * OperationMaster::AssignmentExpr * *****************************************/ @@ -567,6 +587,12 @@ namespace MultiArrayTools return mDataPtr[pos.val()]; } + template + const T* ConstOperationRoot::data() const + { + return mDataPtr + mIndex().pos(); + } + template MExt ConstOperationRoot::rootSteps(std::intptr_t iPtrNum) const { @@ -697,9 +723,23 @@ namespace MultiArrayTools template T* OperationRoot::data() const { - return mDataPtr + mIndex.pos(); + return mDataPtr + mIndex().pos(); } + template + template + auto OperationRoot::sl(const std::shared_ptr&... inds) + -> Slice + { + Slice out(inds->range()...); + out.define(inds...) = *this; + return out; + } + + + /************************ + * OperationValue * + ************************/ template OperationValue::OperationValue(const T& val) : mVal(val) {}