yrange implementations (part only)

This commit is contained in:
Christian Zimmermann 2022-09-15 23:40:23 +02:00
parent 3764f865e9
commit 3044646b6a
4 changed files with 235 additions and 49 deletions

View file

@ -69,13 +69,12 @@ namespace CNORXZ
URangeFactory(const Vector<MetaType>& space, const RangePtr& ref); URangeFactory(const Vector<MetaType>& space, const RangePtr& ref);
URangeFactory(Vector<MetaType>&& space, const RangePtr& ref); URangeFactory(Vector<MetaType>&& space, const RangePtr& ref);
protected:
URangeFactory() = default;
virtual void make() override;
private: private:
URangeFactory() = default;
virtual void make() override final;
Vector<MetaType> mSpace; Vector<MetaType> mSpace;
RangePtr mRef = nullptr; RangePtr mRef;
}; };
template <typename MetaType> template <typename MetaType>
@ -84,21 +83,19 @@ namespace CNORXZ
public: public:
typedef RangeBase RB; typedef RangeBase RB;
typedef UIndex<MetaType> IndexType; typedef UIndex<MetaType> IndexType;
typedef URangeFactory<MetaType> FType;
friend URangeFactory<MetaType>; friend URangeFactory<MetaType>;
virtual SizeT size() const final; virtual SizeT size() const override final;
virtual SizeT dim() const final; virtual SizeT dim() const override final;
virtual String stringMeta(SizeT pos) const final; virtual String stringMeta(SizeT pos) const override final;
virtual IndexType begin() const final; virtual IndexType begin() const override final;
virtual IndexType end() const final; virtual IndexType end() const override final;
const MetaType& get(SizeT pos) const; const MetaType& get(SizeT pos) const;
SizeT getMeta(const MetaType& metaPos) const; SizeT getMeta(const MetaType& metaPos) const;
private:
protected:
URange() = delete; URange() = delete;
URange(const URange& in) = delete; URange(const URange& in) = delete;

View file

@ -18,34 +18,87 @@ namespace CNORXZ
{ {
public: public:
typedef IndexInterface<YIndex,DType> IB; typedef IndexInterface<YIndex,DType> IB;
typedef YRange RangeType;
DEFAULT_MEMBERS(YIndex);
YIndex(const RangePtr& range, SizeT pos = 0);
YIndex(const RangePtr& range, const Vector<XIndexPtr>& 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<YRange> 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: private:
RangePtr mRange;
Sptr<YRange> mRangePtr;
Vector<XIndexPtr> mIs; Vector<XIndexPtr> mIs;
Vector<SizeT> mBlockSizes; // dim() elements only!!! Vector<SizeT> mBlockSizes; // dim() elements only!!!
bool mExternalControl = false; bool mExternalControl = false;
public:
DEFAULT_MEMBERS(YIndex);
YIndex(const RangePtr& range);
YIndex(const RangePtr& range, const Vector<XIndexPtr>& 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<RangePtr>& rvec);
YRangeFactory(Vector<RangePtr>&& rvec);
YRangeFactory(const Vector<RangePtr>& rvec, const RangePtr& ref);
YRangeFactory(Vector<RangePtr>&& rvec, const RangePtr& ref);
private:
YRangeFactory() = default;
virtual void make() override final;
Vector<RangePtr> mRVec;
RangePtr mRef;
};
class YRange : public RangeInterface<YIndex,DType>
{
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<RangePtr>& rvec);
YRange(Vector<RangePtr>&& rvec);
Vector<RangePtr> mRVec;
};
} }
#endif #endif

View file

@ -105,9 +105,9 @@ namespace CNORXZ
} }
/*************** /**********************
* CRange * * CRangeFactory *
***************/ **********************/
CRangeFactory::CRangeFactory(SizeT size) : CRangeFactory::CRangeFactory(SizeT size) :
mSize(size) {} mSize(size) {}
@ -118,13 +118,13 @@ namespace CNORXZ
void CRangeFactory::make() void CRangeFactory::make()
{ {
if(mRef != nullptr) { if(mRef != nullptr) {
mProd = this->fromCreated(typeid(oType), {mRef->id()}); mProd = this->fromCreated(typeid(CRange), {mRef->id()});
} }
if(mProd == nullptr){ if(mProd == nullptr){
RangePtr key = mProd = std::shared_ptr<oType> RangePtr key = mProd = std::shared_ptr<CRange>
( new CRange( mSize ) ); ( new CRange( mSize ) );
if(mRef != nullptr) { key = mRef; } if(mRef != nullptr) { key = mRef; }
this->addToCreated(typeid(oType), { key->id() }, mProd); this->addToCreated(typeid(CRange), { key->id() }, mProd);
} }
} }

