continue previous commit
This commit is contained in:
parent
13488b9839
commit
482a7a7b4e
12 changed files with 242 additions and 524 deletions
|
@ -131,8 +131,16 @@ namespace MultiArrayTools
|
|||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::up()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
RPackNum<DIR>::pp( mIPack );
|
||||
IB::mPos += sfor_p<DIR,sizeof...(Indices)>
|
||||
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
||||
[&](auto a, auto b) { return a * b; } );
|
||||
sfor_m<DIR+1,0>
|
||||
( [&](auto i) {
|
||||
auto& si = *std::get<i>( mIPack );
|
||||
if(si.last() and i != 0) { si = 0; return true; }
|
||||
else { ++si; return false; }
|
||||
return false;
|
||||
} );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -141,8 +149,16 @@ namespace MultiArrayTools
|
|||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::down()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
RPackNum<DIR>::mm( mIPack );
|
||||
IB::mPos -= sfor_p<DIR,sizeof...(Indices)>
|
||||
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
||||
[&](auto a, auto b) { return a * b; } );
|
||||
sfor_m<DIR+1,0>
|
||||
( [&](auto i) {
|
||||
auto& si = *std::get<i>( mIPack );
|
||||
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
||||
else { --si; return false; }
|
||||
return false;
|
||||
} );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -185,14 +201,12 @@ namespace MultiArrayTools
|
|||
{
|
||||
(*mOutIndex) = pos;
|
||||
IB::mPos = mOutIndex->pos();
|
||||
//RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator++()
|
||||
{
|
||||
//RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
++(*mOutIndex);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
return *this;
|
||||
|
@ -201,7 +215,6 @@ namespace MultiArrayTools
|
|||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator--()
|
||||
{
|
||||
//RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
--(*mOutIndex);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
return *this;
|
||||
|
@ -210,20 +223,16 @@ namespace MultiArrayTools
|
|||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
|
||||
{
|
||||
//int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
||||
mOutIndex->pp(idxPtrNum);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
//IB::mPos += tmp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
|
||||
{
|
||||
//int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
||||
mOutIndex->mm(idxPtrNum);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
//IB::mPos -= tmp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,12 +68,7 @@ namespace MultiArrayTools
|
|||
mCPos(in.mCPos),
|
||||
mObjPtrNum(in.mObjPtrNum)
|
||||
{
|
||||
//if(copy){
|
||||
RPackNum<sizeof...(Indices)-1>::copyIndex(mIPack, in);
|
||||
//}
|
||||
//else {
|
||||
//mIPack = in.mIPack;
|
||||
//}
|
||||
}
|
||||
|
||||
ContainerIndex& copy(const ContainerIndex& in)
|
||||
|
@ -149,16 +144,16 @@ namespace MultiArrayTools
|
|||
void print(size_t offset);
|
||||
|
||||
template <class Exprs>
|
||||
auto ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs));
|
||||
auto ifor(size_t step, Exprs exs) const;
|
||||
//-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
template <class Exprs>
|
||||
auto iforh(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs));
|
||||
auto iforh(size_t step, Exprs exs) const;
|
||||
// -> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
template <class Exprs>
|
||||
auto pifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs));
|
||||
auto pifor(size_t step, Exprs exs) const;
|
||||
// -> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
std::intptr_t container() const;
|
||||
ContainerIndex& format(const std::array<size_t,sizeof...(Indices)+1>& blocks);
|
||||
|
@ -189,71 +184,6 @@ namespace MultiArrayTools
|
|||
|
||||
};
|
||||
|
||||
/*
|
||||
template <typename T, class... Ranges>
|
||||
class ContainerRangeFactory : public RangeFactoryBase
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ContainerRange<T,Ranges...> oType;
|
||||
|
||||
ContainerRangeFactory();
|
||||
ContainerRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
||||
ContainerRangeFactory(const typename ContainerRange<T,Ranges...>::SpaceType& space);
|
||||
|
||||
virtual std::shared_ptr<RangeBase> create() override;
|
||||
|
||||
protected:
|
||||
|
||||
};*/
|
||||
/*
|
||||
template <typename T, class... Ranges>
|
||||
class ContainerRange : public RangeInterface<ContainerIndex<T,typename Ranges::IndexType...> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef RangeBase RB;
|
||||
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
|
||||
typedef ContainerIndex<T,typename Ranges::IndexType...> IndexType;
|
||||
|
||||
protected:
|
||||
ContainerRange() = default;
|
||||
ContainerRange(const ContainerRange& in) = delete;
|
||||
ContainerRange& operator=(const ContainerRange& in) = delete;
|
||||
|
||||
ContainerRange(const std::shared_ptr<Ranges>&... rs);
|
||||
ContainerRange(const SpaceType& space);
|
||||
|
||||
SpaceType mSpace;
|
||||
|
||||
public:
|
||||
static const size_t sdim = sizeof...(Ranges);
|
||||
|
||||
virtual size_t dim() const override;
|
||||
virtual size_t size() const override;
|
||||
|
||||
template <size_t N>
|
||||
auto get() const -> decltype( *std::get<N>( mSpace ) )&;
|
||||
|
||||
template <size_t N>
|
||||
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
||||
|
||||
const SpaceType& space() const;
|
||||
|
||||
virtual IndexType begin() const override;
|
||||
virtual IndexType end() const override;
|
||||
|
||||
friend ContainerRangeFactory<T,Ranges...>;
|
||||
|
||||
static constexpr bool defaultable = false;
|
||||
static constexpr size_t ISSTATIC = SubProp<Ranges...>::ISSTATIC;
|
||||
static constexpr size_t SIZE = SubProp<Ranges...>::SIZE;
|
||||
};
|
||||
*/
|
||||
|
||||
//template <typename T, class... Ranges>
|
||||
//using ContainerRange = MultiRange<Ranges...>;
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
|
||||
/* ========================= *
|
||||
|
@ -316,9 +246,6 @@ namespace MultiArrayTools
|
|||
if(mExternControl){
|
||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
||||
//VCHECK(id());
|
||||
//VCHECK(sizeof...(Indices));
|
||||
//assert(IB::mPos < IB::max());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -368,7 +295,13 @@ namespace MultiArrayTools
|
|||
if(mExternControl){
|
||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
}
|
||||
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
sfor_m<sizeof...(Indices),0>
|
||||
( [&](auto i) {
|
||||
auto& si = *std::get<i>( mIPack );
|
||||
if(si.last() and i != 0) { si = 0; return true; }
|
||||
else { ++si; return false; }
|
||||
return false;
|
||||
} );
|
||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
|
@ -380,7 +313,13 @@ namespace MultiArrayTools
|
|||
if(mExternControl){
|
||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
}
|
||||
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
sfor_m<sizeof...(Indices),0>
|
||||
( [&](auto i) {
|
||||
auto& si = *std::get<i>( mIPack );
|
||||
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
||||
else { --si; return false; }
|
||||
return false;
|
||||
} );
|
||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
|
@ -399,7 +338,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... Indices>
|
||||
int ContainerIndex<T,Indices...>::pp(std::intptr_t idxPtrNum)
|
||||
{
|
||||
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
||||
const int tmp = ppx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||
IB::mPos += tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
@ -407,7 +346,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... Indices>
|
||||
int ContainerIndex<T,Indices...>::mm(std::intptr_t idxPtrNum)
|
||||
{
|
||||
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
||||
const int tmp = mmx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||
IB::mPos -= tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
@ -503,7 +442,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... Indices>
|
||||
template <class Exprs>
|
||||
auto ContainerIndex<T,Indices...>::ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs))
|
||||
// -> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
@ -511,7 +450,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... Indices>
|
||||
template <class Exprs>
|
||||
auto ContainerIndex<T,Indices...>::iforh(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs))
|
||||
// -> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
@ -519,7 +458,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... Indices>
|
||||
template <class Exprs>
|
||||
auto ContainerIndex<T,Indices...>::pifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs))
|
||||
// -> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
@ -673,93 +612,6 @@ namespace MultiArrayTools
|
|||
return IB::mPos >= it.pos();
|
||||
}
|
||||
|
||||
/*****************************
|
||||
* ContainerRangeFactory *
|
||||
*****************************/
|
||||
/*
|
||||
template <typename T, class... Ranges>
|
||||
ContainerRangeFactory<T,Ranges...>::ContainerRangeFactory(const std::shared_ptr<Ranges>&... rs)
|
||||
{
|
||||
mProd = std::shared_ptr<ContainerRange<T,Ranges...> >( new ContainerRange<T,Ranges...>( rs... ) );
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
ContainerRangeFactory<T,Ranges...>::
|
||||
ContainerRangeFactory(const typename ContainerRange<T,Ranges...>::SpaceType& space)
|
||||
{
|
||||
mProd = std::shared_ptr<ContainerRange<T,Ranges...> >( new ContainerRange<T,Ranges...>( space ) );
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
std::shared_ptr<RangeBase> ContainerRangeFactory<T,Ranges...>::create()
|
||||
{
|
||||
setSelf();
|
||||
return mProd;
|
||||
}
|
||||
*/
|
||||
/**********************
|
||||
* ContainerRange *
|
||||
**********************/
|
||||
/*
|
||||
template <typename T, class... Ranges>
|
||||
ContainerRange<T,Ranges...>::ContainerRange(const std::shared_ptr<Ranges>&... rs) :
|
||||
mSpace( std::make_tuple( rs... ) ) {}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
ContainerRange<T,Ranges...>::ContainerRange(const SpaceType& space) : mSpace( space ) {}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
size_t ContainerRange<T,Ranges...>::dim() const
|
||||
{
|
||||
return sizeof...(Ranges);
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
size_t ContainerRange<T,Ranges...>::size() const
|
||||
{
|
||||
return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
template <size_t N>
|
||||
auto ContainerRange<T,Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
|
||||
{
|
||||
return *std::get<N>( mSpace );
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
template <size_t N>
|
||||
auto ContainerRange<T,Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
|
||||
{
|
||||
return std::get<N>( mSpace );
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
const typename ContainerRange<T,Ranges...>::SpaceType& ContainerRange<T,Ranges...>::space() const
|
||||
{
|
||||
return mSpace;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
typename ContainerRange<T,Ranges...>::IndexType ContainerRange<T,Ranges...>::begin() const
|
||||
{
|
||||
ContainerIndex<T,typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<ContainerRange<T,Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
i = 0;
|
||||
return i;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
typename ContainerRange<T,Ranges...>::IndexType ContainerRange<T,Ranges...>::end() const
|
||||
{
|
||||
ContainerIndex<T,typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<ContainerRange<T,Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
i = size();
|
||||
return i;
|
||||
}
|
||||
*/
|
||||
} // end namespace MultiArrayTools
|
||||
|
||||
|
||||
|
|
|
@ -111,9 +111,6 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n) const;
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
DynamicExpression ifor(size_t step, Expr ex) const;
|
||||
|
||||
|
|
|
@ -57,15 +57,11 @@ namespace MultiArrayTools
|
|||
|
||||
operator size_t() const;
|
||||
|
||||
std::string id() const { return THIS().id(); }
|
||||
|
||||
std::string stringMeta() const { return THIS().stringMeta(); }
|
||||
MetaType meta() const { return THIS().meta(); }
|
||||
MetaType metaPtr() const { return THIS().metaPtr(); }
|
||||
I& at(const MetaType& meta) { return THIS().at(meta); }
|
||||
|
||||
void print(size_t offset = 0) const { THIS().print(offset); }
|
||||
|
||||
// CHECK / IMPLEMENT !!!!!!
|
||||
template <class Expr>
|
||||
auto ifor(size_t step, const Expr ex) const
|
||||
|
@ -93,7 +89,6 @@ namespace MultiArrayTools
|
|||
|
||||
std::shared_ptr<RangeBase> mRangePtr;
|
||||
size_t mPos = 0;
|
||||
size_t mId;
|
||||
size_t mMax = 0;
|
||||
|
||||
std::intptr_t mPtrNum;
|
||||
|
@ -118,7 +113,7 @@ namespace MultiArrayTools
|
|||
**********************/
|
||||
|
||||
template <class I, typename MetaType>
|
||||
IndexInterface<I,MetaType>::IndexInterface() : mId(indexId())
|
||||
IndexInterface<I,MetaType>::IndexInterface()
|
||||
{
|
||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||
}
|
||||
|
@ -128,7 +123,6 @@ namespace MultiArrayTools
|
|||
mPos(in.mPos),
|
||||
mMax(in.mMax)
|
||||
{
|
||||
mId = indexId();
|
||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||
}
|
||||
|
||||
|
@ -137,7 +131,6 @@ namespace MultiArrayTools
|
|||
mPos(in.mPos),
|
||||
mMax(in.mMax)
|
||||
{
|
||||
mId = indexId();
|
||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||
}
|
||||
|
||||
|
@ -165,7 +158,6 @@ namespace MultiArrayTools
|
|||
mPos(pos),
|
||||
mMax(mRangePtr->size())
|
||||
{
|
||||
mId = indexId();
|
||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -115,21 +115,14 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n);
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
template <class Exprs>
|
||||
auto ifor(size_t step, Exprs exs) const;
|
||||
|
||||
template <class Exprs>
|
||||
auto ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs));
|
||||
auto iforh(size_t step, Exprs exs) const;
|
||||
|
||||
template <class Exprs>
|
||||
auto iforh(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
template <class Exprs>
|
||||
auto pifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
auto pifor(size_t step, Exprs exs) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -173,7 +166,6 @@ namespace MultiArrayTools
|
|||
typedef std::tuple<typename Ranges::IndexType::MetaType...> MetaType;
|
||||
typedef MultiRange RangeType;
|
||||
typedef MultiRangeFactory<Ranges...> FType;
|
||||
//typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
||||
|
||||
protected:
|
||||
MultiRange() = delete;
|
||||
|
@ -249,30 +241,15 @@ namespace MultiArrayTools
|
|||
* MultiIndex *
|
||||
******************/
|
||||
|
||||
/*
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>::MultiIndex(const MultiIndex<Indices...>& in) :
|
||||
IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(const MultiIndex<Indices...>& in)
|
||||
{
|
||||
IndexI::operator=(in);
|
||||
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
template <class... Indices>
|
||||
template <typename T>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(ContainerIndex<T,Indices...>& ci)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::copyInst(mIPack, ci);
|
||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
sfor_p<0,sizeof...(Indices)>
|
||||
( [&](auto i) { std::get<i>(mIPack) = ci.template getPtr<i>(); return true; } );
|
||||
IB::mPos = sfor_p<0,sizeof...(Indices)>
|
||||
( [&](auto i) { return std::get<i>(mIPack); },
|
||||
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -282,29 +259,21 @@ namespace MultiArrayTools
|
|||
IndexInterface<MultiIndex<Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
||||
{
|
||||
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
||||
sfor<sizeof...(Indices),0,-1>
|
||||
( [&](auto i) constexpr { return i-1; } ,
|
||||
[&](auto i) {
|
||||
sfor_mn<sizeof...(Indices),0>
|
||||
( [&](auto i) {
|
||||
auto r = range->template getPtr<i>();
|
||||
std::get<i>(mIPack) = r->beginPtr();
|
||||
*std::get<i>(mIPack) = 0;
|
||||
|
||||
std::get<i>(mBlockSizes) = sfor<i,sizeof...(Indices),0>
|
||||
( [&](auto j) { return j+1; } ,
|
||||
[&](auto j) { return std::get<j>(mIPack)->max(); } ,
|
||||
[&](auto a, auto b) { return a * b; }
|
||||
);
|
||||
|
||||
std::get<i>(mBlockSizes) = sfor_p<i,sizeof...(Indices)>
|
||||
( [&](auto j) { return std::get<j>(mIPack)->max(); } ,
|
||||
[&](auto a, auto b) { return a * b; });
|
||||
return 0;
|
||||
},
|
||||
[&](auto a, auto b) { return 0; }
|
||||
);
|
||||
});
|
||||
|
||||
IB::mPos = sfor<0,sizeof...(Indices),0>
|
||||
( [&](auto i) {return i+1;},
|
||||
[&](auto i) {return std::get<i>(mIPack);},
|
||||
[&](auto a, auto b) {return a->pos() + b*a->max();},
|
||||
0 );
|
||||
IB::mPos = sfor_p<0,sizeof...(Indices)>
|
||||
( [&](auto i) { return std::get<i>(mIPack); },
|
||||
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
|
@ -312,8 +281,16 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
RPackNum<DIR>::pp( mIPack );
|
||||
IB::mPos += sfor_p<DIR,sizeof...(Indices)>
|
||||
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
||||
[&](auto a, auto b) { return a * b; } );
|
||||
sfor_m<DIR+1,0>
|
||||
( [&](auto i) {
|
||||
auto& si = *std::get<i>( mIPack );
|
||||
if(si.last() and i != 0) { si = 0; return true; }
|
||||
else { ++si; return false; }
|
||||
return false;
|
||||
} );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -322,8 +299,16 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::down()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
RPackNum<DIR>::mm( mIPack );
|
||||
IB::mPos -= sfor_p<DIR,sizeof...(Indices)>
|
||||
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
||||
[&](auto a, auto b) { return a * b; } );
|
||||
sfor_m<DIR+1,0>
|
||||
( [&](auto i) {
|
||||
auto& si = *std::get<i>( mIPack );
|
||||
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
||||
else { --si; return false; }
|
||||
return false;
|
||||
} );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -374,7 +359,13 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
sfor_m<sizeof...(Indices),0>
|
||||
( [&](auto i) {
|
||||
auto& si = *std::get<i>( mIPack );
|
||||
if(si.last() and i != 0) { si = 0; return true; }
|
||||
else { ++si; return false; }
|
||||
return false;
|
||||
} );
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
@ -382,15 +373,22 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
sfor_m<sizeof...(Indices),0>
|
||||
( [&](auto i) {
|
||||
auto& si = *std::get<i>( mIPack );
|
||||
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
||||
else { --si; return false; }
|
||||
return false;
|
||||
} );
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <class... Indices>
|
||||
int MultiIndex<Indices...>::pp(std::intptr_t idxPtrNum)
|
||||
{
|
||||
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
||||
const int tmp = ppx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||
IB::mPos += tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
@ -398,7 +396,7 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
int MultiIndex<Indices...>::mm(std::intptr_t idxPtrNum)
|
||||
{
|
||||
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
||||
const int tmp = mmx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||
IB::mPos -= tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
@ -421,7 +419,10 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
|
||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||
( [&](auto i) { return std::get<i>(mIPack); },
|
||||
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||
//IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -467,28 +468,9 @@ namespace MultiArrayTools
|
|||
return mBlockSizes[n+1];
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
std::string MultiIndex<Indices...>::id() const
|
||||
{
|
||||
return std::string("mul") + std::to_string(IB::mId);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
void MultiIndex<Indices...>::print(size_t offset)
|
||||
{
|
||||
if(offset == 0){
|
||||
std::cout << " === " << std::endl;
|
||||
}
|
||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
||||
<< "]" << "(" << IB::mRangePtr << "): " << meta() << std::endl;
|
||||
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <class Exprs>
|
||||
auto MultiIndex<Indices...>::ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
@ -496,7 +478,6 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
template <class Exprs>
|
||||
auto MultiIndex<Indices...>::iforh(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
@ -504,7 +485,6 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
template <class Exprs>
|
||||
auto MultiIndex<Indices...>::pifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
|
|
@ -42,78 +42,6 @@ namespace MultiArrayHelper
|
|||
RPackNum<N-1>::initBlockSizes(bs, ip);
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
template <class... Indices>
|
||||
inline void RPackNum<N>::pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<N>(ip);
|
||||
if(si.last()){
|
||||
si = 0;
|
||||
RPackNum<N-1>::pp(ip);
|
||||
}
|
||||
else {
|
||||
++si;
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
template <class... Indices>
|
||||
inline int RPackNum<N>::pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum)
|
||||
{
|
||||
auto& siPtr = std::get<N>(ip);
|
||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||
return RPackNum<N-1>::pp(ip, bs, idxPtrNum);
|
||||
}
|
||||
else {
|
||||
int tmp = siPtr->pp(idxPtrNum);
|
||||
if(siPtr->pos() == siPtr->max()){
|
||||
(*siPtr) = 0;
|
||||
return RPackNum<N-1>::pp(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||
}
|
||||
else {
|
||||
return tmp * std::get<N+1>(bs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
template <class... Indices>
|
||||
inline void RPackNum<N>::mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<N>(ip);
|
||||
if(si.first()){
|
||||
si = si.max() - 1;
|
||||
RPackNum<N-1>::mm(ip);
|
||||
}
|
||||
else {
|
||||
--si;
|
||||
}
|
||||
}
|
||||
|
||||
// !!!!
|
||||
template <size_t N>
|
||||
template <class... Indices>
|
||||
inline int RPackNum<N>::mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum)
|
||||
{
|
||||
auto& siPtr = std::get<N>(ip);
|
||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||
return std::get<N>(bs) + RPackNum<N-1>::mm(ip, bs, idxPtrNum);
|
||||
}
|
||||
else {
|
||||
if(siPtr->first()){
|
||||
(*siPtr) = siPtr->max() - 1;
|
||||
return RPackNum<N-1>::mm(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||
}
|
||||
else {
|
||||
return siPtr->mm(idxPtrNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
template <class RangeTuple>
|
||||
size_t RPackNum<N>::getSize(const RangeTuple& rt)
|
||||
|
@ -256,14 +184,6 @@ namespace MultiArrayHelper
|
|||
RPackNum<N-1>::RangesToVec(rst, v);
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
template <class... Indices>
|
||||
void RPackNum<N>::printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset)
|
||||
{
|
||||
std::get<N>(ip)->print(offset);
|
||||
RPackNum<N-1>::printIndex(ip, offset);
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
template <class Range, class... Ranges>
|
||||
void RPackNum<N>::checkDefaultable()
|
||||
|
@ -424,50 +344,6 @@ namespace MultiArrayHelper
|
|||
std::get<0>(bs) = RPackNum<sizeof...(Indices)>::blockSize(ip);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
inline void RPackNum<0>::pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<0>(ip);
|
||||
++si;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
inline int RPackNum<0>::pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum)
|
||||
{
|
||||
auto& siPtr = std::get<0>(ip);
|
||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||
return std::get<0>(bs);
|
||||
}
|
||||
else {
|
||||
int tmp = siPtr->pp(idxPtrNum);
|
||||
return tmp * std::get<1>(bs);
|
||||
}
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
inline void RPackNum<0>::mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<0>(ip);
|
||||
--si;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
inline int RPackNum<0>::mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum)
|
||||
{
|
||||
auto& siPtr = std::get<0>(ip);
|
||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||
return std::get<0>(bs);
|
||||
//return 1;
|
||||
}
|
||||
else {
|
||||
return siPtr->mm(idxPtrNum);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RangeTuple>
|
||||
size_t RPackNum<0>::getSize(const RangeTuple& rt)
|
||||
{
|
||||
|
@ -582,12 +458,6 @@ namespace MultiArrayHelper
|
|||
setRangeToVec(v, std::get<0>(rst));
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
void RPackNum<0>::printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset)
|
||||
{
|
||||
std::get<0>(ip)->print(offset);
|
||||
}
|
||||
|
||||
template <class Range>
|
||||
void RPackNum<0>::checkDefaultable()
|
||||
{
|
||||
|
|
|
@ -13,6 +13,57 @@ namespace MultiArrayHelper
|
|||
{
|
||||
using namespace MultiArrayTools;
|
||||
|
||||
template <size_t I, class... Indices>
|
||||
int ppx(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum)
|
||||
{
|
||||
auto& siPtr = std::get<I>(ip);
|
||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||
if constexpr(I != 0){
|
||||
return ppx<I-1>(ip, bs, idxPtrNum);
|
||||
}
|
||||
else {
|
||||
return std::get<0>(bs);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const int tmp = siPtr->pp(idxPtrNum);
|
||||
if constexpr(I != 0){
|
||||
if(siPtr->pos() == siPtr->max()){
|
||||
(*siPtr) = 0;
|
||||
return ppx<I-1>(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||
}
|
||||
}
|
||||
return tmp * std::get<I+1>(bs);
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t I, class... Indices>
|
||||
int mmx(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum)
|
||||
{
|
||||
auto& siPtr = std::get<I>(ip);
|
||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||
if constexpr(I != 0){
|
||||
return mmx<I-1>(ip, bs, idxPtrNum);
|
||||
}
|
||||
else {
|
||||
return std::get<0>(bs);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const int tmp = siPtr->mm(idxPtrNum);
|
||||
if constexpr(I != 0){
|
||||
if(siPtr->pos() == siPtr->max()){
|
||||
(*siPtr) = siPtr->max() - 1;
|
||||
return mmx<I-1>(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||
}
|
||||
}
|
||||
return tmp * std::get<I+1>(bs);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Index1>
|
||||
size_t mkTotalDim();
|
||||
|
@ -54,23 +105,6 @@ namespace MultiArrayHelper
|
|||
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||
|
||||
template <class... Indices>
|
||||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||
|
||||
template <class... Indices>
|
||||
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum);
|
||||
|
||||
template <class... Indices>
|
||||
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||
|
||||
// !!!!
|
||||
template <class... Indices>
|
||||
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum);
|
||||
|
||||
template <class RangeTuple>
|
||||
static size_t getSize(const RangeTuple& rt);
|
||||
|
||||
|
@ -125,9 +159,6 @@ namespace MultiArrayHelper
|
|||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||
vector<std::intptr_t>& v);
|
||||
|
||||
template <class... Indices>
|
||||
static void printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset);
|
||||
|
||||
template <class Range, class... Ranges>
|
||||
static void checkDefaultable();
|
||||
|
||||
|
@ -195,22 +226,6 @@ namespace MultiArrayHelper
|
|||
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||
|
||||
template <class... Indices>
|
||||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||
|
||||
template <class... Indices>
|
||||
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum);
|
||||
|
||||
template <class... Indices>
|
||||
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||
|
||||
template <class... Indices>
|
||||
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::intptr_t idxPtrNum);
|
||||
|
||||
template <class RangeTuple>
|
||||
static size_t getSize(const RangeTuple& rt);
|
||||
|
||||
|
@ -263,9 +278,6 @@ namespace MultiArrayHelper
|
|||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||
vector<std::shared_ptr<RangeBase> >& v);
|
||||
|
||||
template <class... Indices>
|
||||
static void printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset);
|
||||
|
||||
template <class Range>
|
||||
static void checkDefaultable();
|
||||
|
||||
|
|
|
@ -79,9 +79,6 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n);
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
auto ifor(size_t step, Expr ex) const
|
||||
-> For<GenSingleIndex<U,TYPE,S>,Expr>;
|
||||
|
@ -492,23 +489,6 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
template <typename U, SpaceType TYPE, size_t S>
|
||||
std::string GenSingleIndex<U,TYPE,S>::id() const
|
||||
{
|
||||
return std::string("sin") + std::to_string(IB::mId);
|
||||
}
|
||||
|
||||
template <typename U, SpaceType TYPE, size_t S>
|
||||
void GenSingleIndex<U,TYPE,S>::print(size_t offset)
|
||||
{
|
||||
if(offset == 0){
|
||||
std::cout << " === " << std::endl;
|
||||
}
|
||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
||||
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
|
||||
}
|
||||
|
||||
template <typename U, SpaceType TYPE, size_t S>
|
||||
template <class Expr>
|
||||
auto GenSingleIndex<U,TYPE,S>::ifor(size_t step, Expr ex) const
|
||||
|
|
|
@ -71,9 +71,6 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n);
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
auto ifor(size_t step, Expr ex) const
|
||||
-> For<SubIndex<Index>,SubExpr<Index,Expr>>;
|
||||
|
@ -302,23 +299,6 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
template <class Index>
|
||||
std::string SubIndex<Index>::id() const
|
||||
{
|
||||
return std::string("sub") + std::to_string(IB::mId);
|
||||
}
|
||||
|
||||
template <class Index>
|
||||
void SubIndex<Index>::print(size_t offset)
|
||||
{
|
||||
if(offset == 0){
|
||||
std::cout << " === " << std::endl;
|
||||
}
|
||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
||||
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
|
||||
}
|
||||
|
||||
template <class Index>
|
||||
template <class Expr>
|
||||
auto SubIndex<Index>::ifor(size_t step, Expr ex) const
|
||||
|
|
|
@ -69,9 +69,6 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n);
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
auto ifor(size_t step, Expr ex) const
|
||||
-> For<ValueIndex<U>,Expr>;
|
||||
|
@ -275,23 +272,6 @@ namespace MultiArrayTools
|
|||
return 1;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
std::string ValueIndex<U>::id() const
|
||||
{
|
||||
return std::string("val") + std::to_string(IB::mId);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void ValueIndex<U>::print(size_t offset)
|
||||
{
|
||||
if(offset == 0){
|
||||
std::cout << " === " << std::endl;
|
||||
}
|
||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
||||
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
template <class Expr>
|
||||
auto ValueIndex<U>::ifor(size_t step, Expr ex) const
|
||||
|
|
|
@ -6,6 +6,20 @@
|
|||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
template <size_t BEG, size_t END, int OFF, typename Incr, typename F>
|
||||
inline void sfor(Incr incr, F f)
|
||||
{
|
||||
constexpr auto idx = std::integral_constant<size_t, BEG>{};
|
||||
constexpr auto idxm = std::integral_constant<size_t, BEG+OFF>{};
|
||||
|
||||
const bool cond = f(idxm);
|
||||
if constexpr(incr(idx) != END){
|
||||
if(cond){
|
||||
sfor<incr(idx),END,OFF>(incr,f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, int OFF, typename Incr, typename F, typename Conc>
|
||||
inline auto sfor(Incr incr, F f, Conc conc)
|
||||
{
|
||||
|
@ -14,7 +28,7 @@ namespace MultiArrayTools
|
|||
//static_assert(abs(idx.value - END) >= abs(incr(idx) - END),
|
||||
// "this turns out to be a static endless loop");
|
||||
auto tmp = f(idxm);
|
||||
if constexpr(incr(idx) >= END){
|
||||
if constexpr(incr(idx) == END){
|
||||
return tmp;
|
||||
}
|
||||
else {
|
||||
|
@ -30,7 +44,7 @@ namespace MultiArrayTools
|
|||
//static_assert(abs(idx.value - END) >= abs(incr(idx) - END),
|
||||
// "this turns out to be a static endless loop");
|
||||
auto tmp = f(idxm);
|
||||
if constexpr(incr(idx) >= END){
|
||||
if constexpr(incr(idx) == END){
|
||||
return conc(tmp, arg);
|
||||
}
|
||||
else {
|
||||
|
@ -45,7 +59,7 @@ namespace MultiArrayTools
|
|||
constexpr auto idxm = std::integral_constant<size_t, BEG+OFF>{};
|
||||
//static_assert(abs(idx.value - END) >= abs(incr(idx) - END),
|
||||
// "this turns out to be a static endless loop");
|
||||
if constexpr(BEG >= END){
|
||||
if constexpr(BEG == END){
|
||||
return create(args...);
|
||||
}
|
||||
else {
|
||||
|
@ -56,9 +70,78 @@ namespace MultiArrayTools
|
|||
|
||||
}
|
||||
|
||||
#define MA_INC [&](auto i) constexpr { return i+1; }
|
||||
#define MA_DEC [&](auto i) constexpr { return i-1; }
|
||||
#define MA_ZCONC [&](auto a, auto b) { return 0; }
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
template <size_t BEG, size_t END, typename F>
|
||||
inline auto sfor_p(F f)
|
||||
{
|
||||
return sfor<BEG,END,0>(MA_INC,f);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F>
|
||||
inline auto sfor_m(F f)
|
||||
{
|
||||
return sfor<BEG,END,-1>(MA_DEC,f);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F, typename Conc>
|
||||
inline auto sfor_p(F f, Conc conc)
|
||||
{
|
||||
return sfor<BEG,END,0>(MA_INC,f,conc);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F>
|
||||
inline auto sfor_pn(F f)
|
||||
{
|
||||
return sfor_p<BEG,END>(f,MA_ZCONC);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F, typename Conc>
|
||||
inline auto sfor_m(F f, Conc conc)
|
||||
{
|
||||
return sfor<BEG,END,-1>(MA_DEC,f,conc);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F>
|
||||
inline auto sfor_mn(F f)
|
||||
{
|
||||
return sfor_m<BEG,END>(f,MA_ZCONC);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F, typename Conc, typename Arg>
|
||||
inline auto sfor_p(F f, Conc conc, const Arg& arg)
|
||||
{
|
||||
return sfor<BEG,END,0>(MA_INC,f,conc,arg);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F, typename Arg>
|
||||
inline auto sfor_pn(F f, const Arg& arg)
|
||||
{
|
||||
return sfor_p<BEG,END>(f,MA_ZCONC,arg);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F, typename Conc, typename Arg>
|
||||
inline auto sfor_m(F f, Conc conc, const Arg& arg)
|
||||
{
|
||||
return sfor<BEG,END,-1>(MA_DEC,f,conc,arg);
|
||||
}
|
||||
|
||||
template <size_t BEG, size_t END, typename F, typename Arg>
|
||||
inline auto sfor_mn(F f, const Arg& arg)
|
||||
{
|
||||
return sfor_m<BEG,END>(f,MA_ZCONC,arg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define MA_SFOR(i,beg,end,incr,expr) sfor<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ expr return 0; }, [&](auto f, auto next) { return 0; })
|
||||
#define MA_SCFOR(i,beg,end,incr,expr,conc) sfor<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); })
|
||||
#define MA_SCFOR2(i,beg,end,incr,expr,conc) sfor<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, [&](auto a, auto b) { return conc(a,b); })
|
||||
#define MA_SCFOR3(i,beg,end,incr,expr,conc) sfor<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, conc)
|
||||
#define MA_SRFOR(i,beg,end,decr,expr) sfor<beg,end,-1>([&](auto i) constexpr { return decr; }, [&](auto i){ expr return 0; }, [&](auto f, auto next) { return 0; })
|
||||
#define MA_SCRFOR(i,beg,end,decr,expr,conc) sfor<beg,end,-1>([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); })
|
||||
#define MA_SCRAFOR(i,beg,end,decr,expr,conc,arg) sfor<beg,end,-1>([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }, arg)
|
||||
|
|
|
@ -304,23 +304,6 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
|
||||
std::string DynamicIndex::id() const
|
||||
{
|
||||
return std::string("dyn") + std::to_string(IB::mId);
|
||||
}
|
||||
|
||||
|
||||
void DynamicIndex::print(size_t offset)
|
||||
{
|
||||
if(offset == 0){
|
||||
std::cout << " === " << std::endl;
|
||||
}
|
||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
||||
<< "](" << IB::mRangePtr << "): " /*<< meta().first*/ << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/***********************
|
||||
* DynamicRange *
|
||||
***********************/
|
||||
|
|
Loading…
Reference in a new issue