yrange implementations (part only)
This commit is contained in:
parent
3764f865e9
commit
3044646b6a
4 changed files with 235 additions and 49 deletions
|
@ -69,13 +69,12 @@ namespace CNORXZ
|
|||
URangeFactory(const Vector<MetaType>& space, const RangePtr& ref);
|
||||
URangeFactory(Vector<MetaType>&& space, const RangePtr& ref);
|
||||
|
||||
protected:
|
||||
URangeFactory() = default;
|
||||
virtual void make() override;
|
||||
|
||||
private:
|
||||
URangeFactory() = default;
|
||||
virtual void make() override final;
|
||||
|
||||
Vector<MetaType> mSpace;
|
||||
RangePtr mRef = nullptr;
|
||||
RangePtr mRef;
|
||||
};
|
||||
|
||||
template <typename MetaType>
|
||||
|
@ -84,21 +83,19 @@ namespace CNORXZ
|
|||
public:
|
||||
typedef RangeBase RB;
|
||||
typedef UIndex<MetaType> IndexType;
|
||||
typedef URangeFactory<MetaType> FType;
|
||||
|
||||
friend URangeFactory<MetaType>;
|
||||
|
||||
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;
|
||||
|
|
|
@ -18,34 +18,87 @@ namespace CNORXZ
|
|||
{
|
||||
public:
|
||||
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:
|
||||
RangePtr mRange;
|
||||
|
||||
Sptr<YRange> mRangePtr;
|
||||
Vector<XIndexPtr> mIs;
|
||||
Vector<SizeT> mBlockSizes; // dim() elements only!!!
|
||||
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
|
||||
|
|
|
@ -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<oType>
|
||||
RangePtr key = mProd = std::shared_ptr<CRange>
|
||||
( new CRange( mSize ) );
|
||||
if(mRef != nullptr) { key = mRef; }
|
||||
this->addToCreated(typeid(oType), { key->id() }, mProd);
|
||||
this->addToCreated(typeid(CRange), { key->id() }, mProd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<YIndex,DType>(pos),
|
||||
mRangePtr(rangeCast<YRange>(range)), mIs(mRangePtr->dim()),
|
||||
mBlockSizes(mRangePtr->dim()), mExternalControl(false)
|
||||
{
|
||||
assert(0);
|
||||
// init ...!!!
|
||||
}
|
||||
|
||||
YIndex::YIndex(const RangePtr& range, const Vector<XIndexPtr>& is) :
|
||||
mRange(range), mIs(is),
|
||||
mBlockSizes(mRange->dim()), mExternalControl(false)
|
||||
YIndex::YIndex(const RangePtr& range, const Vector<XIndexPtr>& is, SizeT pos) :
|
||||
IndexInterface<YIndex,DType>(pos),
|
||||
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);
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -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<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)) {}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue