diff --git a/src/include/high_level_operation.cc.h b/src/include/high_level_operation.cc.h index 669c13e..a51bf4f 100644 --- a/src/include/high_level_operation.cc.h +++ b/src/include/high_level_operation.cc.h @@ -302,13 +302,130 @@ namespace MultiArrayTools #undef regFunc1 #undef SP - /* - template - HighLevelOpHolder exp(const HighLevelOpHolder& in) + + template + template + inline void SetLInds::mkLIT(const ITuple& itp, const std::shared_ptr& di) { - return HighLevelOpHolder - ( std::make_shared,1>> - ( std::array>,1>( {in.op()} ) ) ); + constexpr size_t NN = std::tuple_size::value-N-1; + const size_t nn = di->dim()-N-1; + typedef typename std::remove_reference(itp))>::type T; + std::get(itp) = + std::dynamic_pointer_cast(di->get(nn))->getIndex(); + SetLInds::mkLIT(itp, di); + } + + template + template + template + inline void SetLInds::xx:: + assign(Tar& tar, const Args&... args, const ITp& itp, const std::shared_ptr&... is) + { + SetLInds::template xx::assign(tar, args..., itp, std::get(itp), is...); + } + + template + template + template + inline void SetLInds::xx:: + plus(Tar& tar, const Args&... args, const ITp& itp, const std::shared_ptr&... is) + { + SetLInds::template xx::plus(tar, args..., itp, std::get(itp), is...); + } + + //template <> + template + inline void SetLInds<0>::mkLIT(const ITuple& itp, const std::shared_ptr& di) + { + constexpr size_t NN = std::tuple_size::value-1; + const size_t nn = di->dim()-1; + typedef typename std::remove_reference(itp))>::type T; + std::get(itp) = + std::dynamic_pointer_cast(di->get(nn))->getIndex(); + } + + //template <> + template + template + inline void SetLInds<0>::xx:: + assign(Tar& tar, const Args&... args, const ITp& itp, const std::shared_ptr&... is) + { + tar.assign(args..., std::get<0>(itp), is...); + } + + //template <> + template + template + inline void SetLInds<0>::xx:: + plus(Tar& tar, const Args&... args, const ITp& itp, const std::shared_ptr&... is) + { + tar.plus(args..., std::get<0>(itp), is...); + } + + template + size_t INDS::CallHLOpBase::depth() const + { + return mDepth; + } + + std::shared_ptr mkSubSpaceX(const std::shared_ptr& di, + size_t max) + { + auto& o = di->range()->orig(); + vector> ox(o.begin(),o.begin()+max); + DynamicRangeFactory drf(ox); + auto dr = createExplicit(drf); + auto odi = getIndex(dr); + vector> iv; + iv.reserve(max); + for(size_t i = 0; i != max; ++i){ + iv.push_back(di->getP(i)); + } + (*odi)(iv); + return odi; + } + + template + template + void INDS::CallHLOp:: + assign(HighLevelOpHolder& target, const HighLevelOpHolder& source, + const std::shared_ptr&... is, + const std::shared_ptr& di) const + { + auto ip = di->get(di->dim() - this->depth()); + auto iregn = ip->regN(); + if(iregn.type >= 0 and iregn.depth > sizeof...(LIndices)){ + sNext[iregn.type]->assign(target, source, is..., di); + } + else { + ITuple itp; + SetLInds::mkLIT(itp,di); + auto mi = mkIndex(is...,mkSubSpaceX(di, di->dim() - this->depth())); + SetLInds:: + template xx,ITuple,HighLevelOpHolder,decltype(mi)>:: + assign(target, source, mi, itp); + } + } + + template + template + void INDS::CallHLOp:: + plus(HighLevelOpHolder& target, const HighLevelOpHolder& source, + const std::shared_ptr&... is, + const std::shared_ptr& di) const + { + auto ip = di->get(di->dim() - this->depth()); + auto iregn = ip->regN(); + if(iregn.type >= 0 and iregn.depth > sizeof...(LIndices)){ + sNext[iregn.type]->plus(target, source, is..., di); + } + else { + ITuple itp; + SetLInds::mkLIT(itp,di); + auto mi = mkIndex(is...,mkSubSpaceX(di, di->dim() - this->depth())); + SetLInds:: + template xx,ITuple,HighLevelOpHolder,decltype(mi)>:: + plus(target, source, mi, itp); + } } - */ } diff --git a/src/include/high_level_operation.h b/src/include/high_level_operation.h index 7a54451..9adbb46 100644 --- a/src/include/high_level_operation.h +++ b/src/include/high_level_operation.h @@ -174,11 +174,81 @@ namespace MultiArrayTools #include "extensions/math.h" #undef regFunc1 #undef SP - /* - template - HighLevelOpHolder exp(const HighLevelOpHolder& in); - */ + + template + struct SetLInds + { + template + static inline void mkLIT(const ITuple& itp, const std::shared_ptr& di); + template + struct xx + { + template + static inline void assign(Tar& tar, const Args&... args, + const ITp& itp, const std::shared_ptr&... is); + + template + static inline void plus(Tar& tar, const Args&... args, + const ITp& itp, const std::shared_ptr&... is); + }; + }; + + template <> + struct SetLInds<0> + { + template + static inline void mkLIT(const ITuple& itp, const std::shared_ptr& di); + + template + struct xx + { + template + static inline void assign(Tar& tar, const Args&... args, + const ITp& itp, const std::shared_ptr&... is); + + template + static inline void plus(Tar& tar, const Args&... args, + const ITp& itp, const std::shared_ptr&... is); + }; + }; + + template + struct INDS + { + class CallHLOpBase + { + private: + size_t mDepth; + public: + size_t depth() const; + + void assign(const HighLevelOpHolder& target, const HighLevelOpHolder& source, + const std::shared_ptr&... is, + const std::shared_ptr& di) const = 0; + + void plus(const HighLevelOpHolder& target, const HighLevelOpHolder& source, + const std::shared_ptr&... is, + const std::shared_ptr& di) const = 0; + }; + + template + class CallHLOp + { + private: + typedef std::tuple...> ITuple; + static vector> sNext; + public: + void assign(HighLevelOpHolder& target, const HighLevelOpHolder& source, + const std::shared_ptr&... is, + const std::shared_ptr& di) const override final; + + void plus(HighLevelOpHolder& target, const HighLevelOpHolder& source, + const std::shared_ptr&... is, + const std::shared_ptr& di) const override final; + }; + }; + } #endif diff --git a/src/include/hl_reg_ind.h b/src/include/hl_reg_ind.h index d8592c9..144c5e0 100644 --- a/src/include/hl_reg_ind.h +++ b/src/include/hl_reg_ind.h @@ -2,6 +2,8 @@ #ifndef __hl_reg_ind_h__ #define __hl_reg_ind_h__ +#include "ranges/rheader.h" + namespace MultiArrayTools { @@ -30,101 +32,9 @@ namespace MultiArrayTools { type = RegIndNum::VALUE; depth = RegIndNum::DEPTH; + return *this; } }; - - template - struct SetLInds - { - template - struct xx - { - template - static inline void assign(Tar& tar, const Args&... args, const ITp& itp, const std::shared_ptr&... is) - { - SetLInds::template xx::assign(tar, args..., itp, std::get(itp), is...); - } - - template - static inline void plus(Tar& tar, const Args&... args, const ITp& itp, const std::shared_ptr&... is) - { - SetLInds::template xx::plus(tar, args..., itp, std::get(itp), is...); - } - }; - }; - - template <> - struct SetLInds<0> - { - template - struct xx - { - template - static inline void assign(Tar& tar, const Args&... args, const ITp& itp, const std::shared_ptr&... is) - { - tar.assign(args..., std::get<0>(itp), is...); - } - - template - static inline void plus(Tar& tar, const Args&... args, const ITp& itp, const std::shared_ptr&... is) - { - tar.plus(args..., std::get<0>(itp), is...); - } - }; - }; - - template - struct INDS - { - class CallHLOpBase - { - private: - size_t mDepth; - public: - void assign(const HighLevelOpHolder& target, const HighLevelOpHolder& source, - const std::shared_ptr&... is, - const std::shared_ptr& di) const = 0; - - void plus(const HighLevelOpHolder& target, const HighLevelOpHolder& source, - const std::shared_ptr&... is, - const std::shared_ptr& di) const = 0; - }; - - template - class CallHLOp - { - private: - typedef std::tuple...> ITuple; - static vector> sNext; - public: - void assign(HighLevelOpHolder& target, const HighLevelOpHolder& source, - const std::shared_ptr&... is, - const std::shared_ptr& di) const override final - { - auto ip = di->get(di->dim()-mDepth); - auto iregn = ip->regN(); - if(iregn.type >= 0 and iregn.depth > sizeof...(LIndices)){ - sCall[iregn.type]->assign(target, source, is..., di); - } - else { - auto mi = mkIndex(is...,di->subSpaceI(0, di->dim()-mDepth)); - SetLInds:: - template xx:: - assign(target, source, mi, - SetLInds::template mkLIT(di)); - } - } - - void plus(HighLevelOpHolder& target, const HighLevelOpHolder& source, - const std::shared_ptr&... is, - const std::shared_ptr& di) const override final - { - auto mi = mkIndex(is...,di); - SetLInds::template xx::plus - (target, source, mi, mLInds); - } - }; - }; } #endif diff --git a/src/include/ranges/dynamic_range.h b/src/include/ranges/dynamic_range.h index 1b84bda..d7307c6 100644 --- a/src/include/ranges/dynamic_range.h +++ b/src/include/ranges/dynamic_range.h @@ -92,6 +92,7 @@ namespace MultiArrayTools bool first() const; const IndexW& get(size_t n) const; + const std::shared_ptr& getP(size_t n) const; std::shared_ptr range(); diff --git a/src/include/ranges/index_wrapper.cc.h b/src/include/ranges/index_wrapper.cc.h index fae672e..b482cfb 100644 --- a/src/include/ranges/index_wrapper.cc.h +++ b/src/include/ranges/index_wrapper.cc.h @@ -144,6 +144,13 @@ namespace MultiArrayTools return std::make_shared( std::make_shared( *mI ) ); } + template + RegIndInfo IndexWrapper::regN() const + { + RegIndInfo out; + return out.set(mI); + } + template inline std::shared_ptr mkIndexWrapper(const Index& i) { diff --git a/src/include/ranges/index_wrapper.h b/src/include/ranges/index_wrapper.h index 1300cca..17b77c4 100644 --- a/src/include/ranges/index_wrapper.h +++ b/src/include/ranges/index_wrapper.h @@ -4,6 +4,7 @@ #include "ranges/rbase_def.h" #include "xfor/xfor.h" +#include "hl_reg_ind.h" namespace MultiArrayTools { @@ -48,7 +49,8 @@ namespace MultiArrayTools virtual std::intptr_t ptrNum() const = 0; virtual std::shared_ptr duplicate() const = 0; - + + virtual RegIndInfo regN() const = 0; //virtual DynamicMetaT meta() const = 0; //virtual const DynamicMetaT* metaPtr() const = 0; //virtual AbstractIW& at(const U& metaPos) = 0; @@ -134,6 +136,7 @@ namespace MultiArrayTools virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const override final; virtual std::shared_ptr duplicate() const override final; + virtual RegIndInfo regN() const override final; std::shared_ptr getIndex() const { return mI; } diff --git a/src/include/ranges/reg_ind_num.h b/src/include/ranges/reg_ind_num.h new file mode 100644 index 0000000..c7b9640 --- /dev/null +++ b/src/include/ranges/reg_ind_num.h @@ -0,0 +1,7 @@ + +#ifndef __reg_ind_num_h__ +#define __reg_ind_num_h__ + + + +#define diff --git a/src/lib/ranges/dynamic_range.cc b/src/lib/ranges/dynamic_range.cc index ac47393..d0d9407 100644 --- a/src/lib/ranges/dynamic_range.cc +++ b/src/lib/ranges/dynamic_range.cc @@ -268,6 +268,11 @@ namespace MultiArrayTools return *mIVec[n].first; } + const std::shared_ptr& DynamicIndex::getP(size_t n) const + { + assert(mIvecInit); + return mIVec[n].first; + } std::shared_ptr DynamicIndex::range() {