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 *
**************/
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 MRange>
MIndex<Indices...>::MIndex(const Sptr<MRange>& range, SizeT pos) :
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(0),
mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})),
mBlockSizes(mkBlockSizes(IB::mPos), Isqr<0,NI>{}),
mBlockSizes(mkBlockSizes(), Isqr<0,NI>{}),
mRange(range),
{
(*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>
MIndex<Indices...>& MIndex<Indices...>::operator=(SizeT pos)
{
@ -130,6 +138,93 @@ namespace CNORXZ
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>
String MIndex<Indices...>::stringMeta() const
{
@ -160,34 +255,35 @@ namespace CNORXZ
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 Xpr, class F>
constexpr decltype(auto) MIndex<Indices...>::ifor(const Xpr& xpr, F&& f) const
{
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 *

View file

@ -26,19 +26,14 @@ namespace CNORXZ
// NO DEFAULT HERE !!!
// ( have to assign sub-indices (ptr!) correctly )
MIndex() = default;
MIndex(const MIndex& i);
MIndex(MIndex&& i);
MIndex& operator=(const MIndex& i);
MIndex& operator=(MIndex&& i);
MIndex& operator=(const MIndex& i) = default;
MIndex& operator=(MIndex&& i) = default;
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++();
MIndex& operator--();
@ -46,29 +41,33 @@ namespace CNORXZ
MIndex operator-(Int n) const;
MIndex& operator+=(Int n);
MIndex& operator-=(Int n);
SizeT max() const;
decltype(auto) id() const;
SizeT operator*() const;
SizeT operator->() const;
SizeT dim();
Sptr<RangeType> range();
SizeT max() const;
IndexId<0> id() const;
MetaType operator*() const;
MetaType operator->() const;
SizeT dim() const
Sptr<RangeType> range() const;
template <SizeT I>
decltype(auto) stepSize(const IndexId<I>& id) const;
String stringMeta() const;
MetaType meta() const;
MIndex& at(const MetaType& metaPos);
template <class Xpr, class F>
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
// replace sub-index instances; only use if you know what you are doing!
MIndex& operator()(const Sptr<MIndex>& mi);
const IndexPack& pack() const;
const auto& blockSizes() const;
private:
MIndex() = default;
IndexPack mIPack;
typedef decltype(mkBlockSizes(Isqr<0,NI-1>{})) BlockTuple;
BlockTuple mBlockSizes;