diff --git a/src/include/array/aindex.cc.h b/src/include/array/aindex.cc.h new file mode 100644 index 0000000..3929ee0 --- /dev/null +++ b/src/include/array/aindex.cc.h @@ -0,0 +1,216 @@ + +#ifndef __cxz_aindex_cc_h__ +#define __cxz_aindex_cc_h__ + +#include "aindex.h" +#include "statics/static_for.h" + +namespace CNORXZ +{ + + template + AIndex::AIndex(const T* data, const RangePtr& range, SizeT pos): + IndexInterface,DType>(pos), + mRangePtr(rangeCast(range)), mIs(mRangePtr->dim()), + mBlockSizes(mRangePtr->dim()), mExternalControl(false), + mCData(data) + { + assert(0); + // init ...!!! + } + + template + AIndex& AIndex::operator=(SizeT pos) + { + IB::mPos = pos; + assert(0); + // sub inds... (LAZY!!!) !!! + return *this; + } + + template + AIndex& AIndex::operator++() + { + if(mExternalControl) this->sync(); + assert(0); + // increment sub inds (LAZY!!!) !!! + ++IB::mPos; + return *this; + } + + template + AIndex& AIndex::operator--() + { + if(mExternalControl) this->sync(); + assert(0); + // decrement sub inds (LAZY!!!) !!! + --IB::mPos; + return *this; + } + + template + AIndex AIndex::operator+(Int n) const + { + assert(0); + // sub inds !!! + return AIndex(mCData, mRangePtr, IB::mPos + n); + } + + template + AIndex AIndex::operator-(Int n) const + { + assert(0); + // sub inds !!! + return AIndex(mCData, mRangePtr, IB::mPos - n); + } + + template + AIndex& AIndex::operator+=(Int n) + { + assert(0); + // sub inds !!! + IB::mPos += n; + return *this; + } + + template + AIndex& AIndex::operator-=(Int n) + { + assert(0); + // sub inds !!! + IB::mPos -= n; + return *this; + } + + template + const T& AIndex::operator*() const + { + assert(0); + // sub inds !!! + return mCData[IB::mPos]; + } + + template + const T* AIndex::operator->() const + { + assert(0); + // sub inds !!! + return mCData+IB::mPos; + } + + template + int AIndex::pp(PtrId idxPtrNum) + { + assert(0); + // sub inds !!! + return 0; + } + + template + int AIndex::mm(PtrId idxPtrNum) + { + assert(0); + // sub inds !!! + return 0; + } + + template + SizeT AIndex::dim() const + { + return mIs.size(); + } + + template + RangePtr AIndex::range() const + { + return mRangePtr; + } + + template + SizeT AIndex::getStepSize(SizeT n) const + { + assert(0); + // sub inds !!! + return 0; + } + + template + String AIndex::stringMeta() const + { + String out = "["; + auto it = mIs.begin(); + for(; it != mIs.end()-1; ++it){ + out += (*it)->stringMeta() + ","; + } + out += (*it)->stringMeta() + "]"; + return out; + } + + template + DType AIndex::meta() const + { + //this->sync(); + Vector v(mIs.size()); + std::transform(mIs.begin(), mIs.end(), v.begin(), [](auto& x) { return x->meta(); }); + return DType(v); + } + + template + AIndex& AIndex::at(const DType& meta) + { + auto& v = std::any_cast&>(meta.get()); + assert(v.size() == mIs.size()); + for(SizeT i = 0; i != mIs.size(); ++i){ + mIs[i]->at(v[i]); + } + return *this; + } + /* + template + DExpr AIndex::ifor(SizeT step, DExpr ex) const + { + return mI->ifor(step, ex); + } + + template + DExpr AIndex::iforh(SizeT step, DExpr ex) const + { + return mI->iforh(step, ex); + } + */ + + template + BIndex::BIndex(T* data, const RangePtr& range, SizeT pos) : + AIndex(data, range, pos), mData(data) {} + + template + BIndex::BIndex(T* data, const AIndex& ai, SizeT pos) : + AIndex(data, ai.range(), pos), mData(data) {} + + template + BIndex BIndex::operator+(Int n) const + { + return BIndex(mData, IB::mRangePtr, IB::mPos + n); + } + + template + BIndex BIndex::operator-(Int n) const + { + return BIndex(mData, IB::mRangePtr, IB::mPos - n); + } + + template + T& BIndex::operator*() + { + return mData[AI::mPos]; + } + + template + T* BIndex::operator->() + { + return mData+AI::mPos; + } + +} + +#endif diff --git a/src/include/array/aindex.h b/src/include/array/aindex.h new file mode 100644 index 0000000..9cc8599 --- /dev/null +++ b/src/include/array/aindex.h @@ -0,0 +1,87 @@ + +#ifndef __cxz_aindex_h__ +#define __cxz_aindex_h__ + +#include "ranges/range_base.h" +#include "ranges/index_base.h" +#include "ranges/xfor/xfor.h" +#include "ranges/xindex.h" +#include "ranges/yrange.h" + +namespace CNORXZ +{ + + // rename: AIndex (A = Array) + // implementation similar to YIndex + template + class AIndex : public IndexInterface,DType> + { + public: + typedef IndexInterface,DType> IB; + + DEFAULT_MEMBERS(AIndex); + AIndex(const T* data, const RangePtr& range, SizeT pos = 0); + + AIndex& sync(); // recalculate 'IB::mPos' when externalControl == true + AIndex& operator()(const Vector& inds); // control via external indice + AIndex& operator()(); // -> sync; just to shorten the code + + AIndex& operator=(SizeT pos); + AIndex& operator++(); + AIndex& operator--(); + AIndex operator+(Int n) const; + AIndex operator-(Int n) const; + AIndex& operator+=(Int n); + AIndex& operator-=(Int n); + + const T& operator*() const; + const T* operator->() const; + + Int pp(PtrId idxPtrNum); + Int mm(PtrId idxPtrNum); + + SizeT dim() const; + RangePtr range() const; + SizeT getStepSize(SizeT n) const; + + String stringMeta() const; + DType meta() const; + AIndex& at(const DType& meta); + + //DExpr ifor(SizeT step, DExpr ex) const; + //DExpr iforh(SizeT step, DExpr ex) const; + + protected: + Sptr mRangePtr; + Vector mIs; + Vector mBlockSizes; // dim() elements only!!! + bool mExternalControl = false; + const T* mCData = nullptr; + + }; + + // BIndex (because B comes after A...) + template + class BIndex : public AIndex + { + public: + typedef AIndex AI; + typedef typename AI::IB IB; + + DEFAULT_MEMBERS(BIndex); + BIndex(T* data, const RangePtr& range, SizeT pos = 0); + BIndex(T* data, const AIndex& cci, SizeT pos = 0); + + BIndex operator+(Int n) const; + BIndex operator-(Int n) const; + + T& operator*(); + T* operator->(); + + private: + T* mData = nullptr; + + }; +} + +#endif diff --git a/src/include/array/array.cc.h b/src/include/array/array.cc.h index fbc55db..ce33281 100644 --- a/src/include/array/array.cc.h +++ b/src/include/array/array.cc.h @@ -2,5 +2,5 @@ //#include "access.cc.h" #include "darray_base.cc.h" #include "darray.cc.h" -#include "dcontainer_index.cc.h" +#include "aindex.cc.h" //#include "functional_array.cc.h" diff --git a/src/include/array/array.h b/src/include/array/array.h index 183812d..8f07d26 100644 --- a/src/include/array/array.h +++ b/src/include/array/array.h @@ -2,7 +2,7 @@ //#include "access.h" #include "darray_base.h" #include "darray.h" -#include "dcontainer_index.h" +#include "aindex.h" //#include "functional_array.h" #include "array.cc.h" diff --git a/src/include/array/darray_base.cc.h b/src/include/array/darray_base.cc.h index 7e09dd1..a64e8df 100644 --- a/src/include/array/darray_base.cc.h +++ b/src/include/array/darray_base.cc.h @@ -28,7 +28,7 @@ namespace CNORXZ } template - size_t DArrayBase::size() const + SizeT DArrayBase::size() const { return mRange->size(); } diff --git a/src/include/array/darray_base.h b/src/include/array/darray_base.h index 1a65be4..c7491bf 100644 --- a/src/include/array/darray_base.h +++ b/src/include/array/darray_base.h @@ -8,7 +8,7 @@ #include #include "base/base.h" -#include "dcontainer_index.h" +#include "aindex.h" //#include "operation/" namespace CNORXZ @@ -17,7 +17,7 @@ namespace CNORXZ class DArrayBase { public: - typedef DConstContainerIndex const_iterator; + typedef AIndex const_iterator; protected: RangePtr mRange; @@ -37,10 +37,10 @@ namespace CNORXZ const T& at(const IndexInterface& i) const; template - DArrayBase sl(const IndexInterface& i) const; + Sptr> sl(const IndexInterface& i) const; virtual const T* data() const = 0; - virtual size_t size() const; + virtual SizeT size() const; virtual RangePtr range() const; virtual const_iterator begin() const; @@ -61,7 +61,7 @@ namespace CNORXZ public: typedef DArrayBase DAB; typedef typename DAB::const_iterator const_iterator; - typedef DContainerIndex iterator; + typedef BIndex iterator; using DAB::operator[]; using DAB::at; @@ -82,7 +82,7 @@ namespace CNORXZ T& at(const IndexInterface& i); template - std::shared_ptr> sl(const IndexInterface& i); + Sptr> sl(const IndexInterface& i); virtual T* data() = 0; diff --git a/src/include/array/dcontainer_index.cc.h b/src/include/array/dcontainer_index.cc.h deleted file mode 100644 index f9a5d62..0000000 --- a/src/include/array/dcontainer_index.cc.h +++ /dev/null @@ -1,134 +0,0 @@ - -#ifndef __cxz_dcontainer_index_cc_h__ -#define __cxz_dcontainer_index_cc_h__ - -#include "dcontainer_index.h" -#include "statics/static_for.h" - -namespace CNORXZ -{ - - template - DConstContainerIndex::DConstContainerIndex(const T* data, const RangePtr& range): - mI(range->begin()), mCData(data) - { - assert(0); - } - - template - DConstContainerIndex& DConstContainerIndex::operator=(SizeT pos) - { - (*mI) = pos; - IB::mPos = mI->pos(); - return *this; - } - - template - DConstContainerIndex& DConstContainerIndex::operator++() - { - ++(*mI); - IB::mPos = mI->pos(); - return *this; - } - - template - DConstContainerIndex& DConstContainerIndex::operator--() - { - --(*mI); - IB::mPos = mI->pos(); - return *this; - } - - template - int DConstContainerIndex::pp(PtrId idxPtrNum) - { - return mI->pp(idxPtrNum); - } - - template - int DConstContainerIndex::mm(PtrId idxPtrNum) - { - return mI->mm(idxPtrNum); - } - - template - SizeT DConstContainerIndex::dim() const - { - return mI->dim(); - } - - template - SizeT DConstContainerIndex::getStepSize(SizeT n) const - { - return mI->getStepSize(n); // dim() elements only!!! - } - - template - String DConstContainerIndex::stringMeta() const - { - return mI->stringMeta(); - } - - template - DType DConstContainerIndex::meta() const - { - return mI->meta(); - } - - template - DConstContainerIndex& DConstContainerIndex::at(const DType& meta) - { - mI->at(meta); - IB::mPos = mI->pos(); - return *this; - } - /* - template - DExpr DConstContainerIndex::ifor(SizeT step, DExpr ex) const - { - return mI->ifor(step, ex); - } - - template - DExpr DConstContainerIndex::iforh(SizeT step, DExpr ex) const - { - return mI->iforh(step, ex); - } - */ - template - const T& DConstContainerIndex::operator*() const - { - //this->sync(); - return mCData[mI->pos()]; - } - - template - const T* DConstContainerIndex::operator->() const - { - //this->sync(); - return mCData+mI->pos(); - } - - template - DContainerIndex::DContainerIndex(T* data, const RangePtr& range) : - DConstContainerIndex(range), mData(data) {} - - template - DContainerIndex::DContainerIndex(T* data, const DConstContainerIndex& cci) : - DConstContainerIndex(data, cci.range()), mData(data) {} - - template - T& DContainerIndex::operator*() - { - return mData[CCI::mI->pos()]; - } - - template - T* DContainerIndex::operator->() - { - return mData+CCI::mI->pos(); - } - -} - -#endif diff --git a/src/include/array/dcontainer_index.h b/src/include/array/dcontainer_index.h deleted file mode 100644 index 1bb3359..0000000 --- a/src/include/array/dcontainer_index.h +++ /dev/null @@ -1,74 +0,0 @@ - -#ifndef __cxz_dcontainer_index_h__ -#define __cxz_dcontainer_index_h__ - -#include "ranges/range_base.h" -#include "ranges/index_base.h" -#include "ranges/xfor/xfor.h" -#include "ranges/xindex.h" -#include "ranges/yrange.h" - -namespace CNORXZ -{ - - // rename: AIndex (A = Array) - template - class DConstContainerIndex : public IndexInterface,DType> - { - public: - typedef IndexInterface,DType> IB; - - protected: - YIndexPtr mI; - const T* mCData = nullptr; - - public: - DEFAULT_MEMBERS(DConstContainerIndex); - DConstContainerIndex(const T* data, const RangePtr& range); - - DConstContainerIndex& operator=(SizeT pos); - DConstContainerIndex& operator++(); - DConstContainerIndex& operator--(); - - int pp(PtrId idxPtrNum); - int mm(PtrId idxPtrNum); - SizeT dim() const; - SizeT getStepSize(SizeT n) const; - String stringMeta() const; - DType meta() const; - DType metaPtr() const; - DConstContainerIndex& at(const DType& meta); - //DExpr ifor(SizeT step, DExpr ex) const; - //DExpr iforh(SizeT step, DExpr ex) const; - - const T& operator*() const; - const T* operator->() const; - - DConstContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true - DConstContainerIndex& operator()(const std::vector& inds); // control via external indice - DConstContainerIndex& operator()(); // -> sync; just to shorten the code - - }; - - template - class DContainerIndex : public DConstContainerIndex - { - public: - typedef DConstContainerIndex CCI; - typedef typename CCI::IB IB; - - private: - T* mData = nullptr; - - public: - - DEFAULT_MEMBERS(DContainerIndex); - DContainerIndex(T* data, const RangePtr& range); - DContainerIndex(T* data, const DConstContainerIndex& cci); - - T& operator*(); - T* operator->(); - }; -} - -#endif diff --git a/src/include/base/types.h b/src/include/base/types.h index b4c76c5..455587d 100644 --- a/src/include/base/types.h +++ b/src/include/base/types.h @@ -59,11 +59,14 @@ namespace CNORXZ S = Static P = Partial = Sub C = Classic - M = Multi or !const + M = Multi (Index,Ranges) or !const (Container) U = One(=Uni) dimensional N = None = Null + E = Extension (SSE,AVX,etc dof) T = Thread R = Rank + A = (const) Array + B = (mutable) Array ***/ // definition: base/dtype.h diff --git a/src/include/ranges/yrange.cc.h b/src/include/ranges/yrange.cc.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/include/ranges/yrange.cc.h @@ -0,0 +1 @@ + diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 4bf7077..9337c0b 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -24,7 +24,7 @@ namespace CNORXZ YIndex(const RangePtr& range, SizeT pos = 0); YIndex(const RangePtr& range, const Vector& is, SizeT pos = 0); - YIndex& sync(); + YIndex& sync(); // remove!!! YIndex& operator=(SizeT pos); YIndex& operator++(); @@ -56,7 +56,6 @@ namespace CNORXZ Sptr mRangePtr; Vector mIs; Vector mBlockSizes; // dim() elements only!!! - bool mExternalControl = false; }; diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 1443a76..9b5e41a 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -10,7 +10,7 @@ namespace CNORXZ YIndex::YIndex(const RangePtr& range, SizeT pos) : IndexInterface(pos), mRangePtr(rangeCast(range)), mIs(mRangePtr->dim()), - mBlockSizes(mRangePtr->dim()), mExternalControl(false) + mBlockSizes(mRangePtr->dim()) { assert(0); // init ...!!! @@ -19,7 +19,7 @@ namespace CNORXZ YIndex::YIndex(const RangePtr& range, const Vector& is, SizeT pos) : IndexInterface(pos), mRangePtr(rangeCast(range)), mIs(is), - mBlockSizes(mRangePtr->dim()), mExternalControl(false) + mBlockSizes(mRangePtr->dim()) { CXZ_ASSERT(mIs.size() == mRangePtr->dim(), "obtained wrong number of indices"); assert(0); @@ -42,7 +42,6 @@ namespace CNORXZ YIndex& YIndex::operator++() { - if(mExternalControl) this->sync(); assert(0); // increment sub inds (LAZY!!!) !!! ++mPos; @@ -51,7 +50,6 @@ namespace CNORXZ YIndex& YIndex::operator--() { - if(mExternalControl) this->sync(); assert(0); // decrement sub inds (LAZY!!!) !!! --mPos; @@ -91,14 +89,12 @@ namespace CNORXZ DType YIndex::operator*() const { assert(0); - // sub inds !!! return DType(); } DType YIndex::operator->() const { assert(0); - // sub inds !!! return DType(); } @@ -141,7 +137,6 @@ namespace CNORXZ DType YIndex::meta() const { - //this->sync(); Vector v(mIs.size()); std::transform(mIs.begin(), mIs.end(), v.begin(), [](auto& x) { return x->meta(); }); return DType(v);