From 3044646b6ac1775ceb9e5e3c4a131ad464e1cdfb Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 15 Sep 2022 23:40:23 +0200 Subject: [PATCH] yrange implementations (part only) --- src/include/ranges/urange.h | 23 +++--- src/include/ranges/yrange.h | 93 ++++++++++++++++----- src/lib/ranges/crange.cc | 12 +-- src/lib/ranges/yrange.cc | 156 +++++++++++++++++++++++++++++++++--- 4 files changed, 235 insertions(+), 49 deletions(-) diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index bee4f12..216e62a 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -69,13 +69,12 @@ namespace CNORXZ URangeFactory(const Vector& space, const RangePtr& ref); URangeFactory(Vector&& space, const RangePtr& ref); - protected: - URangeFactory() = default; - virtual void make() override; - private: + URangeFactory() = default; + virtual void make() override final; + Vector mSpace; - RangePtr mRef = nullptr; + RangePtr mRef; }; template @@ -84,21 +83,19 @@ namespace CNORXZ public: typedef RangeBase RB; typedef UIndex IndexType; - typedef URangeFactory FType; friend URangeFactory; - virtual SizeT size() const final; - virtual SizeT dim() const final; - virtual String stringMeta(SizeT pos) const final; - virtual IndexType begin() const final; - virtual IndexType end() const final; + virtual SizeT size() const override final; + virtual SizeT dim() const override final; + virtual String stringMeta(SizeT pos) const override final; + virtual IndexType begin() const override final; + virtual IndexType end() const override final; const MetaType& get(SizeT pos) const; SizeT getMeta(const MetaType& metaPos) const; - - protected: + private: URange() = delete; URange(const URange& in) = delete; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 2a29f58..4bf7077 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -18,34 +18,87 @@ namespace CNORXZ { public: typedef IndexInterface IB; + typedef YRange RangeType; + DEFAULT_MEMBERS(YIndex); + YIndex(const RangePtr& range, SizeT pos = 0); + YIndex(const RangePtr& range, const Vector& is, SizeT pos = 0); + + YIndex& sync(); + + YIndex& operator=(SizeT pos); + YIndex& operator++(); + YIndex& operator--(); + YIndex operator+(Int n) const; + YIndex operator-(Int n) const; + YIndex& operator+=(Int n); + YIndex& operator-=(Int n); + + DType operator*() const; + DType operator->() const; + + Int pp(PtrId idxPtrNum); + Int mm(PtrId idxPtrNum); + + SizeT dim() const; + Sptr range() const; + SizeT getStepSize(SizeT n) const; + + String stringMeta() const; + DType meta() const; + YIndex& at(const DType& meta); + + //DExpr ifor(SizeT step, DExpr ex) const; + //DExpr iforh(SizeT step, DExpr ex) const; + private: - RangePtr mRange; + + Sptr mRangePtr; Vector mIs; Vector mBlockSizes; // dim() elements only!!! bool mExternalControl = false; - public: - - DEFAULT_MEMBERS(YIndex); - YIndex(const RangePtr& range); - YIndex(const RangePtr& range, const Vector& is); - - YIndex& sync(); - YIndex& operator=(SizeT pos); - YIndex& operator++(); - YIndex& operator--(); - int pp(PtrId idxPtrNum); - int mm(PtrId idxPtrNum); - size_t dim() const; - size_t getStepSize(SizeT n) const; - String stringMeta() const; - DType meta() const; - YIndex& at(const DType& meta); - DExpr ifor(SizeT step, DExpr ex) const; - DExpr iforh(SizeT step, DExpr ex) const; }; + class YRangeFactory : public RangeFactoryBase + { + public: + YRangeFactory(const Vector& rvec); + YRangeFactory(Vector&& rvec); + YRangeFactory(const Vector& rvec, const RangePtr& ref); + YRangeFactory(Vector&& rvec, const RangePtr& ref); + + private: + YRangeFactory() = default; + virtual void make() override final; + + Vector mRVec; + RangePtr mRef; + }; + + class YRange : public RangeInterface + { + public: + typedef RangeBase RB; + typedef YIndex IndexType; + + friend YRangeFactory; + + virtual SizeT size() const override final; + virtual SizeT dim() const override final; + virtual String stringMeta(SizeT pos) const override final; + virtual const TypeInfo& type() const override final; + virtual const TypeInfo& metaType() const override final; + + private: + + YRange() = delete; + YRange(const YRange& a) = delete; + YRange(const Vector& rvec); + YRange(Vector&& rvec); + + Vector mRVec; + }; } #endif diff --git a/src/lib/ranges/crange.cc b/src/lib/ranges/crange.cc index 6247cf1..aa36ae1 100644 --- a/src/lib/ranges/crange.cc +++ b/src/lib/ranges/crange.cc @@ -105,9 +105,9 @@ namespace CNORXZ } - /*************** - * CRange * - ***************/ + /********************** + * CRangeFactory * + **********************/ CRangeFactory::CRangeFactory(SizeT size) : mSize(size) {} @@ -118,13 +118,13 @@ namespace CNORXZ void CRangeFactory::make() { if(mRef != nullptr) { - mProd = this->fromCreated(typeid(oType), {mRef->id()}); + mProd = this->fromCreated(typeid(CRange), {mRef->id()}); } if(mProd == nullptr){ - RangePtr key = mProd = std::shared_ptr + RangePtr key = mProd = std::shared_ptr ( new CRange( mSize ) ); if(mRef != nullptr) { key = mRef; } - this->addToCreated(typeid(oType), { key->id() }, mProd); + this->addToCreated(typeid(CRange), { key->id() }, mProd); } } diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index f620def..1443a76 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -3,19 +3,25 @@ namespace CNORXZ { - YIndex::YIndex(const RangePtr& range) : - mRange(range), mIs(mRange->dim()), - mBlockSizes(mRange->dim()), mExternalControl(false) + /*************** + * YIndex * + ***************/ + + YIndex::YIndex(const RangePtr& range, SizeT pos) : + IndexInterface(pos), + mRangePtr(rangeCast(range)), mIs(mRangePtr->dim()), + mBlockSizes(mRangePtr->dim()), mExternalControl(false) { assert(0); // init ...!!! } - YIndex::YIndex(const RangePtr& range, const Vector& is) : - mRange(range), mIs(is), - mBlockSizes(mRange->dim()), mExternalControl(false) + YIndex::YIndex(const RangePtr& range, const Vector& is, SizeT pos) : + IndexInterface(pos), + mRangePtr(rangeCast(range)), mIs(is), + mBlockSizes(mRangePtr->dim()), mExternalControl(false) { - CXZ_ASSERT(mIs.size() == mRange->dim(), "obtained wrong number of indices"); + CXZ_ASSERT(mIs.size() == mRangePtr->dim(), "obtained wrong number of indices"); assert(0); // init ...!!! } @@ -29,6 +35,7 @@ namespace CNORXZ YIndex& YIndex::operator=(SizeT pos) { IB::mPos = pos; + assert(0); // sub inds... (LAZY!!!) !!! return *this; } @@ -36,6 +43,7 @@ namespace CNORXZ YIndex& YIndex::operator++() { if(mExternalControl) this->sync(); + assert(0); // increment sub inds (LAZY!!!) !!! ++mPos; return *this; @@ -44,31 +52,79 @@ namespace CNORXZ YIndex& YIndex::operator--() { if(mExternalControl) this->sync(); + assert(0); // decrement sub inds (LAZY!!!) !!! --mPos; return *this; } + YIndex YIndex::operator+(Int n) const + { + assert(0); + // sub inds !!! + return YIndex(mRangePtr, IB::mPos + n); + } + + YIndex YIndex::operator-(Int n) const + { + assert(0); + // sub inds !!! + return YIndex(mRangePtr, IB::mPos - n); + } + + YIndex& YIndex::operator+=(Int n) + { + assert(0); + // sub inds !!! + IB::mPos += n; + return *this; + } + + YIndex& YIndex::operator-=(Int n) + { + assert(0); + // sub inds !!! + IB::mPos -= n; + return *this; + } + + DType YIndex::operator*() const + { + assert(0); + // sub inds !!! + return DType(); + } + + DType YIndex::operator->() const + { + assert(0); + // sub inds !!! + return DType(); + } + Int YIndex::pp(PtrId idxPtrNum) { assert(0); + // sub inds !!! return 0; } Int YIndex::mm(PtrId idxPtrNum) { assert(0); + // sub inds !!! return 0; } SizeT YIndex::dim() const { - return mRange->dim(); + return mRangePtr->dim(); } SizeT YIndex::getStepSize(SizeT n) const { assert(0); + // sub inds !!! return 0; } @@ -82,7 +138,7 @@ namespace CNORXZ out += (*it)->stringMeta() + "]"; return out; } - + DType YIndex::meta() const { //this->sync(); @@ -100,7 +156,7 @@ namespace CNORXZ } return *this; } - + /* DExpr YIndex::ifor(SizeT step, DExpr ex) const { assert(0); @@ -112,5 +168,85 @@ namespace CNORXZ assert(0); return DExpr(); } + */ + + /********************** + * YRangeFactory * + **********************/ + + YRangeFactory::YRangeFactory(const Vector& rvec) : + mRVec(rvec) {} + + YRangeFactory::YRangeFactory(Vector&& rvec) : + mRVec(std::forward>(rvec)) {} + + YRangeFactory::YRangeFactory(const Vector& rvec, const RangePtr& ref) : + mRVec(rvec), mRef(ref) {} + + YRangeFactory::YRangeFactory(Vector&& rvec, const RangePtr& ref) : + mRVec(std::forward>(rvec)), mRef(ref) {} + + void YRangeFactory::make() + { + Vector key; + std::transform(mRVec.begin(), mRVec.end(), key.begin(), + [&](const RangePtr& r) { return r->id(); } ); + mProd = this->fromCreated(typeid(YRange), key); + if(mProd == nullptr){ + mProd = std::shared_ptr + ( new YRange( std::move(mRVec) ) ); + this->addToCreated(typeid(YRange), key, mProd); + } + } + + /*************** + * YRange * + ***************/ + + SizeT YRange::size() const + { + SizeT out = 1; + for(auto& r: mRVec){ + out *= r->size(); + } + return out; + } + + SizeT YRange::dim() const + { + return mRVec.size(); + } + + String YRange::stringMeta(SizeT pos) const + { + String out = "["; + for(auto rit = mRVec.end()-1;;--rit){ + const SizeT cursize = (*rit)->size(); + const SizeT curpos = pos % cursize; + out += (*rit)->stringMeta(curpos); + pos -= curpos; + pos /= cursize; + if(rit == mRVec.begin()){ + out += "]"; + break; + } + out += ","; + } + return out; + } + + const TypeInfo& YRange::type() const + { + return typeid(YRange); + } + + const TypeInfo& YRange::metaType() const + { + return typeid(DType); + } + + YRange::YRange(const Vector& rvec) : mRVec(rvec) {} + + YRange::YRange(Vector&& rvec) : mRVec(std::forward>(rvec)) {} }