finish mrange/mindex (unchecked)

This commit is contained in:
Christian Zimmermann 2022-11-12 03:14:07 +01:00
parent 113a0e7209
commit 4e2244db79
2 changed files with 148 additions and 53 deletions

View file

@ -81,27 +81,35 @@ namespace CNORXZ
* MIndex * * MIndex *
**************/ **************/
template <class... Indices>
MIndex<Indices...>::MIndex(const MIndex& i) :
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(i.pos()),
mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})),
mBlockSizes(mkBlockSizes(), Isqr<0,NI>{}),
mRange(i.range())
{}
template <class... Indices>
MIndex& MIndex<Indices...>::operator=(const MIndex& i)
{
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>::operator=(i);
mIPack = mkIPack(IB::mPos, Isqr<0,NI>{});
mBlockSizes(mkBlockSizes(), Isqr<0,NI>{});
mRange = i.range();
return *this;
}
template <class... Indices> template <class... Indices>
template <class MRange> template <class MRange>
MIndex<Indices...>::MIndex(const Sptr<MRange>& range, SizeT pos) : MIndex<Indices...>::MIndex(const Sptr<MRange>& range, SizeT pos) :
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(0), IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(0),
mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})), mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})),
mBlockSizes(mkBlockSizes(IB::mPos), Isqr<0,NI>{}), mBlockSizes(mkBlockSizes(), Isqr<0,NI>{}),
mRange(range), mRange(range),
{ {
(*this) = pos; (*this) = pos;
} }
template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator()(const Sptr<MIndex>& mi)
{
mIPack = mi.mIPack;
IB::mPos = iter<0,NI>
( [&](auto i) { return std::get<i>(mIPack)*std::get<i>(mBlockSizes); },
[](const auto&... xs) { return (xs + ...); });
return *this;
}
template <class... Indices> template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator=(SizeT pos) MIndex<Indices...>& MIndex<Indices...>::operator=(SizeT pos)
{ {
@ -130,6 +138,93 @@ namespace CNORXZ
return *this; return *this;
} }
template <class... Indices>
MIndex<Indices...> MIndex<Indices...>::operator+(Int n) const
{
MIndex o(*this);
return o += n;
}
template <class... Indices>
MIndex<Indices...> MIndex<Indices...>::operator-(Int n) const
{
MIndex o(*this);
return o -= n;
}
template <class... Indices>
MIndex& MIndex<Indices...>::operator+=(Int n)
{
if(-n > IB::mPos){
(*this) = 0;
}
const SizeT p = IB::mPos + n;
if(p > max()){
(*this) = max();
}
(*this) = p;
return *this;
}
template <class... Indices>
MIndex& MIndex<Indices...>::operator-=(Int n)
{
if(n > IB::mPos){
(*this) = 0;
}
const SizeT p = IB::mPos + n;
if(p > max()){
(*this) = max();
}
(*this) = p;
return *this;
}
template <class... Indices>
SizeT MIndex<Indices...>::max() const
{
return mRange->size();
}
template <class... Indices>
IndexId<0> MIndex<Indices...>::id() const
{
return IndexId<0>(this->ptrId());
}
template <class... Indices>
MetaType MIndex<Indices...>::operator*() const
{
return meta();
}
template <class... Indices>
MetaType MIndex<Indices...>::operator->() const
{
return meta();
}
template <class... Indices>
SizeT MIndex<Indices...>::dim() const
{
return NI;
}
template <class... Indices>
Sptr<RangeType> MIndex<Indices...>::range() const
{
return mRange;
}
template <class... Indices>
template <SizeT I>
decltype(auto) MIndex<Indices...>::stepSize(const IndexId<I>& id) const;
{
return iter<0,NI>
( [&](auto i) { return std::get<i>(mIPack)->stepSize(id) * std::get<i>(mBlockSize); },
[](const auto&... ss) { return ( ss + ... ); });
}
template <class... Indices> template <class... Indices>
String MIndex<Indices...>::stringMeta() const String MIndex<Indices...>::stringMeta() const
{ {
@ -160,28 +255,6 @@ namespace CNORXZ
return *this; return *this;
} }
template <class... Indices>
SizeT MIndex<Indices...>::dim()
{
return NI;
}
template <class... Indices>
Sptr<typename MIndex<Indices...>::RangeType>
MIndex<Indices...>::range()
{
return std::dynamic_pointer_cast<RangeType>( mRangePtr );
}
template <class... Indices>
template <SizeT I>
decltype(auto) MIndex<Indices...>::stepSize(const IndexId<I>& id) const;
{
return iter<0,NI>
( [&](auto i) { return std::get<i>(mIPack)->stepSize(id) * std::get<i>(mBlockSize); },
[](const auto&... ss) { return ( ss + ... ); });
}
template <class... Indices> template <class... Indices>
template <class Xpr, class F> template <class Xpr, class F>
constexpr decltype(auto) MIndex<Indices...>::ifor(const Xpr& xpr, F&& f) const constexpr decltype(auto) MIndex<Indices...>::ifor(const Xpr& xpr, F&& f) const
@ -189,6 +262,29 @@ namespace CNORXZ
return mkIFor<0>(xpr, f); return mkIFor<0>(xpr, f);
} }
template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator()(const Sptr<MIndex>& mi)
{
mIPack = mi.mIPack;
IB::mPos = iter<0,NI>
( [&](auto i) { return std::get<i>(mIPack)*std::get<i>(mBlockSizes); },
[](const auto&... xs) { return (xs + ...); });
return *this;
}
template <class... Indices>
const IndexPack& pack() const
{
return mIPack;
}
template <class... Indices>
const auto& blockSizes() const
{
return mBlockSizes;
}
/********************* /*********************
* MRangeFactory * * MRangeFactory *
*********************/ *********************/

