more doxy comments + WIP: index member function formatIsTrivial
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Christian Zimmermann 2023-11-05 22:20:12 +01:00
parent 7487929bfc
commit be44541135
23 changed files with 332 additions and 88 deletions

View file

@ -18,9 +18,9 @@
namespace CNORXZ
{
/******************
* CArrayBase *
******************/
/*=======================================================+
| Implementations for CArrayBase member functions |
+=======================================================*/
template <typename T>
CArrayBase<T>::CArrayBase(const RangePtr& range) :
@ -31,6 +31,11 @@ namespace CNORXZ
template <typename I, typename M>
const T& CArrayBase<T>::operator[](const IndexInterface<I,M>& 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 <class Index>
COpRoot<T,Index> CArrayBase<T>::operator()(const Sptr<Index>& 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 <typename T>
template <class Acc>
@ -185,9 +197,9 @@ namespace CNORXZ
}
}
/*****************
* ArrayBase *
*****************/
/*======================================================+
| Implementations for ArrayBase member functions |
+======================================================*/
template <typename T>
ArrayBase<T>::ArrayBase(const RangePtr& range) :
@ -287,9 +299,9 @@ namespace CNORXZ
return oproot(*this, i);
}
/*****************************
* ArrayBase (protected) *
*****************************/
/*================================================================+
| Implementations for protected ArrayBase member functions |
+================================================================*/
template <typename T>
template <class Acc>

View file

