From be44541135dccc01f71e15b74461724665a1d0bc Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 5 Nov 2023 22:20:12 +0100 Subject: [PATCH] more doxy comments + WIP: index member function formatIsTrivial --- src/include/array/array_base.cc.h | 36 ++++--- src/include/array/array_base.h | 151 ++++++++++++++++++++++++++++-- src/include/array/marray.cc.h | 15 ++- src/include/array/marray.h | 3 + src/include/array/slice.cc.h | 32 +++++-- src/include/array/slice.h | 61 +++++++++--- src/include/ranges/crange.h | 3 + src/include/ranges/dindex.h | 3 + src/include/ranges/index_base.h | 5 +- src/include/ranges/mrange.cc.h | 7 ++ src/include/ranges/mrange.h | 3 + src/include/ranges/prange.cc.h | 25 ++--- src/include/ranges/prange.h | 9 +- src/include/ranges/srange.cc.h | 25 ++--- src/include/ranges/srange.h | 3 + src/include/ranges/urange.cc.h | 6 ++ src/include/ranges/urange.h | 3 + src/include/ranges/xindex.cc.h | 6 ++ src/include/ranges/xindex.h | 3 + src/include/ranges/yrange.h | 3 + src/lib/ranges/crange.cc | 5 + src/lib/ranges/dindex.cc | 5 + src/lib/ranges/yrange.cc | 8 +- 23 files changed, 332 insertions(+), 88 deletions(-) diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index 80ce363..02daf86 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -18,9 +18,9 @@ namespace CNORXZ { - /****************** - * CArrayBase * - ******************/ + /*=======================================================+ + | Implementations for CArrayBase member functions | + +=======================================================*/ template CArrayBase::CArrayBase(const RangePtr& range) : @@ -31,6 +31,11 @@ namespace CNORXZ template const T& CArrayBase::operator[](const IndexInterface& i) const { + /* + TODO: check if container format is trivial: + if yes, just return data[i.lex()], in case of at() check extensions + if not, do what is done now + */ auto ai = itLex(i); return *ai; } @@ -111,6 +116,13 @@ namespace CNORXZ template COpRoot CArrayBase::operator()(const Sptr& i) const { + /* + TODO: check if container format is trivial + if yes, assert that index format is trivial and has correct extensions + if not, check if index format is trivial + - if yes: try to apply container format + - if not: check if format is compatible + */ this->checkFormatCompatibility(*i); return coproot(*this, i); } @@ -132,9 +144,9 @@ namespace CNORXZ return coproot(*this, i); } - /****************************** - * CArrayBase (protected) * - ******************************/ + /*=================================================================+ + | Implementations for protected CArrayBase member functions | + +=================================================================*/ template template @@ -185,9 +197,9 @@ namespace CNORXZ } } - /***************** - * ArrayBase * - *****************/ + /*======================================================+ + | Implementations for ArrayBase member functions | + +======================================================*/ template ArrayBase::ArrayBase(const RangePtr& range) : @@ -287,9 +299,9 @@ namespace CNORXZ return oproot(*this, i); } - /***************************** - * ArrayBase (protected) * - *****************************/ + /*================================================================+ + | Implementations for protected ArrayBase member functions | + +================================================================*/ template template diff --git a/src/include/array/array_base.h b/src/include/array/array_base.h index 9d67752..155325a 100644 --- a/src/include/array/array_base.h +++ b/src/include/array/array_base.h @@ -24,75 +24,175 @@ namespace CNORXZ { + /** **** + Abstract container base class + only read access to the data + + @tparam T data type + */ template class CArrayBase { public: - typedef AIndex const_iterator; + typedef AIndex const_iterator; /** const iterator type */ + DEFAULT_MEMBERS(CArrayBase); /**< default constructors and assignments */ + + /** construct container on a range + @param range + */ CArrayBase(const RangePtr& range); - DEFAULT_MEMBERS(CArrayBase); + /** default destructor */ virtual ~CArrayBase() = default; + /** const data element access + @tparam I index type + @tparam M meta data type + @param i index + */ template const T& operator[](const IndexInterface& i) const; + /** const data element access + performs compatibility checks + @tparam I index type + @tparam M meta data type + @param i index + */ template const T& at(const IndexInterface& i) const; + /** const data element access + @tparam I index type + @tparam M meta data type + @param pack static index pack + */ template const T& operator[](const SPack& pack) const; + /** const data element access + performs compatibility checks + @tparam I index type + @tparam M meta data type + @param i static index pack + */ template const T& at(const SPack& pack) const; + /** const data element access + @param pack index pack + */ const T& operator[](const DPack& pack) const; + + /** const data element access + performs compatibility checks + @param i index pack + */ const T& at(const DPack& pack) const; + /** create hypercubic slice from this container + @tparam I type of index used to indicate slice edges + @tparam M index meta type + @param begin begin edge + @param end end edge + */ template Sptr> sl(const IndexInterface& begin, const IndexInterface& end) const; + /** create operation on this container + @tparam Index type of operation index + @param i operation index + */ template COpRoot operator()(const Sptr& i) const; + /** create operation on this container + @tparam Indices types of operation indices + @param pack pack of operation index + */ template inline decltype(auto) operator()(const SPack& pack) const; + /** create operation on this container + @param pack pack of operation index + */ inline decltype(auto) operator()(const DPack& pack) const; + /** get pointer to container data */ virtual const T* data() const = 0; + + /** get number of elements in the container */ virtual SizeT size() const; + + /** get container range */ virtual RangePtr range() const; + /** get index pointing to first position */ virtual const_iterator begin() const; + + /** get index pointing to position after last position */ virtual const_iterator end() const; + + /** get index pointing to first position */ virtual const_iterator cbegin() const = 0; + + /** get index pointing to position after last position */ virtual const_iterator cend() const = 0; + /** check if container views the data, i.e. it does not own it */ virtual bool isView() const = 0; protected: - RangePtr mRange; + RangePtr mRange; /**< the container range */ + /** Get valid data index. + Create well-formated index from index pack (unformatted) + or index using trivial format. + @tparam Acc index type or index pack type + @param acc index or index pack + */ template const_iterator itLex(const Acc& acc) const; + /** Get valid data index. + Create well-formated index from index pack (unformatted) + or index using trivial format. + Perform compatibility checks. + @tparam Acc index type or index pack type + @param acc index or index pack + */ template const_iterator itLexSave(const Acc& acc) const; + /** Perform compatibility checks + @tparam Acc index type or index pack type + @param acc index or index pack. + */ template void checkFormatCompatibility(const Acc& acc) const; + + /** check if format is trivial + @return true is container is data owning array, else return + result of the corresponding container index + */ + virtual bool formatIsTrivial() const = 0; }; + /** **** + Abstract container base class + read and write access to the data + + @tparam T data type + */ template class ArrayBase : public CArrayBase { public: typedef CArrayBase CAB; - typedef typename CAB::const_iterator const_iterator; - typedef BIndex iterator; + typedef typename CAB::const_iterator const_iterator; /**< constant iterator type */ + typedef BIndex iterator; /**< read/write iterator type */ using CAB::operator[]; using CAB::operator(); @@ -103,48 +203,85 @@ namespace CNORXZ using CAB::cbegin; using CAB::cend; using CAB::sl; - //using CAB::operator(); + DEFAULT_MEMBERS(ArrayBase); /**< default constructors and assignments */ + + /** construct a container on a range + */ ArrayBase(const RangePtr& range); - DEFAULT_MEMBERS(ArrayBase); + /** @copydoc CArrayBase::operator[]() + */ template T& operator[](const IndexInterface& i); + /** @copydoc CArrayBase::at() + */ template T& at(const IndexInterface& i); + /** @copydoc CArrayBase::operator[]() + */ template T& operator[](const SPack& pack); + /** @copydoc CArrayBase::at() + */ template T& at(const SPack& pack); + /** @copydoc CArrayBase::operator[]() + */ T& operator[](const DPack& pack); + + /** @copydoc CArrayBase::at() + */ T& at(const DPack& pack); + /** @copydoc CArrayBase::operator()() + */ template OpRoot operator()(const Sptr& i); + /** @copydoc CArrayBase::operator()() + */ template inline decltype(auto) operator()(const SPack& pack); + /** @copydoc CArrayBase::operator()() + */ inline decltype(auto) operator()(const DPack& pack); + /** @copydoc CArrayBase::sl() + */ template Sptr> sl(const IndexInterface& begin, const IndexInterface& end); + /** @copydoc CArrayBase::data() + read/write access + */ virtual T* data() = 0; + /** @copydoc CArrayBase::begin() + read/write access + */ virtual iterator begin(); + + /** @copydoc CArrayBase::end() + read/write access + */ virtual iterator end(); protected: + /** @copydoc CArrayBase::itLex() + */ template iterator itLex(const Acc& acc); + /** @copydoc CArrayBase::itLexSave() + */ template iterator itLexSave(const Acc& acc); }; diff --git a/src/include/array/marray.cc.h b/src/include/array/marray.cc.h index 591ce8e..3ea3923 100644 --- a/src/include/array/marray.cc.h +++ b/src/include/array/marray.cc.h @@ -17,9 +17,9 @@ namespace CNORXZ { - /**************** - * MArray * - ***************/ + /*=======================================================+ + | Implementation of MArray public member functions | + +=======================================================*/ template MArray::MArray(const RangePtr& range) : @@ -92,6 +92,15 @@ namespace CNORXZ return false; } + /*==========================================================+ + | Implementation of MArray protected member functions | + +==========================================================*/ + + template + bool MArray::formatIsTrivial() const + { + return true; + } } #endif diff --git a/src/include/array/marray.h b/src/include/array/marray.h index 1f561ea..8195e16 100644 --- a/src/include/array/marray.h +++ b/src/include/array/marray.h @@ -42,6 +42,9 @@ namespace CNORXZ virtual bool isView() const override; SERIALIZATION_FUNCTIONS; + + protected: + virtual bool formatIsTrivial() const override final; private: Vector mCont; diff --git a/src/include/array/slice.cc.h b/src/include/array/slice.cc.h index a1df1d0..1dca0cf 100644 --- a/src/include/array/slice.cc.h +++ b/src/include/array/slice.cc.h @@ -17,9 +17,9 @@ namespace CNORXZ { - /************** - * CSlice * - **************/ + /*========================================================+ + | Implementation of public CSlice member functions | + +========================================================*/ template CSlice::CSlice(const RangePtr& range, const CArrayBase* parent, @@ -54,9 +54,19 @@ namespace CNORXZ return true; } - /************* - * Slice * - *************/ + /*===========================================================+ + | Implementation of protected CSlice member functions | + +===========================================================*/ + + template + bool CSlice::formatIsTrivial() const + { + return cbegin().formatIsTrivial(); + } + + /*=======================================================+ + | Implementation of public Slice member functions | + +=======================================================*/ template Slice::Slice(const RangePtr& range, ArrayBase* parent, @@ -96,6 +106,16 @@ namespace CNORXZ { return true; } + + /*==========================================================+ + | Implementation of protected Slice member functions | + +==========================================================*/ + + template + bool Slice::formatIsTrivial() const + { + return cbegin().formatIsTrivial(); + } } #endif diff --git a/src/include/array/slice.h b/src/include/array/slice.h index 9959dc8..a636b1a 100644 --- a/src/include/array/slice.h +++ b/src/include/array/slice.h @@ -18,6 +18,12 @@ namespace CNORXZ { + /** **** + constant and possibly partial view on the data + of another container + + @tparam T data type + */ template class CSlice : public CArrayBase { @@ -25,13 +31,15 @@ namespace CNORXZ typedef CArrayBase AB; typedef typename AB::const_iterator const_iterator; - protected: - const CArrayBase* mCParent = nullptr; - YFormat mBlockSizes; - SizeT mOff = 0; - - public: - DEFAULT_MEMBERS(CSlice); + DEFAULT_MEMBERS(CSlice); /**< default constructors and assignments */ + + /** create slice from an array + + @param range the slice's container range + @param parent the original container + @param blockSizes the format of the slice + @param off the initial pointer position w.r.t. the original initial position + */ CSlice(const RangePtr& range, const CArrayBase* parent, const YFormat& blockSizes, SizeT off); @@ -39,23 +47,39 @@ namespace CNORXZ virtual const_iterator cbegin() const override; virtual const_iterator cend() const override; virtual bool isView() const override final; + + protected: + + virtual bool formatIsTrivial() const override final; + + const CArrayBase* mCParent = nullptr; /**< pointer to the original container */ + YFormat mBlockSizes; /**< the format */ + SizeT mOff = 0; /** pointer offset w.r.t. the original pointer */ + }; + /** **** + possibly partial view on the data + of another container + + @tparam T data type + */ template class Slice : public ArrayBase { public: typedef CArrayBase AB; - //typedef CSlice CS; typedef typename AB::const_iterator const_iterator; - private: - ArrayBase* mParent = nullptr; - YFormat mBlockSizes; - SizeT mOff = 0; + DEFAULT_MEMBERS(Slice); /**< default constructors and assignments */ - public: - DEFAULT_MEMBERS(Slice); + /** create slice from an array + + @param range the slice's container range + @param parent the original container + @param blockSizes the format of the slice + @param off the initial pointer position w.r.t. the original initial position + */ Slice(const RangePtr& range, ArrayBase* parent, const YFormat& blockSizes, SizeT off); @@ -64,6 +88,15 @@ namespace CNORXZ virtual const_iterator cbegin() const override; virtual const_iterator cend() const override; virtual bool isView() const override final; + + protected: + virtual bool formatIsTrivial() const override final; + + private: + ArrayBase* mParent = nullptr; + YFormat mBlockSizes; + SizeT mOff = 0; + }; } diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index 5675b3f..07f6352 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -111,6 +111,9 @@ namespace CNORXZ template decltype(auto) ifor(const Xpr& xpr, F&& f) const; + /** @copydoc IndexInterface::formatIsTrivial() */ + bool formatIsTrivial() const; + private: Sptr mRangePtr; }; diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index dfe98ad..80fe024 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -73,6 +73,9 @@ namespace CNORXZ const XIndexPtr& xptr() const; + /** @copydoc IndexInterface::formatIsTrivial() */ + bool formatIsTrivial() const; + private: XIndexPtr mI; }; diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index 71d8a92..a246e3f 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -189,12 +189,15 @@ namespace CNORXZ template decltype(auto) ifor(const Xpr& xpr, F&& f) const { return THIS().ifor(xpr,std::forward(f)); } + + /** check is format is trivial */ + bool formatIsTrivial() const { return THIS().formatIsTrivial(); } protected: SizeT mPos = 0; /**< the memory position */ private: - friend I; // why not protected???!!! + friend I; // not protected; I should really be something that is derived from IndexInterface // NO DEFAULT CONSTRUCTORS/ASSIGNMENTS! IndexInterface(); diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 84a5020..81aae28 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -448,6 +448,13 @@ namespace CNORXZ return mkIFor<0>(xpr, std::forward(f)); } + template + bool GMIndex::formatIsTrivial() const + { + CXZ_ERROR("IMPLEMENT!!!"); + return true; + } + template GMIndex& GMIndex::operator()(const Sptr>& mi) { diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index f805ad1..aa30d7c 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -93,6 +93,9 @@ namespace CNORXZ auto deepFormat() const; GMIndex& setFormat(const FormatT& bs); + /** @copydoc IndexInterface::formatIsTrivial() */ + bool formatIsTrivial() const; + private: template static constexpr decltype(auto) mkLexFormat(const SPack& ipack, Isq is); diff --git a/src/include/ranges/prange.cc.h b/src/include/ranges/prange.cc.h index fea55ab..f670991 100644 --- a/src/include/ranges/prange.cc.h +++ b/src/include/ranges/prange.cc.h @@ -195,25 +195,6 @@ namespace CNORXZ return mOrig->xpr(mOrig); } - template - template - decltype(auto) PIndex::reformat(const Sptr& ind) const - { - return ind; - } - - template - template - decltype(auto) PIndex::slice(const Sptr& ind) const - { - if(ind != nullptr){ - if(ind->dim() != 0){ - return Sptr>(); - } - } - return std::make_shared>(*this); - } - template template decltype(auto) PIndex::ifor(const Xpr& xpr, F&& f) const @@ -222,6 +203,12 @@ namespace CNORXZ mRangePtr->parts().data(), xpr, std::forward(f)); } + template + bool PIndex::formatIsTrivial() const + { + return mOrig->formatIsTrivial(); + } + template PIndex& PIndex::operator()() { diff --git a/src/include/ranges/prange.h b/src/include/ranges/prange.h index ac3c1c6..419212f 100644 --- a/src/include/ranges/prange.h +++ b/src/include/ranges/prange.h @@ -61,12 +61,6 @@ namespace CNORXZ PIndex& at(const MetaType& metaPos); decltype(auto) xpr(const Sptr>& _this) const; - template - decltype(auto) reformat(const Sptr& ind) const; - - template - decltype(auto) slice(const Sptr& ind) const; - template decltype(auto) ifor(const Xpr& xpr, F&& f) const; @@ -74,6 +68,9 @@ namespace CNORXZ PIndex& operator()(const Sptr& i); const Sptr& orig() const; + /** @copydoc IndexInterface::formatIsTrivial() */ + bool formatIsTrivial() const; + private: Sptr mRangePtr; Sptr mOrig; diff --git a/src/include/ranges/srange.cc.h b/src/include/ranges/srange.cc.h index 481223e..bffa17f 100644 --- a/src/include/ranges/srange.cc.h +++ b/src/include/ranges/srange.cc.h @@ -176,26 +176,7 @@ namespace CNORXZ { return 1; } - /* - template - template - decltype(auto) SIndex::formatFrom(const Index& ind) const - { - return *this; - } - template - template - decltype(auto) SIndex::slice(const Sptr& ind) const - { - if(ind != nullptr){ - if(ind->dim() != 0) { - return Sptr>(); - } - } - return std::make_shared>(*this); - } - */ template template decltype(auto) SIndex::ifor(const Xpr& xpr, F&& f) const @@ -203,6 +184,12 @@ namespace CNORXZ return SFor(this->id(), xpr, std::forward(f)); } + template + bool SIndex::formatIsTrivial() const + { + return true; + } + template decltype(auto) operator*(const Sptr>& a, const Sptr& b) { diff --git a/src/include/ranges/srange.h b/src/include/ranges/srange.h index 230ef44..0ece1f7 100644 --- a/src/include/ranges/srange.h +++ b/src/include/ranges/srange.h @@ -65,6 +65,9 @@ namespace CNORXZ template decltype(auto) ifor(const Xpr& xpr, F&& f) const; + /** @copydoc IndexInterface::formatIsTrivial() */ + bool formatIsTrivial() const; + private: Sptr mRangePtr; const MetaT* mMetaPtr; diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index 9a75837..978610f 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -193,6 +193,12 @@ namespace CNORXZ { return For<0,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward(f)); } + + template + bool UIndex::formatIsTrivial() const + { + return true; + } template decltype(auto) operator*(const Sptr>& a, const Sptr& b) diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index d4ec151..7d5dade 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -70,6 +70,9 @@ namespace CNORXZ template decltype(auto) ifor(const Xpr& xpr, F&& f) const; + /** @copydoc IndexInterface::formatIsTrivial() */ + bool formatIsTrivial() const; + private: Sptr mRangePtr; const MetaT* mMetaPtr; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index a7b6460..c73fc37 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -191,6 +191,12 @@ namespace CNORXZ return DXpr(mI->ifor(xpr, std::forward>(f))); } + template + bool XIndex::formatIsTrivial() const + { + return mI->formatIsTrivial(); + } + template Index& XIndex::get() { diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index fa3b32d..b60f672 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -61,6 +61,7 @@ namespace CNORXZ virtual DXpr ifor(const DXpr& xpr, std::function&& f) const = 0; + virtual bool formatIsTrivial() const = 0; }; //Sptr& operator++(Sptr& i); @@ -114,6 +115,8 @@ namespace CNORXZ virtual DXpr ifor(const DXpr& xpr, std::function&& f) const override final; + virtual bool formatIsTrivial() const override final; + Index& get(); const Index& get() const; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 62bb89b..9a57027 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -84,6 +84,9 @@ namespace CNORXZ const YFormat& lexFormat() const; YIndex& setFormat(const YFormat& bs); + /** @copydoc IndexInterface::formatIsTrivial() */ + bool formatIsTrivial() const; + private: inline Vector mkFormat() const; inline Vector mkLexFormat() const; diff --git a/src/lib/ranges/crange.cc b/src/lib/ranges/crange.cc index 4e95cd3..fc1924a 100644 --- a/src/lib/ranges/crange.cc +++ b/src/lib/ranges/crange.cc @@ -138,6 +138,11 @@ namespace CNORXZ { return 1; } + + bool CIndex::formatIsTrivial() const + { + return true; + } /*============================================================+ | Implementations of member functions of CRangeFactory | diff --git a/src/lib/ranges/dindex.cc b/src/lib/ranges/dindex.cc index 9b059ee..9947249 100644 --- a/src/lib/ranges/dindex.cc +++ b/src/lib/ranges/dindex.cc @@ -181,6 +181,11 @@ namespace CNORXZ { return mI->deepFormat(); } + + bool DIndex::formatIsTrivial() const + { + return true; + } DXpr DIndex::ifor(const DXpr& xpr, std::function&& f) const { diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 029dc60..5f816f3 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -400,7 +400,13 @@ namespace CNORXZ } return o; } - + + bool YIndex::formatIsTrivial() const + { + CXZ_ERROR("IMPLEMENT!!!"); + return true; + } + const YFormat& YIndex::format() const { return mFormat;