View file

@ -26,19 +26,14 @@ namespace CNORXZ
// NO DEFAULT HERE !!! // NO DEFAULT HERE !!!
// ( have to assign sub-indices (ptr!) correctly ) // ( have to assign sub-indices (ptr!) correctly )
MIndex() = default;
MIndex(const MIndex& i); MIndex(const MIndex& i);
MIndex(MIndex&& i); MIndex(MIndex&& i);
MIndex& operator=(const MIndex& i); MIndex& operator=(const MIndex& i) = default;
MIndex& operator=(MIndex&& i); MIndex& operator=(MIndex&& i) = default;
MIndex(const RangePtr& range, SizeT pos = 0); MIndex(const RangePtr& range, SizeT pos = 0);
// replace sub-index instances; only use if you know what you are doing!
MIndex& operator()(const Sptr<MIndex>& mi);
const IndexPack& pack() const { return mIPack; }
const auto& getBlockSizes() const { return mBlockSizes; }
MIndex& operator=(SizeT pos); MIndex& operator=(SizeT pos);
MIndex& operator++(); MIndex& operator++();
MIndex& operator--(); MIndex& operator--();
@ -48,13 +43,13 @@ namespace CNORXZ
MIndex& operator-=(Int n); MIndex& operator-=(Int n);
SizeT max() const; SizeT max() const;
decltype(auto) id() const; IndexId<0> id() const;
SizeT operator*() const; MetaType operator*() const;
SizeT operator->() const; MetaType operator->() const;
SizeT dim(); SizeT dim() const
Sptr<RangeType> range(); Sptr<RangeType> range() const;
template <SizeT I> template <SizeT I>
decltype(auto) stepSize(const IndexId<I>& id) const; decltype(auto) stepSize(const IndexId<I>& id) const;
@ -66,9 +61,13 @@ namespace CNORXZ
template <class Xpr, class F> template <class Xpr, class F>
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
private: // replace sub-index instances; only use if you know what you are doing!
MIndex() = default; MIndex& operator()(const Sptr<MIndex>& mi);
const IndexPack& pack() const;
const auto& blockSizes() const;
private:
IndexPack mIPack; IndexPack mIPack;
typedef decltype(mkBlockSizes(Isqr<0,NI-1>{})) BlockTuple; typedef decltype(mkBlockSizes(Isqr<0,NI-1>{})) BlockTuple;
BlockTuple mBlockSizes; BlockTuple mBlockSizes;