@ -24,75 +24,175 @@
namespace CNORXZ
{
/** ****
Abstract container base class
only read access to the data
@tparam T data type
*/
template <typename T>
class CArrayBase
{
public:
typedef AIndex<T> const_iterator;
typedef AIndex<T> 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 <typename I, typename M>
const T& operator[](const IndexInterface<I,M>& i) const;
/** const data element access
performs compatibility checks
@tparam I index type
@tparam M meta data type
@param i index
*/
template <typename I, typename M>
const T& at(const IndexInterface<I,M>& i) const;
/** const data element access
@tparam I index type
@tparam M meta data type
@param pack static index pack
*/
template <class... Indices>
const T& operator[](const SPack<Indices...>& pack) const;
/** const data element access
performs compatibility checks
@tparam I index type
@tparam M meta data type
@param i static index pack
*/
template <class... Indices>
const T& at(const SPack<Indices...>& 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 <typename I, typename M>
Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& begin,
const IndexInterface<I,M>& end) const;
/** create operation on this container
@tparam Index type of operation index
@param i operation index
*/
template <class Index>
COpRoot<T,Index> operator()(const Sptr<Index>& i) const;
/** create operation on this container
@tparam Indices types of operation indices
@param pack pack of operation index
*/
template <class... Indices>
inline decltype(auto) operator()(const SPack<Indices...>& 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 <class Acc>
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 <class Acc>
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 <class Acc>
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 <typename T>
class ArrayBase : public CArrayBase<T>
{
public:
typedef CArrayBase<T> CAB;
typedef typename CAB::const_iterator const_iterator;
typedef BIndex<T> iterator;
typedef typename CAB::const_iterator const_iterator; /**< constant iterator type */
typedef BIndex<T> 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 <typename I, typename M>
T& operator[](const IndexInterface<I,M>& i);
/** @copydoc CArrayBase::at()
*/
template <typename I, typename M>
T& at(const IndexInterface<I,M>& i);
/** @copydoc CArrayBase::operator[]()
*/
template <class... Indices>
T& operator[](const SPack<Indices...>& pack);
/** @copydoc CArrayBase::at()
*/
template <class... Indices>
T& at(const SPack<Indices...>& pack);
/** @copydoc CArrayBase::operator[]()
*/
T& operator[](const DPack& pack);
/** @copydoc CArrayBase::at()
*/
T& at(const DPack& pack);
/** @copydoc CArrayBase::operator()()
*/
template <class Index>
OpRoot<T,Index> operator()(const Sptr<Index>& i);
/** @copydoc CArrayBase::operator()()
*/
template <class... Indices>
inline decltype(auto) operator()(const SPack<Indices...>& pack);
/** @copydoc CArrayBase::operator()()
*/
inline decltype(auto) operator()(const DPack& pack);
/** @copydoc CArrayBase::sl()
*/
template <typename I, typename M>
Sptr<ArrayBase<T>> sl(const IndexInterface<I,M>& begin,
const IndexInterface<I,M>& 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 <class Acc>
iterator itLex(const Acc& acc);
/** @copydoc CArrayBase::itLexSave()
*/
template <class Acc>
iterator itLexSave(const Acc& acc);
};

View file

@ -17,9 +17,9 @@
namespace CNORXZ
{
/****************
* MArray *
***************/
/*=======================================================+
| Implementation of MArray public member functions |
+=======================================================*/
template <typename T>
MArray<T>::MArray(const RangePtr& range) :
@ -92,6 +92,15 @@ namespace CNORXZ
return false;
}
/*==========================================================+
| Implementation of MArray protected member functions |
+==========================================================*/
template <typename T>
bool MArray<T>::formatIsTrivial() const
{
return true;
}
}
#endif

View file

@ -42,6 +42,9 @@ namespace CNORXZ
virtual bool isView() const override;
SERIALIZATION_FUNCTIONS;
protected:
virtual bool formatIsTrivial() const override final;
private:
Vector<T> mCont;

View file

@ -17,9 +17,9 @@
namespace CNORXZ
{
/**************
* CSlice *
**************/
/*========================================================+
| Implementation of public CSlice member functions |
+========================================================*/
template <typename T>
CSlice<T>::CSlice(const RangePtr& range, const CArrayBase<T>* parent,
@ -54,9 +54,19 @@ namespace CNORXZ
return true;
}
/*************
* Slice *
*************/
/*===========================================================+
| Implementation of protected CSlice member functions |
+===========================================================*/
template <typename T>
bool CSlice<T>::formatIsTrivial() const
{
return cbegin().formatIsTrivial();
}
/*=======================================================+
| Implementation of public Slice member functions |
+=======================================================*/
template <typename T>
Slice<T>::Slice(const RangePtr& range, ArrayBase<T>* parent,
@ -96,6 +106,16 @@ namespace CNORXZ
{
return true;
}
/*==========================================================+
| Implementation of protected Slice member functions |
+==========================================================*/
template <typename T>
bool Slice<T>::formatIsTrivial() const
{
return cbegin().formatIsTrivial();
}
}
#endif

View file

@ -18,6 +18,12 @@
namespace CNORXZ
{
/** ****
constant and possibly partial view on the data
of another container
@tparam T data type
*/
template <typename T>
class CSlice : public CArrayBase<T>
{
@ -25,13 +31,15 @@ namespace CNORXZ
typedef CArrayBase<T> AB;
typedef typename AB::const_iterator const_iterator;
protected:
const CArrayBase<T>* 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<T>* 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<T>* 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 <typename T>
class Slice : public ArrayBase<T>
{
public:
typedef CArrayBase<T> AB;
//typedef CSlice<T> CS;
typedef typename AB::const_iterator const_iterator;
private:
ArrayBase<T>* 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<T>* 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<T>* mParent = nullptr;
YFormat mBlockSizes;
SizeT mOff = 0;
};
}

View file

@ -111,6 +111,9 @@ namespace CNORXZ
template <class Xpr, class F = NoF>
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
/** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const;
private:
Sptr<RangeType> mRangePtr;
};

View file

@ -73,6 +73,9 @@ namespace CNORXZ
const XIndexPtr& xptr() const;
/** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const;
private:
XIndexPtr mI;
};

View file

@ -189,12 +189,15 @@ namespace CNORXZ
template <class Xpr, class F = NoF>
decltype(auto) ifor(const Xpr& xpr, F&& f) const
{ return THIS().ifor(xpr,std::forward<F>(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();

View file

@ -448,6 +448,13 @@ namespace CNORXZ
return mkIFor<0>(xpr, std::forward<F>(f));
}
template <class FormatT, class... Indices>
bool GMIndex<FormatT,Indices...>::formatIsTrivial() const
{
CXZ_ERROR("IMPLEMENT!!!");
return true;
}
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator()(const Sptr<MIndex<Indices...>>& mi)
{

View file

@ -93,6 +93,9 @@ namespace CNORXZ
auto deepFormat() const;
GMIndex& setFormat(const FormatT& bs);
/** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const;
private:
template <SizeT... Is>
static constexpr decltype(auto) mkLexFormat(const SPack<Indices...>& ipack, Isq<Is...> is);

View file

@ -195,25 +195,6 @@ namespace CNORXZ
return mOrig->xpr(mOrig);
}
template <class IndexT>
template <class I>
decltype(auto) PIndex<IndexT>::reformat(const Sptr<I>& ind) const
{
return ind;
}
template <class IndexT>
template <class I>
decltype(auto) PIndex<IndexT>::slice(const Sptr<I>& ind) const
{
if(ind != nullptr){
if(ind->dim() != 0){
return Sptr<PIndex<IndexT>>();
}
}
return std::make_shared<PIndex<IndexT>>(*this);
}
template <class IndexT>
template <class Xpr, class F>
decltype(auto) PIndex<IndexT>::ifor(const Xpr& xpr, F&& f) const
@ -222,6 +203,12 @@ namespace CNORXZ
mRangePtr->parts().data(), xpr, std::forward<F>(f));
}
template <class IndexT>
bool PIndex<IndexT>::formatIsTrivial() const
{
return mOrig->formatIsTrivial();
}
template <class IndexT>
PIndex<IndexT>& PIndex<IndexT>::operator()()
{

View file

@ -61,12 +61,6 @@ namespace CNORXZ
PIndex& at(const MetaType& metaPos);
decltype(auto) xpr(const Sptr<PIndex<IndexT>>& _this) const;
template <class I>
decltype(auto) reformat(const Sptr<I>& ind) const;
template <class I>
decltype(auto) slice(const Sptr<I>& ind) const;
template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
@ -74,6 +68,9 @@ namespace CNORXZ
PIndex& operator()(const Sptr<IndexT>& i);
const Sptr<IndexT>& orig() const;
/** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const;
private:
Sptr<RangeType> mRangePtr;
Sptr<IndexT> mOrig;

View file

@ -176,26 +176,7 @@ namespace CNORXZ
{
return 1;
}
/*
template <typename MetaT, SizeT S>
template <class Index>
decltype(auto) SIndex<MetaT,S>::formatFrom(const Index& ind) const
{
return *this;
}
template <typename MetaT, SizeT S>
template <class Index>
decltype(auto) SIndex<MetaT,S>::slice(const Sptr<Index>& ind) const
{
if(ind != nullptr){
if(ind->dim() != 0) {
return Sptr<SIndex<MetaType,S>>();
}
}
return std::make_shared<SIndex<MetaType,S>>(*this);
}
*/
template <typename MetaT, SizeT S>
template <class Xpr, class F>
decltype(auto) SIndex<MetaT,S>::ifor(const Xpr& xpr, F&& f) const
@ -203,6 +184,12 @@ namespace CNORXZ
return SFor<S,0,Xpr,F>(this->id(), xpr, std::forward<F>(f));
}
template <typename MetaT, SizeT S>
bool SIndex<MetaT,S>::formatIsTrivial() const
{
return true;
}
template <typename MetaType, SizeT S, class I1>
decltype(auto) operator*(const Sptr<SIndex<MetaType,S>>& a, const Sptr<I1>& b)
{

View file

@ -65,6 +65,9 @@ namespace CNORXZ
template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
/** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const;
private:
Sptr<RangeType> mRangePtr;
const MetaT* mMetaPtr;

View file

@ -193,6 +193,12 @@ namespace CNORXZ
{
return For<0,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward<F>(f));
}
template <typename MetaT>
bool UIndex<MetaT>::formatIsTrivial() const
{
return true;
}
template <typename MetaT, class I1>
decltype(auto) operator*(const Sptr<UIndex<MetaT>>& a, const Sptr<I1>& b)

View file

@ -70,6 +70,9 @@ namespace CNORXZ
template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
/** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const;
private:
Sptr<RangeType> mRangePtr;
const MetaT* mMetaPtr;

View file

@ -191,6 +191,12 @@ namespace CNORXZ
return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)));
}
template <class Index, typename Meta>
bool XIndex<Index,Meta>::formatIsTrivial() const
{
return mI->formatIsTrivial();
}
template <class Index, typename Meta>
Index& XIndex<Index,Meta>::get()
{

View file

@ -61,6 +61,7 @@ namespace CNORXZ
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const = 0;
virtual bool formatIsTrivial() const = 0;
};
//Sptr<XIndexBase>& operator++(Sptr<XIndexBase>& i);
@ -114,6 +115,8 @@ namespace CNORXZ
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const override final;
virtual bool formatIsTrivial() const override final;
Index& get();
const Index& get() const;

View file

@ -84,6 +84,9 @@ namespace CNORXZ
const YFormat& lexFormat() const;
YIndex& setFormat(const YFormat& bs);
/** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const;
private:
inline Vector<SizeT> mkFormat() const;
inline Vector<SizeT> mkLexFormat() const;

View file

@ -138,6 +138,11 @@ namespace CNORXZ
{
return 1;
}
bool CIndex::formatIsTrivial() const
{
return true;
}
/*============================================================+
| Implementations of member functions of CRangeFactory |

View file

@ -181,6 +181,11 @@ namespace CNORXZ
{
return mI->deepFormat();
}
bool DIndex::formatIsTrivial() const
{
return true;
}
DXpr<SizeT> DIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
{

View file

@ -400,7 +400,13 @@ namespace CNORXZ
}
return o;
}
bool YIndex::formatIsTrivial() const
{
CXZ_ERROR("IMPLEMENT!!!");
return true;
}
const YFormat& YIndex::format() const
{
return mFormat;