mindex: replace block sizes by format

This commit is contained in:
Christian Zimmermann 2023-01-03 18:11:45 +01:00
parent 53aa87c362
commit 8787ec7590
9 changed files with 212 additions and 316 deletions

View file

@ -46,17 +46,14 @@ namespace CNORXZ
RangePtr range() const;
UPos stepSize(const IndexId<0>& id) const;
Vector<XIndexPtr> pack() const;
Vector<SizeT> blockSizes() const;
DIndex& setBlockSizes(const Vector<SizeT>& bs);
//Vector<XIndexPtr> pack() const;
//Vector<SizeT> format() const;
//DIndex& setBlockSizes(const Vector<SizeT>& bs);
String stringMeta() const;
DType meta() const;
DIndex& at(const DType& meta);
Sptr<DIndex> format(const Sptr<DIndex>& ind) const;
Sptr<DIndex> slice(const Sptr<DIndex>& ind) const;
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;
const XIndexPtr& xptr() const;

View file

@ -54,11 +54,11 @@ namespace CNORXZ
decltype(auto) meta() const { return THIS().meta(); }
I& at(const MetaType& meta) { return THIS().at(meta); }
template <class Index>
decltype(auto) format(const Sptr<Index>& ind) const { return THIS().format(ind); }
//template <class Index>
//decltype(auto) format(const Sptr<Index>& ind) const { return THIS().format(ind); }
template <class Index>
decltype(auto) slice(const Sptr<Index>& ind) const { return THIS().slice(ind); }
//template <class Index>
//decltype(auto) slice(const Sptr<Index>& ind) const { return THIS().slice(ind); }
template <class Xpr, class F = NoF>
decltype(auto) ifor(const Xpr& xpr, F&& f) const

View file

@ -59,6 +59,11 @@ namespace CNORXZ
mB(b)
{}
template <class... PosT>
constexpr GMFormat<PosT...>::GMFormat(Tuple<PosT...>&& b) :
mB(std::forward<Tuple<PosT...>>(b))
{}
template <class... PosT>
template <class FormatT>
constexpr GMFormat<PosT...>::GMFormat(const FormatT& f)
@ -93,6 +98,12 @@ namespace CNORXZ
return get(i);
}
template <class... PosT>
constexpr decltype(auto) gmformat(const PosT&... ps)
{
return GMFormat(std::move(std::make_tuple(ps...)));
}
/***************
* YFormat *
***************/

View file

@ -41,6 +41,7 @@ namespace CNORXZ
public:
SP_DEFAULT_MEMBERS(constexpr,GMFormat);
explicit constexpr GMFormat(const Tuple<PosT...>& b);
explicit constexpr GMFormat(Tuple<PosT...>&& b);
template <class FormatT>
constexpr GMFormat(const FormatT& f);
@ -58,6 +59,9 @@ namespace CNORXZ
Tuple<PosT...> mB;
};
template <class... PosT>
constexpr decltype(auto) gmformat(const PosT&... ps);
template <class... PosT> struct is_static_format<GMFormat<PosT...>> { CXZ_CVAL_TRUE; };
class YFormat

View file

