prange comments
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Christian Zimmermann 2024-01-17 22:57:18 +01:00
parent ac352206c7
commit a5031d80b1
2 changed files with 112 additions and 16 deletions

View file

@ -123,8 +123,7 @@ namespace CNORXZ
Sptr<RangeType> mRangePtr; Sptr<RangeType> mRangePtr;
}; };
/** make index pack of a CIndex and another index. /** Make index pack of a CIndex and another index.
@tparam type of the second index.
@param a pointer to CIndex. @param a pointer to CIndex.
@param b pointer to another index. @param b pointer to another index.
*/ */

View file

@ -2,10 +2,9 @@
/** /**
@file include/ranges/prange.h @file include/ranges/prange.h
@brief ... @brief PRange, PRangeFactory and PIndex declaration.
Copyright (c) 2024 Christian Zimmermann. All rights reserved.
Copyright (c) 2022 Christian Zimmermann. All rights reserved.
Mail: chizeta@f3l.de Mail: chizeta@f3l.de
**/ **/
@ -20,7 +19,10 @@
namespace CNORXZ namespace CNORXZ
{ {
/** ****
Index specific for PRange.
@tparam IndexT Full index type.
*/
template <class IndexT> template <class IndexT>
class PIndex : public IndexInterface<PIndex<IndexT>,typename IndexT::MetaType> class PIndex : public IndexInterface<PIndex<IndexT>,typename IndexT::MetaType>
{ {
@ -30,51 +32,105 @@ namespace CNORXZ
typedef PRange<typename IndexT::RangeType> RangeType; typedef PRange<typename IndexT::RangeType> RangeType;
typedef typename IndexT::MetaType MetaType; typedef typename IndexT::MetaType MetaType;
/** Constructor.
@param range Range to define index on.
@param pos Initial lexicographic position (default = 0).
*/
PIndex(const RangePtr& range, SizeT pos = 0); PIndex(const RangePtr& range, SizeT pos = 0);
/** @copydoc IndexInterface::operator=(SizeT) */
PIndex& operator=(SizeT lexpos); PIndex& operator=(SizeT lexpos);
/** @copydoc IndexInterface::operator++() */
PIndex& operator++(); PIndex& operator++();
/** @copydoc IndexInterface::operator--() */
PIndex& operator--(); PIndex& operator--();
/** @copydoc IndexInterface::operator+() */
PIndex operator+(Int n) const; PIndex operator+(Int n) const;
/** @copydoc IndexInterface::operator-() */
PIndex operator-(Int n) const; PIndex operator-(Int n) const;
/** @copydoc IndexInterface::operator-(PIndex) */
SizeT operator-(const PIndex& i) const; SizeT operator-(const PIndex& i) const;
/** @copydoc IndexInterface::operator+=() */
PIndex& operator+=(Int n); PIndex& operator+=(Int n);
/** @copydoc IndexInterface::operator-=() */
PIndex& operator-=(Int n); PIndex& operator-=(Int n);
/** @copydoc IndexInterface::lex() */
SizeT lex() const; SizeT lex() const;
/** @copydoc IndexInterface::pmax() */
UPos pmax() const; UPos pmax() const;
/** @copydoc IndexInterface::lmax() */
UPos lmax() const; UPos lmax() const;
/** @copydoc IndexInterface::id() */
IndexId<0> id() const; IndexId<0> id() const;
/** @copydoc IndexInterface::operator*() */
decltype(auto) operator*() const; decltype(auto) operator*() const;
/** @copydoc IndexInterface::dim() */
SizeT dim() const; SizeT dim() const;
/** @copydoc IndexInterface::range() */
Sptr<RangeType> range() const; Sptr<RangeType> range() const;
/** @copydoc IndexInterface::stepSize() */
template <SizeT I> template <SizeT I>
UPos stepSize(const IndexId<I>& id) const; UPos stepSize(const IndexId<I>& id) const;
/** @copydoc IndexInterface::stringMeta() */
String stringMeta() const;
/** @copydoc IndexInterface::meta() */
decltype(auto) meta() const;
/** @copydoc IndexInterface::at() */
PIndex& at(const MetaType& metaPos);
/** @copydoc IndexInterface::prange() */
RangePtr prange(const PIndex<IndexT>& last) const; RangePtr prange(const PIndex<IndexT>& last) const;
/** @copydoc IndexInterface::deepFormat() */
decltype(auto) deepFormat() const; decltype(auto) deepFormat() const;
/** @copydoc IndexInterface::deepMax() */
decltype(auto) deepMax() const; decltype(auto) deepMax() const;
/** @copydoc IndexInterface::reformat() */ /** @copydoc IndexInterface::reformat() */
PIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s); PIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
String stringMeta() const; /** @copydoc IndexInterface::ifor() */
decltype(auto) meta() const;
PIndex& at(const MetaType& metaPos);
decltype(auto) xpr(const Sptr<PIndex<IndexT>>& _this) const;
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const; decltype(auto) ifor(const Xpr& xpr, F&& f) const;
PIndex& operator()();
PIndex& operator()(const Sptr<IndexT>& i);
const Sptr<IndexT>& orig() const;
/** @copydoc IndexInterface::formatIsTrivial() */ /** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const; bool formatIsTrivial() const;
/** @copydoc IndexInterface::xpr() */
decltype(auto) xpr(const Sptr<PIndex<IndexT>>& _this) const;
/** Replace instance of index on full range and update current position accordingly.
@param i New index instance.
*/
PIndex& operator()(const Sptr<IndexT>& i);
/** Update current index position according to the internal index on the full range. */
PIndex& operator()();
/** Get original index.
@return Index corresponding to original range and current position.
*/
const Sptr<IndexT>& orig() const;
private: private:
Sptr<RangeType> mRangePtr; Sptr<RangeType> mRangePtr;
Sptr<IndexT> mOrig; Sptr<IndexT> mOrig;
@ -82,14 +138,31 @@ namespace CNORXZ
void mkPos(); void mkPos();
}; };
/** Make index pack of a PIndex and another index.
@param a pointer to PIndex.
@param b pointer to another index.
*/
template <class I, class I1> template <class I, class I1>
decltype(auto) operator*(const Sptr<PIndex<I>>& a, const Sptr<I1>& b); decltype(auto) operator*(const Sptr<PIndex<I>>& a, const Sptr<I1>& b);
/** ****
Specific factory for PRange.
*/
template <class RangeT> template <class RangeT>
class PRangeFactory : public RangeFactoryBase class PRangeFactory : public RangeFactoryBase
{ {
public: public:
/** Construct and setup factory.
@param range Full range (explicit type) the constructed range is part of.
@param _parts Integer vector indicating the parts w.r.t. input range to be covered by the PRange.
*/
PRangeFactory(const Sptr<RangeT>& range, const Vector<SizeT>& _parts); PRangeFactory(const Sptr<RangeT>& range, const Vector<SizeT>& _parts);
/** Construct and setup factory.
@param range Full range the constructed range is part of.
@param _parts Integer vector indicating the parts of the full range.
*/
PRangeFactory(const RangePtr& range, const Vector<SizeT>& _parts); PRangeFactory(const RangePtr& range, const Vector<SizeT>& _parts);
private: private:
@ -99,7 +172,14 @@ namespace CNORXZ
Sptr<RangeT> mRange; Sptr<RangeT> mRange;
Vector<SizeT> mParts; Vector<SizeT> mParts;
}; };
/** ****
Partial Range.
Ranges of these kind represent a part of a given range (full range).
Using a mathematical nomenclature, this would be called a "sub-range".
(The prefix "sub", as well as the letter "S" are, however, already extensively
used in other contexts.)
*/
template <class RangeT> template <class RangeT>
class PRange : public RangeInterface<PRange<RangeT>> class PRange : public RangeInterface<PRange<RangeT>>
{ {
@ -117,8 +197,20 @@ namespace CNORXZ
virtual const TypeInfo& metaType() const override final; virtual const TypeInfo& metaType() const override final;
virtual RangePtr extend(const RangePtr& r) const override final; virtual RangePtr extend(const RangePtr& r) const override final;
/** Get the full range.
@return Pointer to the full range.
*/
Sptr<RangeT> orig() const; Sptr<RangeT> orig() const;
/** Get the parts.
@return Integer vector indicating the parts contained by the PRange w.r.t. the full range.
*/
const Vector<SizeT>& parts() const; const Vector<SizeT>& parts() const;
/** Create a new range of the type of the full range but containing only
the parts covered by the PRange.
@return The created range.
*/
RangePtr derive() const; RangePtr derive() const;
private: private:
@ -133,6 +225,11 @@ namespace CNORXZ
Vector<SizeT> mParts; Vector<SizeT> mParts;
}; };
/** Create a PRange.
Internally calls PRangeFactory.
@param range Range to create a PRange on.
@param parts Integer vector indicating the parts w.r.t. input range to be covered by the PRange.
*/
template <class RangeT> template <class RangeT>
RangePtr prange(const Sptr<RangeT>& range, const Vector<SizeT>& parts); RangePtr prange(const Sptr<RangeT>& range, const Vector<SizeT>& parts);