View file

@ -3,19 +3,25 @@
namespace CNORXZ namespace CNORXZ
{ {
YIndex::YIndex(const RangePtr& range) : /***************
mRange(range), mIs(mRange->dim()), * YIndex *
mBlockSizes(mRange->dim()), mExternalControl(false) ***************/
YIndex::YIndex(const RangePtr& range, SizeT pos) :
IndexInterface<YIndex,DType>(pos),
mRangePtr(rangeCast<YRange>(range)), mIs(mRangePtr->dim()),
mBlockSizes(mRangePtr->dim()), mExternalControl(false)
{ {
assert(0); assert(0);
// init ...!!! // init ...!!!
} }
YIndex::YIndex(const RangePtr& range, const Vector<XIndexPtr>& is) : YIndex::YIndex(const RangePtr& range, const Vector<XIndexPtr>& is, SizeT pos) :
mRange(range), mIs(is), IndexInterface<YIndex,DType>(pos),
mBlockSizes(mRange->dim()), mExternalControl(false) mRangePtr(rangeCast<YRange>(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); assert(0);
// init ...!!! // init ...!!!
} }
@ -29,6 +35,7 @@ namespace CNORXZ
YIndex& YIndex::operator=(SizeT pos) YIndex& YIndex::operator=(SizeT pos)
{ {
IB::mPos = pos; IB::mPos = pos;
assert(0);
// sub inds... (LAZY!!!) !!! // sub inds... (LAZY!!!) !!!
return *this; return *this;
} }
@ -36,6 +43,7 @@ namespace CNORXZ
YIndex& YIndex::operator++() YIndex& YIndex::operator++()
{ {
if(mExternalControl) this->sync(); if(mExternalControl) this->sync();
assert(0);
// increment sub inds (LAZY!!!) !!! // increment sub inds (LAZY!!!) !!!
++mPos; ++mPos;
return *this; return *this;
@ -44,31 +52,79 @@ namespace CNORXZ
YIndex& YIndex::operator--() YIndex& YIndex::operator--()
{ {
if(mExternalControl) this->sync(); if(mExternalControl) this->sync();
assert(0);
// decrement sub inds (LAZY!!!) !!! // decrement sub inds (LAZY!!!) !!!
--mPos; --mPos;
return *this; 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) Int YIndex::pp(PtrId idxPtrNum)
{ {
assert(0); assert(0);
// sub inds !!!
return 0; return 0;
} }
Int YIndex::mm(PtrId idxPtrNum) Int YIndex::mm(PtrId idxPtrNum)
{ {
assert(0); assert(0);
// sub inds !!!
return 0; return 0;
} }
SizeT YIndex::dim() const SizeT YIndex::dim() const
{ {
return mRange->dim(); return mRangePtr->dim();
} }
SizeT YIndex::getStepSize(SizeT n) const SizeT YIndex::getStepSize(SizeT n) const
{ {
assert(0); assert(0);
// sub inds !!!
return 0; return 0;
} }
@ -82,7 +138,7 @@ namespace CNORXZ
out += (*it)->stringMeta() + "]"; out += (*it)->stringMeta() + "]";
return out; return out;
} }
DType YIndex::meta() const DType YIndex::meta() const
{ {
//this->sync(); //this->sync();
@ -100,7 +156,7 @@ namespace CNORXZ
} }
return *this; return *this;
} }
/*
DExpr YIndex::ifor(SizeT step, DExpr ex) const DExpr YIndex::ifor(SizeT step, DExpr ex) const
{ {
assert(0); assert(0);
@ -112,5 +168,85 @@ namespace CNORXZ
assert(0); assert(0);
return DExpr(); return DExpr();
} }
*/
/**********************
* YRangeFactory *
**********************/
YRangeFactory::YRangeFactory(const Vector<RangePtr>& rvec) :
mRVec(rvec) {}
YRangeFactory::YRangeFactory(Vector<RangePtr>&& rvec) :
mRVec(std::forward<Vector<RangePtr>>(rvec)) {}
YRangeFactory::YRangeFactory(const Vector<RangePtr>& rvec, const RangePtr& ref) :
mRVec(rvec), mRef(ref) {}
YRangeFactory::YRangeFactory(Vector<RangePtr>&& rvec, const RangePtr& ref) :
mRVec(std::forward<Vector<RangePtr>>(rvec)), mRef(ref) {}
void YRangeFactory::make()
{
Vector<PtrId> 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<YRange>
( 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<RangePtr>& rvec) : mRVec(rvec) {}
YRange::YRange(Vector<RangePtr>&& rvec) : mRVec(std::forward<Vector<RangePtr>>(rvec)) {}
} }