@ -10,9 +10,9 @@ namespace CNORXZ
* GMIndex (private) *
************************/
template <class BlockType, class... Indices>
template <class FormatT, class... Indices>
template <SizeT... Is>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::mkIPack(Isq<Is...> is) const
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkIPack(Isq<Is...> is) const
{
static_assert(sizeof...(Is) == NI,
"sequence sioze does not match number of indices");
@ -21,36 +21,36 @@ namespace CNORXZ
return std::make_tuple( std::make_shared<Indices>( mRange->sub(Is) )... );
}
template <class BlockType, class... Indices>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::mkLMax(const IndexPack& ipack)
template <class FormatT, class... Indices>
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkLMax(const IndexPack& ipack)
{
return iter<0,NI>( [&](auto i) { return std::get<i>(ipack)->lmax(); },
[](auto... e) { return (e * ...); });
}
template <class BlockType, class... Indices>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::mkPMax(const IndexPack& ipack, const BlockType& blockSizes)
template <class FormatT, class... Indices>
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkPMax(const IndexPack& ipack, const FormatT& format)
{
if constexpr(std::is_same<BlockType,None>::value){
if constexpr(std::is_same<FormatT,None>::value){
return mkLMax(ipack);
}
else {
return iter<0,NI>
( [&](auto i)
{ return (std::get<i>(ipack)->pmax() - SPos<1>()) * std::get<i>(blockSizes); },
{ return (std::get<i>(ipack)->pmax() - SPos<1>()) * format[i]; },
[](auto... e) { return (e + ...); }) + SPos<1>();
}
}
template <class BlockType, class... Indices>
inline void GMIndex<BlockType,Indices...>::mkPos()
template <class FormatT, class... Indices>
inline void GMIndex<FormatT,Indices...>::mkPos()
{
mLex = iter<0,NI>
([&](auto i) { return std::get<i>(mIPack)->lex() * std::get<i>(mLexBlockSizes).val(); },
([&](auto i) { return std::get<i>(mIPack)->lex() * mLexFormat[i].val(); },
[](const auto&... e) { return (e + ...); });
if constexpr(not std::is_same<BlockType,None>::value){
if constexpr(not std::is_same<FormatT,None>::value){
IB::mPos = iter<0,NI>
([&](auto i) { return std::get<i>(mIPack)->pos() * std::get<i>(mBlockSizes).val(); },
([&](auto i) { return std::get<i>(mIPack)->pos() * mFormat[i].val(); },
[](const auto&... e) { return (e + ...); });
}
else {
@ -58,66 +58,68 @@ namespace CNORXZ
}
}
template <class BlockType, class... Indices>
template <class FormatT, class... Indices>
template <SizeT... Is>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::mkLexBlockSizes(const IndexPack& ipack, Isq<Is...> is)
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkLexFormat(const IndexPack& ipack, Isq<Is...> is)
{
return std::make_tuple
return gmformat
( iter<Is,NI>
( [&](auto i) { return std::get<i>(ipack)->pmax(); },
[](const auto&... as) { return (as * ...); } )...,
SPos<1>() );
}
template <class BlockType, class... Indices>
template <class FormatT, class... Indices>
template <SizeT I>
inline void GMIndex<BlockType,Indices...>::up()
inline void GMIndex<FormatT,Indices...>::up()
{
auto& i = std::get<I>(mIPack);
std::integral_constant<SizeT,I> i;
auto& ind = std::get<I>(mIPack);
if constexpr(I != 0){
if(i->lex() == i->lmax().val()-1){
IB::mPos -= std::get<I>(blockSizes()).val() * i->pos();
if constexpr(not std::is_same<BlockType,None>::value){
mLex -= std::get<I>(lexBlockSizes()).val() * i->lex();
if(ind->lex() == ind->lmax().val()-1){
IB::mPos -= format()[i].val() * ind->pos();
if constexpr(not std::is_same<FormatT,None>::value){
mLex -= lexFormat()[i].val() * ind->lex();
}
(*i) = 0;
(*ind) = 0;
up<I-1>();
return;
}
}
IB::mPos += std::get<I>(blockSizes()).val();
if constexpr(not std::is_same<BlockType,None>::value){
mLex += std::get<I>(lexBlockSizes()).val();
IB::mPos += format()[i].val();
if constexpr(not std::is_same<FormatT,None>::value){
mLex += lexFormat()[i].val();
}
++(*i);
++(*ind);
}
template <class BlockType, class... Indices>
template <class FormatT, class... Indices>
template <SizeT I>
inline void GMIndex<BlockType,Indices...>::down()
inline void GMIndex<FormatT,Indices...>::down()
{
auto& i = std::get<I>(mIPack);
std::integral_constant<SizeT,I> i;
auto& ind = std::get<I>(mIPack);
if constexpr(I != 0){
if(i->lex() == 0){
(*i) = i->lmax().val()-1;
IB::mPos += std::get<I>(blockSizes()).val() * i->pos();
if constexpr(not std::is_same<BlockType,None>::value){
mLex += std::get<I>(lexBlockSizes()).val() * i->lex();
if(ind->lex() == 0){
(*ind) = ind->lmax().val()-1;
IB::mPos += format()[i].val() * ind->pos();
if constexpr(not std::is_same<FormatT,None>::value){
mLex += lexFormat()[i].val() * ind->lex();
}
down<I-1>();
return;
}
}
IB::mPos -= std::get<I>(blockSizes()).val();
if constexpr(not std::is_same<BlockType,None>::value){
mLex -= std::get<I>(lexBlockSizes()).val();
IB::mPos -= format()[i].val();
if constexpr(not std::is_same<FormatT,None>::value){
mLex -= lexFormat()[i].val();
}
--(*i);
--(*ind);
}
template <class BlockType, class... Indices>
template <class FormatT, class... Indices>
template <SizeT I, class Xpr, class F>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::mkIFor(const Xpr& xpr, F&& f) const
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkIFor(const Xpr& xpr, F&& f) const
{
if constexpr(I == sizeof...(Indices)-1){
return std::get<I>(mIPack)->ifor(xpr,std::forward<F>(f));
@ -133,129 +135,129 @@ namespace CNORXZ
* GMIndex *
***************/
template <class BlockType, class... Indices>
constexpr GMIndex<BlockType,Indices...>::GMIndex(const GMIndex& i) :
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
template <class FormatT, class... Indices>
constexpr GMIndex<FormatT,Indices...>::GMIndex(const GMIndex& i) :
IndexInterface<GMIndex<FormatT,Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(rangeCast<RangeType>(i.range())),
mIPack(mkIPack(Isqr<0,NI>{})),
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
mBlockSizes(i.mBlockSizes),
mLexFormat(mkLexFormat(mIPack,Isqr<1,NI>{})),
mFormat(i.mFormat),
mLMax(mkLMax(mIPack)),
mPMax(mkPMax(mIPack,mBlockSizes))
mPMax(mkPMax(mIPack,mFormat))
{
*this = i.lex();
}
template <class BlockType, class... Indices>
constexpr GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator=(const GMIndex& i)
template <class FormatT, class... Indices>
constexpr GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator=(const GMIndex& i)
{
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>::operator=(0);
IndexInterface<GMIndex<FormatT,Indices...>,Tuple<typename Indices::MetaType...>>::operator=(0);
mRange = rangeCast<RangeType>(i.range());
mIPack = mkIPack(Isqr<0,NI>{});
mLexBlockSizes = mkLexBlockSizes(mIPack,Isqr<1,NI>{});
mBlockSizes = i.mBlockSizes;
mLexFormat = mkLexFormat(mIPack,Isqr<1,NI>{});
mFormat = i.mFormat;
mLMax = mkLMax(mIPack);
mPMax = mkPMax(mIPack,mBlockSizes);
mPMax = mkPMax(mIPack,mFormat);
return *this = i.lex();
}
template <class BlockType, class... Indices>
constexpr GMIndex<BlockType,Indices...>::GMIndex(const Indices&... is) :
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
template <class FormatT, class... Indices>
constexpr GMIndex<FormatT,Indices...>::GMIndex(const Indices&... is) :
IndexInterface<GMIndex<FormatT,Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(std::dynamic_pointer_cast<RangeType>(mrange(is.range()...))),
mIPack(std::make_shared<Indices>(is)...),
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
mBlockSizes(),
mLexFormat(mkLexFormat(mIPack,Isqr<1,NI>{})),
mFormat(),
mLMax(mkLMax(mIPack)),
mPMax(mkPMax(mIPack,mBlockSizes))
mPMax(mkPMax(mIPack,mFormat))
{
mkPos();
}
template <class BlockType, class... Indices>
constexpr GMIndex<BlockType,Indices...>::GMIndex(const BlockType& bs, const Indices&... is) :
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
template <class FormatT, class... Indices>
constexpr GMIndex<FormatT,Indices...>::GMIndex(const FormatT& bs, const Indices&... is) :
IndexInterface<GMIndex<FormatT,Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(std::dynamic_pointer_cast<RangeType>(mrange(is.range()...))),
mIPack(std::make_shared<Indices>(is)...),
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
mBlockSizes(bs),
mLexFormat(mkLexFormat(mIPack,Isqr<1,NI>{})),
mFormat(bs),
mLMax(mkLMax(mIPack)),
mPMax(mkPMax(mIPack,mBlockSizes))
mPMax(mkPMax(mIPack,mFormat))
{
mkPos();
}
template <class BlockType, class... Indices>
constexpr GMIndex<BlockType,Indices...>::GMIndex(const Sptr<Indices>&... is) :
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
template <class FormatT, class... Indices>
constexpr GMIndex<FormatT,Indices...>::GMIndex(const Sptr<Indices>&... is) :
IndexInterface<GMIndex<FormatT,Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(std::dynamic_pointer_cast<RangeType>(mrange(is->range()...))),
mIPack(is...),
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
mBlockSizes(),
mLexFormat(mkLexFormat(mIPack,Isqr<1,NI>{})),
mFormat(),
mLMax(mkLMax(mIPack)),
mPMax(mkPMax(mIPack,mBlockSizes))
mPMax(mkPMax(mIPack,mFormat))
{
mkPos();
}
template <class BlockType, class... Indices>
constexpr GMIndex<BlockType,Indices...>::GMIndex(const BlockType& bs,
template <class FormatT, class... Indices>
constexpr GMIndex<FormatT,Indices...>::GMIndex(const FormatT& bs,
const Sptr<Indices>&... is) :
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
IndexInterface<GMIndex<FormatT,Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(std::dynamic_pointer_cast<RangeType>(mrange(is->range()...))),
mIPack(is...),
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
mBlockSizes(bs),
mLexFormat(mkLexFormat(mIPack,Isqr<1,NI>{})),
mFormat(bs),
mLMax(mkLMax(mIPack)),
mPMax(mkPMax(mIPack,mBlockSizes))
mPMax(mkPMax(mIPack,mFormat))
{
mkPos();
}
template <class BlockType, class... Indices>
constexpr GMIndex<BlockType,Indices...>::GMIndex(const RangePtr& range, SizeT lexpos) :
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
template <class FormatT, class... Indices>
constexpr GMIndex<FormatT,Indices...>::GMIndex(const RangePtr& range, SizeT lexpos) :
IndexInterface<GMIndex<FormatT,Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(rangeCast<RangeType>(range)),
mIPack(mkIPack(Isqr<0,NI>{})),
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
mBlockSizes(),
mLexFormat(mkLexFormat(mIPack,Isqr<1,NI>{})),
mFormat(),
mLMax(mkLMax(mIPack)),
mPMax(mkPMax(mIPack,mBlockSizes))
mPMax(mkPMax(mIPack,mFormat))
{
*this = lexpos;
}
template <class BlockType, class... Indices>
constexpr GMIndex<BlockType,Indices...>::GMIndex(const RangePtr& range, const BlockType& blockSizes, SizeT lexpos) :
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
template <class FormatT, class... Indices>
constexpr GMIndex<FormatT,Indices...>::GMIndex(const RangePtr& range, const FormatT& format, SizeT lexpos) :
IndexInterface<GMIndex<FormatT,Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(rangeCast<RangeType>(range)),
mIPack(mkIPack(Isqr<0,NI>{})),
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
mBlockSizes(blockSizes),
mLexFormat(mkLexFormat(mIPack,Isqr<1,NI>{})),
mFormat(format),
mLMax(mkLMax(mIPack)),
mPMax(mkPMax(mIPack,mBlockSizes))
mPMax(mkPMax(mIPack,mFormat))
{
*this = lexpos;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator=(SizeT lexpos)
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator=(SizeT lexpos)
{
if(lexpos >= lmax().val()){
if constexpr(not std::is_same<BlockType,None>::value){ mLex = lmax().val(); }
if constexpr(not std::is_same<FormatT,None>::value){ mLex = lmax().val(); }
IB::mPos = pmax().val();
return *this;
}
if constexpr(not std::is_same<BlockType,None>::value){ mLex = lexpos; }
if constexpr(not std::is_same<FormatT,None>::value){ mLex = lexpos; }
IB::mPos = iter<0,NI>( [&](auto i) {
*std::get<i>(mIPack) = (lex() / std::get<i>(lexBlockSizes()).val()) % std::get<i>(mIPack)->lmax().val();
return std::get<i>(blockSizes()).val() * std::get<i>(mIPack)->pos();
*std::get<i>(mIPack) = (lex() / lexFormat()[i].val()) % std::get<i>(mIPack)->lmax().val();
return format()[i].val() * std::get<i>(mIPack)->pos();
}, [](const auto&... e) { return (e + ...); } );
return *this;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator++()
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator++()
{
if(lex() == lmax().val()-1){
return *this = lmax().val();
@ -266,8 +268,8 @@ namespace CNORXZ
return *this;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator--()
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator--()
{
if(lex() == lmax().val()){
return *this = lmax().val()-1;
@ -278,22 +280,22 @@ namespace CNORXZ
return *this;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...> GMIndex<BlockType,Indices...>::operator+(Int n) const
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...> GMIndex<FormatT,Indices...>::operator+(Int n) const
{
GMIndex o(*this);
return o += n;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...> GMIndex<BlockType,Indices...>::operator-(Int n) const
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...> GMIndex<FormatT,Indices...>::operator-(Int n) const
{
GMIndex o(*this);
return o -= n;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator+=(Int n)
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator+=(Int n)
{
if(-n > static_cast<long int>(lex())){
(*this) = 0;
@ -306,8 +308,8 @@ namespace CNORXZ
return *this;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator-=(Int n)
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator-=(Int n)
{
if(n > static_cast<long int>(lex())){
(*this) = 0;
@ -320,10 +322,10 @@ namespace CNORXZ
return *this;
}
template <class BlockType, class... Indices>
SizeT GMIndex<BlockType,Indices...>::lex() const
template <class FormatT, class... Indices>
SizeT GMIndex<FormatT,Indices...>::lex() const
{
if constexpr(std::is_same<BlockType,None>::value){
if constexpr(std::is_same<FormatT,None>::value){
return IB::mPos;
}
else {
@ -331,53 +333,53 @@ namespace CNORXZ
}
}
template <class BlockType, class... Indices>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::pmax() const
template <class FormatT, class... Indices>
constexpr decltype(auto) GMIndex<FormatT,Indices...>::pmax() const
{
return mPMax;
}
template <class BlockType, class... Indices>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::lmax() const
template <class FormatT, class... Indices>
constexpr decltype(auto) GMIndex<FormatT,Indices...>::lmax() const
{
return mPMax;
}
template <class BlockType, class... Indices>
IndexId<0> GMIndex<BlockType,Indices...>::id() const
template <class FormatT, class... Indices>
IndexId<0> GMIndex<FormatT,Indices...>::id() const
{
return IndexId<0>(this->ptrId());
}
template <class BlockType, class... Indices>
typename GMIndex<BlockType,Indices...>::MetaType GMIndex<BlockType,Indices...>::operator*() const
template <class FormatT, class... Indices>
typename GMIndex<FormatT,Indices...>::MetaType GMIndex<FormatT,Indices...>::operator*() const
{
return meta();
}
template <class BlockType, class... Indices>
constexpr SizeT GMIndex<BlockType,Indices...>::dim() const
template <class FormatT, class... Indices>
constexpr SizeT GMIndex<FormatT,Indices...>::dim() const
{
return NI;
}
template <class BlockType, class... Indices>
Sptr<typename GMIndex<BlockType,Indices...>::RangeType> GMIndex<BlockType,Indices...>::range() const
template <class FormatT, class... Indices>
Sptr<typename GMIndex<FormatT,Indices...>::RangeType> GMIndex<FormatT,Indices...>::range() const
{
return mRange;
}
template <class BlockType, class... Indices>
template <class FormatT, class... Indices>
template <SizeT I>
decltype(auto) GMIndex<BlockType,Indices...>::stepSize(const IndexId<I>& id) const
decltype(auto) GMIndex<FormatT,Indices...>::stepSize(const IndexId<I>& id) const
{
return iter<0,NI>
( [&](auto i) { return std::get<i>(mIPack)->stepSize(id) * std::get<i>(blockSizes()); },
( [&](auto i) { return std::get<i>(mIPack)->stepSize(id) * format()[i]; },
[](const auto&... ss) { return ( ss + ... ); });
}
template <class BlockType, class... Indices>
String GMIndex<BlockType,Indices...>::stringMeta() const
template <class FormatT, class... Indices>
String GMIndex<FormatT,Indices...>::stringMeta() const
{
const String blim = "(";
const String elim = ")";
@ -389,156 +391,79 @@ namespace CNORXZ
} );
}
template <class BlockType, class... Indices>
typename GMIndex<BlockType,Indices...>::MetaType GMIndex<BlockType,Indices...>::meta() const
template <class FormatT, class... Indices>
typename GMIndex<FormatT,Indices...>::MetaType GMIndex<FormatT,Indices...>::meta() const
{
return iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->meta(); },
[](const auto&... xs) { return std::make_tuple(xs...); } );
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::at(const MetaType& metaPos)
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::at(const MetaType& metaPos)
{
iter<0,NI>( [&](auto i) { std::get<i>(mIPack)->at( std::get<i>(metaPos) ); }, NoF {} );
IB::mPos = iter<0,NI>
( [&](auto i) { return std::get<i>(mIPack)->pos()*std::get<i>(blockSizes()).val(); },
( [&](auto i) { return std::get<i>(mIPack)->pos()*format()[i].val(); },
[](const auto&... xs) { return (xs + ...); });
return *this;
}
template <class BlockType, class... Indices>
template <class Index>
decltype(auto) GMIndex<BlockType,Indices...>::format(const Sptr<Index>& ind) const
{
static_assert(is_index<Index>::value, "got non-index type");
static_assert(has_sub<Index>::value, "try to format single index");
if constexpr(has_static_sub<Index>::value){
static_assert(index_dim<Index>::value == NI, "got index with conflicting static dimension");
return iter<0,NI>
( [&](auto i) {
return std::get<i>(mIPack)->format(std::get<i>(ind->pack()));
},
[&](const auto&... e) {
return gmindexPtr(mBlockSizes, e... );
} );
}
else {
auto pack = ind->pack();
CXZ_ASSERT(pack.size() == NI, "attempt to format index of dimension " << NI
<< " using index of dimension " << pack.size());
return iter<0,NI>
( [&](auto i) {
return std::get<i>(mIPack)->format(pack[i]);
},
[&](const auto&... e) {
return gmindexPtr(mBlockSizes, e... );
} );
}
}
template <class BlockType, class... Indices>
template <class Index>
decltype(auto) GMIndex<BlockType,Indices...>::slice(const Sptr<Index>& ind) const
{
static_assert(is_index<Index>::value, "got non-index type");
static_assert(has_sub<Index>::value, "try to slice single index");
if constexpr(has_static_sub<Index>::value and
((has_static_sub<Indices>::value and ...) or
(not has_sub<Indices>::value and ...)) ){
static_assert(index_dim<Index>::value == NI, "got index with conflicting static dimension");
const auto bs = iterIf<0,NI>
( [&](auto i) { return std::get<i>(mBlockSizes); },
[](const auto&... e) { std::make_tuple(e...); },
[](auto i) {
return std::is_same<typename TupleElem<i>::type,NIndex>::value;
});
return iterIf<0,NI>
( [&](auto i) { return std::get<i>(mIPack)->slice(std::get<i>(ind->pack())); },
[&](const auto&... e) { return gmindex(bs, e... ); },
[](auto i) {
return std::is_same<typename TupleElem<i>::type,NIndex>::value;
} );
}
else {
Vector<SizeT> bs;
Vector<XIndexPtr> ivec;
bs.reserve(NI);
ivec.reserve(NI);
auto pack = ind->pack();
CXZ_ASSERT(pack.size() == NI, "attempt to slice index of dimension " << NI
<< " using index of dimension " << pack.size());
iter<0,NI>
( [&](auto i) {
if(std::get<i>(mIPack)->dim() == 0){
bs.push_back(std::get<i>(mBlockSizes).val());
if constexpr(has_static_sub<Index>::value){
ivec.push_back( xindexPtr( std::get<i>(ind->pack()) ) );
}
else {
ivec.push_back( xindexPtr( ind->pack()[i] ) );
}
}
}, NoF {});
return yindexPtr(bs, ivec);
}
}
template <class BlockType, class... Indices>
template <class FormatT, class... Indices>
template <class Xpr, class F>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::ifor(const Xpr& xpr, F&& f) const
constexpr decltype(auto) GMIndex<FormatT,Indices...>::ifor(const Xpr& xpr, F&& f) const
{
return mkIFor<0>(xpr, std::forward<F>(f));
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator()(const Sptr<MIndex<Indices...>>& mi)
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator()(const Sptr<MIndex<Indices...>>& mi)
{
mIPack = mi.pack();
mkPos();
return *this;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator()()
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::operator()()
{
mkPos();
return *this;
}
template <class BlockType, class... Indices>
const typename GMIndex<BlockType,Indices...>::IndexPack& GMIndex<BlockType,Indices...>::pack() const
template <class FormatT, class... Indices>
const typename GMIndex<FormatT,Indices...>::IndexPack& GMIndex<FormatT,Indices...>::pack() const
{
return mIPack;
}
template <class BlockType, class... Indices>
const auto& GMIndex<BlockType,Indices...>::blockSizes() const
template <class FormatT, class... Indices>
const auto& GMIndex<FormatT,Indices...>::format() const
{
if constexpr(std::is_same<BlockType,None>::value){
return mLexBlockSizes;
if constexpr(std::is_same<FormatT,None>::value){
return mLexFormat;
}
else {
return mBlockSizes;
return mFormat;
}
}
template <class BlockType, class... Indices>
const auto& GMIndex<BlockType,Indices...>::lexBlockSizes() const
template <class FormatT, class... Indices>
const auto& GMIndex<FormatT,Indices...>::lexFormat() const
{
return mLexBlockSizes;
return mLexFormat;
}
template <class BlockType, class... Indices>
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::setBlockSizes(const BlockType& bs)
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::setFormat(const FormatT& bs)
{
if constexpr(not std::is_same<BlockType,None>::value){
mBlockSizes = bs;
if constexpr(not std::is_same<FormatT,None>::value){
mFormat = bs;
}
return *this;
}
template <class BT1, class BT2, class... Indices>
decltype(auto) replaceBlockSizes(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi)
decltype(auto) replaceFormat(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi)
{
return iter<0,sizeof...(Indices)>
( [&](auto i) { return std::get<i>(gmi->pack()); },
@ -558,10 +483,10 @@ namespace CNORXZ
return MIndex<Indices...>(is...);
}
template <class BlockType, class... Indices>
constexpr decltype(auto) gmindexPtr(const BlockType& bs, const Sptr<Indices>&... is)
template <class FormatT, class... Indices>
constexpr decltype(auto) gmindexPtr(const FormatT& bs, const Sptr<Indices>&... is)
{
return std::make_shared<GMIndex<BlockType,Indices...>>(bs, is...);
return std::make_shared<GMIndex<FormatT,Indices...>>(bs, is...);
}
/*********************

View file

@ -6,19 +6,21 @@
#include "base/base.h"
#include "range_base.h"
#include "index_base.h"
#include "index_format.h"
#include "index_pack.h"
#include "xpr/xpr.h"
namespace CNORXZ
{
// template <class FormatT, class... Indices>
// -> Format + IndexTuple
template <class BlockType, class... Indices>
class GMIndex : public IndexInterface<GMIndex<BlockType,Indices...>,
template <class FormatT, class... Indices>
class GMIndex : public IndexInterface<GMIndex<FormatT,Indices...>,
Tuple<typename Indices::MetaType...> >
{
public:
typedef IndexInterface<GMIndex<BlockType,Indices...>,
typedef IndexInterface<GMIndex<FormatT,Indices...>,
Tuple<typename Indices::MetaType...>> IB;
typedef Tuple<Sptr<Indices>...> IndexPack;
typedef Tuple<typename Indices::MetaType...> MetaType;
@ -35,11 +37,11 @@ namespace CNORXZ
//constexpr GMIndex(const SPack<Indices...>& is);
//constexpr GMIndex(const FormatT& format, const SPack<Indices...>& is);
constexpr GMIndex(const Indices&... is);
constexpr GMIndex(const BlockType& blockSizes, const Indices&... is);
constexpr GMIndex(const FormatT& format, const Indices&... is);
constexpr GMIndex(const Sptr<Indices>&... is);
constexpr GMIndex(const BlockType& blockSizes, const Sptr<Indices>&... is);
constexpr GMIndex(const FormatT& format, const Sptr<Indices>&... is);
constexpr GMIndex(const RangePtr& range, SizeT lexpos = 0);
constexpr GMIndex(const RangePtr& range, const BlockType& blockSizes, SizeT lexpos = 0);
constexpr GMIndex(const RangePtr& range, const FormatT& format, SizeT lexpos = 0);
GMIndex& operator=(SizeT pos);
GMIndex& operator++();
@ -66,18 +68,6 @@ namespace CNORXZ
MetaType meta() const;
GMIndex& at(const MetaType& metaPos);
template <class Index>
decltype(auto) format(const Sptr<Index>& ind) const;
// -> IndexInterface;
// replace index instances xor replace blockSizes of ind by that of *this
// return result as new instance
template <class Index>
decltype(auto) slice(const Sptr<Index>& ind) const;
// -> IndexInterface;
// drop index instance or drop blockSize of ind if that of *this is not Null
// return result as new instance
template <class Xpr, class F>
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
@ -86,17 +76,17 @@ namespace CNORXZ
GMIndex& operator()();
const IndexPack& pack() const;
const auto& blockSizes() const;
const auto& lexBlockSizes() const;
GMIndex& setBlockSizes(const BlockType& bs);
const auto& format() const;
const auto& lexFormat() const;
GMIndex& setFormat(const FormatT& bs);
private:
template <SizeT... Is>
static constexpr decltype(auto) mkLexBlockSizes(const IndexPack& ipack, Isq<Is...> is);
static constexpr decltype(auto) mkLexFormat(const IndexPack& ipack, Isq<Is...> is);
static constexpr decltype(auto) mkLMax(const IndexPack& ipack);
static constexpr decltype(auto) mkPMax(const IndexPack& ipack, const BlockType& blockSizes);
static constexpr decltype(auto) mkPMax(const IndexPack& ipack, const FormatT& format);
inline void mkPos();
@ -114,18 +104,19 @@ namespace CNORXZ
Sptr<RangeType> mRange;
IndexPack mIPack;
typedef RemoveRef<decltype(mkLexBlockSizes(mIPack,Isqr<0,NI-1>{}))> LexBlockType;
LexBlockType mLexBlockSizes;
BlockType mBlockSizes; // -> FormatT
typedef RemoveRef<decltype(mkLexFormat(mIPack,Isqr<0,NI-1>{}))> LexFormatT;
LexFormatT mLexFormat;
FormatT mFormat;
//BlockType mFormat; // -> FormatT
SizeT mLex;
typedef RemoveRef<decltype(mkLMax(mIPack))> LMaxT;
LMaxT mLMax;
typedef RemoveRef<decltype(mkPMax(mIPack,mBlockSizes))> PMaxT;
typedef RemoveRef<decltype(mkPMax(mIPack,mFormat))> PMaxT;
PMaxT mPMax;
};
template <class BT1, class BT2, class... Indices>
decltype(auto) replaceBlockSizes(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi);
decltype(auto) replaceFormat(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi);
template <class BT1, class... Is1, class BT2, class... Is2>
decltype(auto) operator*(const Sptr<GMIndex<BT1,Is1...>>& a, const Sptr<GMIndex<BT2,Is2...>>& b);
@ -155,8 +146,8 @@ namespace CNORXZ
template <class... Indices>
constexpr decltype(auto) mindex(const Sptr<Indices>&... is);
template <class BlockType, class... Indices>
constexpr decltype(auto) gmindexPtr(const BlockType& bs, const Sptr<Indices>&... is);
template <class FormatT, class... Indices>
constexpr decltype(auto) gmindexPtr(const FormatT& bs, const Sptr<Indices>&... is);
template <class... Ranges>
class MRangeFactory : public RangeFactoryBase

View file

@ -126,7 +126,7 @@ namespace CNORXZ
{
return mI->stepSize(id);
}
/*
template <class Index, typename Meta>
Vector<XIndexPtr> XIndex<Index,Meta>::pack() const
{
@ -188,7 +188,7 @@ namespace CNORXZ
return nullptr;
}
}
*/
template <class Index, typename Meta>
String XIndex<Index,Meta>::stringMeta() const
{
@ -209,22 +209,6 @@ namespace CNORXZ
return *this;
}
template <class Index, typename Meta>
Sptr<DIndex> XIndex<Index,Meta>::format(const Sptr<DIndex>& ind) const
{
CXZ_ERROR("IMPLEMENT!!!");
return nullptr;
//return std::make_shared<DIndex>(xindexPtr(mI->format(ind)));
}
template <class Index, typename Meta>
Sptr<DIndex> XIndex<Index,Meta>::slice(const Sptr<DIndex>& ind) const
{
CXZ_ERROR("IMPLEMENT!!!");
return nullptr;
//return std::make_shared<DIndex>(xindexPtr(mI->slice(ind)));
}
template <class Index, typename Meta>
DXpr<SizeT> XIndex<Index,Meta>::ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const

View file

@ -38,17 +38,14 @@ namespace CNORXZ
virtual SizeT dim() const = 0;
virtual RangePtr range() const = 0;
virtual UPos stepSize(const IndexId<0>& id) const = 0;
virtual Vector<XIndexPtr> pack() const = 0;
virtual Vector<SizeT> blockSizes() const = 0;
virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) = 0;
//virtual Vector<XIndexPtr> pack() const = 0;
//virtual Vector<SizeT> format() const = 0;
//virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) = 0;
virtual String stringMeta() const = 0;
virtual DType meta() const = 0;
virtual XIndexBase& at(const DType& meta) = 0;
virtual Sptr<DIndex> format(const Sptr<DIndex>& ind) const = 0;
virtual Sptr<DIndex> slice(const Sptr<DIndex>& ind) const = 0;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const = 0;
@ -93,17 +90,14 @@ namespace CNORXZ
virtual SizeT dim() const override final;
virtual RangePtr range() const override final;
virtual UPos stepSize(const IndexId<0>& id) const override final;
virtual Vector<XIndexPtr> pack() const override final;
virtual Vector<SizeT> blockSizes() const override final;
virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) override final;
//virtual Vector<XIndexPtr> pack() const override final;
//virtual Vector<SizeT> format() const override final;
//virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) override final;
virtual String stringMeta() const override final;
virtual DType meta() const override final;
virtual XIndexBase& at(const DType& meta) override final;
virtual Sptr<DIndex> format(const Sptr<DIndex>& ind) const override final;
virtual Sptr<DIndex> slice(const Sptr<DIndex>& ind) const override final;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const override final;

View file

@ -128,7 +128,7 @@ namespace CNORXZ
{
return mI->stepSize(id);
}
/*
Vector<XIndexPtr> DIndex::pack() const
{
return mI->pack();
@ -144,7 +144,7 @@ namespace CNORXZ
mI->setBlockSizes(bs);
return *this;
}
*/
String DIndex::stringMeta() const
{
return mI->stringMeta();
@ -162,16 +162,6 @@ namespace CNORXZ
return *this;
}
Sptr<DIndex> DIndex::format(const Sptr<DIndex>& ind) const
{
return mI->format(ind);
}
Sptr<DIndex> DIndex::slice(const Sptr<DIndex>& ind) const
{
return mI->slice(ind);
}
DXpr<SizeT> DIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
{
return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)) );