diff --git a/src/include/base/types.h b/src/include/base/types.h index 74601db..5f3e658 100644 --- a/src/include/base/types.h +++ b/src/include/base/types.h @@ -180,6 +180,9 @@ namespace CNORXZ template class GMIndex; + template + using MIndex = GMIndex; + // definition: ranges/xindex.h class XIndexBase; // dynamic index wrapper diff --git a/src/include/operation/op_types.h b/src/include/operation/op_types.h index 91bebed..e9bd6cc 100644 --- a/src/include/operation/op_types.h +++ b/src/include/operation/op_types.h @@ -79,8 +79,6 @@ namespace CNORXZ template class OpCont : public OpInterface> { - // operation container (intermediate operation results) - // TO BE IMPLEMENTED!!! public: typedef OpInterface> OI; diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 74aede4..2d98f95 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -170,6 +170,19 @@ namespace CNORXZ mkPos(); } + template + constexpr GMIndex::GMIndex(const BlockType& bs, const Indices&... is) : + IndexInterface,Tuple>(0), + mRange(std::dynamic_pointer_cast(mrange(is.range()...))), + mIPack(std::make_shared(is)...), + mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})), + mBlockSizes(bs), + mLMax(mkLMax(mIPack)), + mPMax(mkPMax(mIPack,mBlockSizes)) + { + mkPos(); + } + template constexpr GMIndex::GMIndex(const Sptr&... is) : IndexInterface,Tuple>(0), @@ -183,6 +196,20 @@ namespace CNORXZ mkPos(); } + template + constexpr GMIndex::GMIndex(const BlockType& bs, + const Sptr&... is) : + IndexInterface,Tuple>(0), + mRange(std::dynamic_pointer_cast(mrange(is->range()...))), + mIPack(is...), + mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})), + mBlockSizes(bs), + mLMax(mkLMax(mIPack)), + mPMax(mkPMax(mIPack,mBlockSizes)) + { + mkPos(); + } + template constexpr GMIndex::GMIndex(const RangePtr& range, SizeT lexpos) : IndexInterface,Tuple>(0), @@ -385,12 +412,17 @@ namespace CNORXZ } template - GMIndex& GMIndex::operator()(const Sptr& mi) + GMIndex& GMIndex::operator()(const Sptr>& mi) { - mIPack = mi.mIPack; - IB::mPos = iter<0,NI> - ( [&](auto i) { return std::get(mIPack)->pos()*std::get(blockSizes()).val(); }, - [](const auto&... xs) { return (xs + ...); }); + mIPack = mi.pack(); + mkPos(); + return *this; + } + + template + GMIndex& GMIndex::operator()() + { + mkPos(); return *this; } diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index 85d0787..20249fe 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -24,8 +24,6 @@ namespace CNORXZ typedef MRange RangeType; static constexpr SizeT NI = sizeof...(Indices); - // NO DEFAULT HERE !!! - // ( have to assign sub-indices (ptr!) correctly ) constexpr GMIndex() = default; constexpr GMIndex(GMIndex&& i) = default; constexpr GMIndex& operator=(GMIndex&& i) = default; @@ -34,7 +32,9 @@ namespace CNORXZ constexpr GMIndex& operator=(const GMIndex& i); constexpr GMIndex(const Indices&... is); + constexpr GMIndex(const BlockType& blockSizes, const Indices&... is); constexpr GMIndex(const Sptr&... is); + constexpr GMIndex(const BlockType& blockSizes, const Sptr&... is); constexpr GMIndex(const RangePtr& range, SizeT lexpos = 0); constexpr GMIndex(const RangePtr& range, const BlockType& blockSizes, SizeT lexpos = 0); @@ -67,7 +67,8 @@ namespace CNORXZ constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; // replace sub-index instances; only use if you know what you are doing! - GMIndex& operator()(const Sptr& mi); + GMIndex& operator()(const Sptr>& mi); + GMIndex& operator()(); const IndexPack& pack() const; const auto& blockSizes() const; @@ -107,8 +108,8 @@ namespace CNORXZ PMaxT mPMax; }; - template - using MIndex = GMIndex; + //template + //using MIndex = GMIndex; template class MRangeFactory : public RangeFactoryBase diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 4a235f2..f7a40fa 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -24,6 +24,8 @@ namespace CNORXZ YIndex(const YIndex& i); YIndex& operator=(const YIndex& i); + YIndex(const Vector& is); + YIndex(const Vector& bs, const Vector& is); YIndex(const RangePtr& range, SizeT lexpos); YIndex& operator=(SizeT lexpos); @@ -51,9 +53,18 @@ namespace CNORXZ DXpr ifor(const DXpr& xpr, const std::function& f) const; + YIndex& operator()(const Sptr& i); + YIndex& operator()(); + + const Vector& pack() const; + const Vector& blockSizes() const; + const Vector& lexBlockSizes() const; + private: inline Vector mkBlockSizes() const; inline Vector mkLexBlockSizes() const; + inline Vector mkRangeVec(const Vector& is) const; + inline void mkPos(); inline Vector mkIndices() const; inline void up(SizeT i); inline void down(SizeT i); @@ -114,6 +125,8 @@ namespace CNORXZ Vector mRVec; }; + RangePtr yrange(const Vector& rs); + template <> struct RangeCast { diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index d23b7ef..a35bd6b 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -41,6 +41,23 @@ namespace CNORXZ } return o; } + + inline Vector YIndex::mkRangeVec(const Vector& is) const + { + Vector o(is.size()); + std::transform(is.begin(), is.end(), o.begin(), [](const auto& e) { return e->range(); }); + return o; + } + + inline void YIndex::mkPos() + { + mLex = 0; + IB::mPos = 0; + for(SizeT i = 0; i != dim(); ++i){ + mLex += mIs[i]->lex() * mLexBlockSizes[i]; + IB::mPos += mIs[i]->pos() * mBlockSizes[i]; + } + } inline void YIndex::up(SizeT i) { @@ -129,6 +146,30 @@ namespace CNORXZ return *this = i.lex(); } + YIndex::YIndex(const Vector& is) : + IndexInterface(0), + mRange(std::dynamic_pointer_cast(yrange(mkRangeVec(is)))), + mIs(is), + mBlockSizes(mkBlockSizes()), + mLexBlockSizes(mkLexBlockSizes()), + mPMax(mkPMax()), + mLMax(mkLMax()) + { + mkPos(); + } + + YIndex::YIndex(const Vector& bs, const Vector& is) : + IndexInterface(0), + mRange(std::dynamic_pointer_cast(yrange(mkRangeVec(is)))), + mIs(is), + mBlockSizes(bs), + mLexBlockSizes(mkLexBlockSizes()), + mPMax(mkPMax()), + mLMax(mkLMax()) + { + mkPos(); + } + YIndex::YIndex(const RangePtr& range, SizeT lexpos) : IndexInterface(0), mRange(rangeCast(range)), @@ -288,6 +329,34 @@ namespace CNORXZ { return mkIFor(0, xpr, f); } + + YIndex& YIndex::operator()(const Sptr& i) + { + mIs = i->pack(); + mkPos(); + return *this; + } + + YIndex& YIndex::operator()() + { + mkPos(); + return *this; + } + + const Vector& YIndex::pack() const + { + return mIs; + } + + const Vector& YIndex::blockSizes() const + { + return mBlockSizes; + } + + const Vector& YIndex::lexBlockSizes() const + { + return mLexBlockSizes; + } /********************** * YRangeFactory * @@ -375,6 +444,15 @@ namespace CNORXZ YRange::YRange(Vector&& rvec) : mRVec(std::forward>(rvec)) {} + /**************************** + * non-member functions * + ****************************/ + + RangePtr yrange(const Vector& rs) + { + return YRangeFactory(rs).create(); + } + /******************* * Range Casts * *******************/