bugfix + continue prev com

This commit is contained in:
Christian Zimmermann 2021-05-07 17:35:59 +02:00
parent 482a7a7b4e
commit 43e8486354
7 changed files with 126 additions and 297 deletions

View file

@ -114,82 +114,53 @@ namespace MultiArrayTools
namespace namespace
{ {
template <size_t N> template <size_t N, class... Indices>
struct Create struct Create
{ {
template <class... Indices> template <class ROP, class OpF, class... OPs>
struct cx struct ccx
{ {
template <class ROP, class OpF, class... OPs> template <size_t M, class... DOPs>
struct ccx static inline void
{ cccx(typename HighLevelOpBase<ROP>::template RetT<Indices...>& res,
template <size_t M, class... DOPs> const std::array<std::shared_ptr<HighLevelOpBase<ROP>>,M>& in,
static inline void const std::shared_ptr<Indices>&... inds,
cccx(typename HighLevelOpBase<ROP>::template RetT<Indices...>& res, const OPs&... ops,
const std::array<std::shared_ptr<HighLevelOpBase<ROP>>,M>& in, const DOPs&... dops)
const std::shared_ptr<Indices>&... inds, {
const OPs&... ops, //static_assert(N > 0, "N > 0 failed");
const DOPs&... dops) auto& inn = std::get<N>(in);
{ if(not inn->root()){
static_assert(N > 0, "N > 0 failed"); auto dop = inn->create(inds...);
auto& inn = std::get<N>(in); auto op = *dop.op.data()->mOp;
if(not inn->root()){ res.appendOuter(dop);
auto dop = inn->create(inds...); assert(dop.op.init());
auto op = *dop.op.data()->mOp; if constexpr(N > 0){
typedef decltype(op) OP; typedef decltype(op) OP;
res.appendOuter(dop); Create<N-1,Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M>
assert(dop.op.init()); (res, in, inds..., op, ops..., dop, dops...);
Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M> }
(res, in, inds..., op, ops..., dop, dops...); else {
} res.op = mkDynOutOp(mkFOp<OpF>(op,ops...), inds...);
else { res.appendOuterM(dop.op,dops.op...);
auto op = inn->get(); }
auto vop = inn->vget(); }
typedef typename std::remove_reference<decltype(*op)>::type OP; else {
typedef typename std::remove_reference<decltype(*vop)>::type VOP; auto op = inn->get();
auto vop = inn->vget();
if constexpr(N > 0){
typedef typename std::remove_reference<decltype(*op)>::type OP;
typedef typename std::remove_reference<decltype(*vop)>::type VOP;
if(op != nullptr){ if(op != nullptr){
Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M> Create<N-1,Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M>
(res, in, inds..., *op, ops..., dops...); (res, in, inds..., *op, ops..., dops...);
} }
else { else {
Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,VOP,OPs...>::template cccx<M> Create<N-1,Indices...>::template ccx<ROP,OpF,VOP,OPs...>::template cccx<M>
(res, in, inds..., *vop, ops..., dops...); (res, in, inds..., *vop, ops..., dops...);
} }
} }
} else {
};
};
};
template <>
struct Create<0>
{
template <class... Indices>
struct cx
{
template <class ROP, class OpF, class... OPs>
struct ccx
{
template <size_t M, class... DOPs>
static inline void
cccx(typename HighLevelOpBase<ROP>::template RetT<Indices...>& res,
const std::array<std::shared_ptr<HighLevelOpBase<ROP>>,M>& in,
const std::shared_ptr<Indices>&... inds,
const OPs&... ops,
const DOPs&... dops)
{
auto& inn = std::get<0>(in);
if(not inn->root()){
auto dop = inn->create(inds...);
auto op = *dop.op.data()->mOp;
res.appendOuter(dop);
res.op = mkDynOutOp(mkFOp<OpF>(op,ops...), inds...);
assert(dop.op.init());
res.appendOuterM(dop.op,dops.op...);
}
else {
auto op = inn->get();
auto vop = inn->vget();
if(op != nullptr){ if(op != nullptr){
res.op = mkDynOutOp(mkFOp<OpF>(*op,ops...), inds...); res.op = mkDynOutOp(mkFOp<OpF>(*op,ops...), inds...);
} }
@ -197,11 +168,12 @@ namespace MultiArrayTools
res.op = mkDynOutOp(mkFOp<OpF>(*vop,ops...), inds...); res.op = mkDynOutOp(mkFOp<OpF>(*vop,ops...), inds...);
} }
res.appendOuterM(dops.op...); res.appendOuterM(dops.op...);
} }
} }
}; }
}; };
}; };
} }
template <class ROP, class OpF, size_t N> template <class ROP, class OpF, size_t N>
@ -234,7 +206,7 @@ namespace MultiArrayTools
-> typename B::template RetT<Inds...> -> typename B::template RetT<Inds...>
{ {
typename B::template RetT<Inds...> res; typename B::template RetT<Inds...> res;
Create<N-1>::template cx<Inds...>::template ccx<ROP,OpF>::template cccx<N> Create<N-1,Inds...>::template ccx<ROP,OpF>::template cccx<N>
(res,mIn,inds...); (res,mIn,inds...);
return res; return res;
} }

View file

@ -87,41 +87,31 @@ namespace MultiArrayTools
return std::make_shared<ExtT<ExtType>>(mExt); return std::make_shared<ExtT<ExtType>>(mExt);
} }
// -> define in range_base.cc
//std::shared_ptr<RangeFactoryBase> mkMULTI(const char** dp);
/****************** /******************
* MapIndex * * MapIndex *
******************/ ******************/
/*
template <class MapF, class... Indices>
MapIndex<MapF,Indices...>::MapIndex(const MapIndex<MapF,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 MapF, class... Indices>
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator=(const MapIndex<MapF,Indices...>& in)
{
IndexI::operator=(in);
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this;
}
*/
template <class OIType, class Op, SpaceType XSTYPE, class... Indices> template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <class MRange> template <class MRange>
GenMapIndex<OIType,Op,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) : GenMapIndex<OIType,Op,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
IndexInterface<GenMapIndex<OIType,Op,XSTYPE,Indices...>,typename Op::value_type>(range, 0) IndexInterface<GenMapIndex<OIType,Op,XSTYPE,Indices...>,typename Op::value_type>(range, 0)
{ {
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
std::get<sizeof...(Indices)>(mBlockSizes) = 1; std::get<sizeof...(Indices)>(mBlockSizes) = 1;
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack); // has one more element! 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_p<i,sizeof...(Indices)>
( [&](auto j) { return std::get<j>(mIPack)->max(); } ,
[&](auto a, auto b) { return a * b; });
return 0;
});
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 );
mOutIndex = std::make_shared<OIType> mOutIndex = std::make_shared<OIType>
( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() ); ( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() );
} }
@ -185,7 +175,18 @@ namespace MultiArrayTools
template <class OIType, class Op, SpaceType XSTYPE, class... Indices> template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator()(const std::shared_ptr<Indices>&... indices) GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator()(const std::shared_ptr<Indices>&... indices)
{ {
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...); //RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
//RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
return (*this)(std::make_tuple(indices...));
//return *this;
}
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& indices)
{
sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(indices); return 0; } );
//RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos); RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
return *this; return *this;
} }
@ -245,17 +246,12 @@ namespace MultiArrayTools
template <class OIType, class Op, SpaceType XSTYPE, class... Indices> template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
typename GenMapIndex<OIType,Op,XSTYPE,Indices...>::MetaType GenMapIndex<OIType,Op,XSTYPE,Indices...>::meta() const typename GenMapIndex<OIType,Op,XSTYPE,Indices...>::MetaType GenMapIndex<OIType,Op,XSTYPE,Indices...>::meta() const
{ {
//MetaType metaTuple;
//RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
//assert(0);
return mOutIndex->meta(); return mOutIndex->meta();
} }
template <class OIType, class Op, SpaceType XSTYPE, class... Indices> template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::at(const MetaType& metaPos) GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::at(const MetaType& metaPos)
{ {
//RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
//IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
mOutIndex->at(metaPos); mOutIndex->at(metaPos);
IB::mPos = mOutIndex->pos(); IB::mPos = mOutIndex->pos();
return *this; return *this;
@ -309,30 +305,9 @@ namespace MultiArrayTools
return mBlockSizes[n+1]; return mBlockSizes[n+1];
} }
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
std::string GenMapIndex<OIType,Op,XSTYPE,Indices...>::id() const
{
return std::string("mul") + std::to_string(IB::mId);
}
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
void GenMapIndex<OIType,Op,XSTYPE,Indices...>::print(size_t offset) const
{
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 OIType, class Op, SpaceType XSTYPE, class... Indices> template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <class Exprs> template <class Exprs>
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE>
( range()->map(), this, step, exs ) ) )
{ {
return RPackNum<sizeof...(Indices)-1>::mkForh return RPackNum<sizeof...(Indices)-1>::mkForh
(0, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE> (0, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE>
@ -342,7 +317,6 @@ namespace MultiArrayTools
template <class OIType, class Op, SpaceType XSTYPE, class... Indices> template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <class Exprs> template <class Exprs>
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::pifor(size_t step, Exprs exs) const auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::pifor(size_t step, Exprs exs) const
-> decltype(ifor(step, exs))
{ {
return ifor(step, exs); return ifor(step, exs);
} }
@ -350,7 +324,6 @@ namespace MultiArrayTools
template <class OIType, class Op, SpaceType XSTYPE, class... Indices> template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <class Exprs> template <class Exprs>
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::iforh(size_t step, Exprs exs) const auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::iforh(size_t step, Exprs exs) const
-> decltype(ifor(step, exs))
{ {
return ifor(step, exs); return ifor(step, exs);
} }
@ -600,7 +573,6 @@ namespace MultiArrayTools
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::size() const size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::size() const
{ {
return mOutRange->size(); return mOutRange->size();
//return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
} }
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges> template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
@ -629,7 +601,6 @@ namespace MultiArrayTools
//MetaType* xtarget = reinterpret_cast<MetaType*>(target); //MetaType* xtarget = reinterpret_cast<MetaType*>(target);
assert(0); assert(0);
return 0; return 0;
//return RPackNum<sizeof...(Ranges)-1>::getCMeta(xtarget,pos,mSpace,cmetaSize());
} }
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges> template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>

View file

@ -164,6 +164,7 @@ namespace MultiArrayTools
// NO foreign/external controll) // NO foreign/external controll)
// Do NOT share index instances between two or more MapIndex instances // Do NOT share index instances between two or more MapIndex instances
GenMapIndex& operator()(const std::shared_ptr<Indices>&... indices); GenMapIndex& operator()(const std::shared_ptr<Indices>&... indices);
GenMapIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& indices);
// ==== >>>>> STATIC POLYMORPHISM <<<<< ==== // ==== >>>>> STATIC POLYMORPHISM <<<<< ====
@ -192,23 +193,14 @@ namespace MultiArrayTools
size_t getStepSize(size_t n) const; size_t getStepSize(size_t n) const;
std::string id() const;
void print(size_t offset) const;
template <class Exprs> template <class Exprs>
auto ifor(size_t step, Exprs exs) const auto ifor(size_t step, Exprs exs) const; // first step arg not used!
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex,Exprs,XSTYPE>( range()->map(), this, step, exs ) ) );
// first step arg not used!
template <class Exprs> template <class Exprs>
auto pifor(size_t step, Exprs exs) const auto pifor(size_t step, Exprs exs) const; // NO MULTITHREADING
-> decltype(ifor(step, exs)); // NO MULTITHREADING
template <class Exprs> template <class Exprs>
auto iforh(size_t step, Exprs exs) const auto iforh(size_t step, Exprs exs) const;
-> decltype(ifor(step, exs));
}; };
@ -261,11 +253,7 @@ namespace MultiArrayTools
typedef RangeBase RB; typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> Space; typedef std::tuple<std::shared_ptr<Ranges>...> Space;
typedef GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...> IndexType; typedef GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...> IndexType;
//typedef GenMapRange RangeType;
//typedef SingleRange<typename Op::value_type,XSTYPE> ORType;
//typedef SingleRangeFactory<typename Op::value_type,XSTYPE> ORFType;
typedef typename Op::value_type MetaType; typedef typename Op::value_type MetaType;
//typedef typename RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
protected: protected:
GenMapRange() = delete; GenMapRange() = delete;

View file

@ -208,10 +208,22 @@ namespace MultiArrayTools
IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0), IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
mObjPtrNum(objPtrNum) mObjPtrNum(objPtrNum)
{ {
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
std::get<sizeof...(Indices)>(mBlockSizes) = 1; std::get<sizeof...(Indices)>(mBlockSizes) = 1;
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack); sfor_mn<sizeof...(Indices),0>
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack); ( [&](auto i) {
auto r = range->template getPtr<i>();
std::get<i>(mIPack) = r->beginPtr();
*std::get<i>(mIPack) = 0;
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;
});
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 );
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes); mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
} }
@ -223,9 +235,16 @@ namespace MultiArrayTools
IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0), IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
mObjPtrNum(objPtrNum) mObjPtrNum(objPtrNum)
{ {
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range); sfor_mn<sizeof...(Indices),0>
mBlockSizes = blockSizes; ( [&](auto i) {
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack); auto r = range->template getPtr<i>();
std::get<i>(mIPack) = r->beginPtr();
*std::get<i>(mIPack) = 0;
return 0;
});
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 );
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes); mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
mNonTrivialBlocks = true; mNonTrivialBlocks = true;
} }
@ -244,7 +263,9 @@ namespace MultiArrayTools
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::sync() ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::sync()
{ {
if(mExternControl){ if(mExternControl){
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 );
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes); mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
} }
return *this; return *this;
@ -267,15 +288,14 @@ namespace MultiArrayTools
template <typename T, class... Indices> template <typename T, class... Indices>
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()(const std::shared_ptr<Indices>&... inds) ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
{ {
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, inds...); return (*this)(std::make_tuple(inds...));
mExternControl = true;
return sync();
} }
template <typename T, class... Indices> template <typename T, class... Indices>
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& inds) ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& inds)
{ {
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, inds); sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(inds); return 0; } );
mExternControl = true; mExternControl = true;
return sync(); return sync();
} }
@ -293,7 +313,9 @@ namespace MultiArrayTools
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator++() ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator++()
{ {
if(mExternControl){ if(mExternControl){
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 );
} }
sfor_m<sizeof...(Indices),0> sfor_m<sizeof...(Indices),0>
( [&](auto i) { ( [&](auto i) {
@ -311,7 +333,9 @@ namespace MultiArrayTools
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator--() ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator--()
{ {
if(mExternControl){ if(mExternControl){
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 );
} }
sfor_m<sizeof...(Indices),0> sfor_m<sizeof...(Indices),0>
( [&](auto i) { ( [&](auto i) {
@ -361,14 +385,16 @@ namespace MultiArrayTools
typename ContainerIndex<T,Indices...>::MetaType ContainerIndex<T,Indices...>::meta() const typename ContainerIndex<T,Indices...>::MetaType ContainerIndex<T,Indices...>::meta() const
{ {
MetaType metaTuple; MetaType metaTuple;
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack); sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(metaTuple) = std::get<i>(mIPack)->meta(); return 0; } );
return metaTuple; return metaTuple;
} }
template <typename T, class... Indices> template <typename T, class... Indices>
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::at(const MetaType& metaPos) ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::at(const MetaType& metaPos)
{ {
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos); sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(mIPack)->at( std::get<i>(metaPos) ); return 0; } );
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes); IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
return *this; return *this;
} }

View file

@ -247,7 +247,7 @@ namespace MultiArrayTools
{ {
sfor_p<0,sizeof...(Indices)> sfor_p<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(mIPack) = ci.template getPtr<i>(); return true; } ); ( [&](auto i) { std::get<i>(mIPack) = ci.template getPtr<i>(); return true; } );
IB::mPos = sfor_p<0,sizeof...(Indices)> IB::mPos = sfor_m<sizeof...(Indices),0>
( [&](auto i) { return std::get<i>(mIPack); }, ( [&](auto i) { return std::get<i>(mIPack); },
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
return *this; return *this;
@ -271,7 +271,7 @@ namespace MultiArrayTools
return 0; return 0;
}); });
IB::mPos = sfor_p<0,sizeof...(Indices)> IB::mPos = sfor_m<sizeof...(Indices),0>
( [&](auto i) { return std::get<i>(mIPack); }, ( [&](auto i) { return std::get<i>(mIPack); },
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
} }
@ -329,15 +329,14 @@ namespace MultiArrayTools
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices) MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
{ {
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...); return (*this)(std::make_tuple(indices...));
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
return *this;
} }
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& indices) MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& indices)
{ {
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices); sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(indices); return 0; } );
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos); RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
return *this; return *this;
} }
@ -411,18 +410,19 @@ namespace MultiArrayTools
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const
{ {
MetaType metaTuple; MetaType metaTuple;
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack); sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(metaTuple) = std::get<i>(mIPack)->meta(); return 0; } );
return metaTuple; return metaTuple;
} }
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos) MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos)
{ {
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos); sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(mIPack)->at( std::get<i>(metaPos) ); return 0; } );
IB::mPos = sfor_m<sizeof...(Indices),0> IB::mPos = sfor_m<sizeof...(Indices),0>
( [&](auto i) { return std::get<i>(mIPack); }, ( [&](auto i) { return std::get<i>(mIPack); },
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 ); [&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
//IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this; return *this;
} }

View file

@ -33,15 +33,6 @@ namespace MultiArrayHelper
v.insert(v.begin(), r); v.insert(v.begin(), r);
} }
template <size_t N>
template <class... Indices>
void RPackNum<N>::initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
std::tuple<std::shared_ptr<Indices>...>& ip)
{
std::get<N>(bs) = RPackNum<sizeof...(Indices)-N>::blockSize(ip);
RPackNum<N-1>::initBlockSizes(bs, ip);
}
template <size_t N> template <size_t N>
template <class RangeTuple> template <class RangeTuple>
size_t RPackNum<N>::getSize(const RangeTuple& rt) size_t RPackNum<N>::getSize(const RangeTuple& rt)
@ -49,23 +40,6 @@ namespace MultiArrayHelper
return std::get<N>(rt)->size() * RPackNum<N-1>::getSize(rt); return std::get<N>(rt)->size() * RPackNum<N-1>::getSize(rt);
} }
template <size_t N>
template <class IndexPack, class MetaType>
void RPackNum<N>::getMetaPos(MetaType& target,
const IndexPack& source)
{
std::get<N>(target) = std::get<N>(source)->meta();
RPackNum<N-1>::getMetaPos(target, source);
}
template <size_t N>
template <class IndexPack, typename MetaType>
void RPackNum<N>::setMeta(IndexPack& target, const MetaType& source)
{
std::get<N>(target)->at( std::get<N>(source) );
RPackNum<N-1>::setMeta(target, source);
}
template <size_t N> template <size_t N>
template <class SpaceClass> template <class SpaceClass>
inline std::shared_ptr<RangeBase> RPackNum<N>::getSub(const SpaceClass& space, size_t num) inline std::shared_ptr<RangeBase> RPackNum<N>::getSub(const SpaceClass& space, size_t num)
@ -88,24 +62,6 @@ namespace MultiArrayHelper
RPackNum<N-1>::setIndexPack(iPack, (pos - ownPos) / i.max() ); RPackNum<N-1>::setIndexPack(iPack, (pos - ownPos) / i.max() );
} }
template <size_t N>
template <class MRange, class... Indices>
void RPackNum<N>::construct(std::tuple<std::shared_ptr<Indices>...>& ip,
const MRange& range)
{
typedef typename std::remove_reference<decltype(range.template get<N>())>::type SubRangeType;
typedef typename SubRangeType::IndexType SubIndexType;
typedef typename std::remove_reference<decltype(*std::get<N>(ip).get())>::type TypeFromIndexPack;
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
"inconsistent types");
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<N>() ) );
*std::get<N>(ip) = 0;
//VCHECK(std::get<N>(ip)->max());
RPackNum<N-1>::construct(ip, range);
}
template <size_t N> template <size_t N>
template <class IndexType, class... Indices> template <class IndexType, class... Indices>
void RPackNum<N>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip, void RPackNum<N>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
@ -125,14 +81,6 @@ namespace MultiArrayHelper
RPackNum<N-1>::copyIndex(ip, ind); RPackNum<N-1>::copyIndex(ip, ind);
} }
template <size_t N>
template <class... Indices>
inline size_t RPackNum<N>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
{
//const auto& idx = *std::get<N>(iPtrTup);
return std::get<N>(iPtrTup)->pos() + RPackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
}
template <size_t N> template <size_t N>
template <class... Indices> template <class... Indices>
inline size_t RPackNum<N>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup, inline size_t RPackNum<N>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
@ -337,32 +285,12 @@ namespace MultiArrayHelper
template <class... Indices>
void RPackNum<0>::initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
std::tuple<std::shared_ptr<Indices>...>& ip)
{
std::get<0>(bs) = RPackNum<sizeof...(Indices)>::blockSize(ip);
}
template <class RangeTuple> template <class RangeTuple>
size_t RPackNum<0>::getSize(const RangeTuple& rt) size_t RPackNum<0>::getSize(const RangeTuple& rt)
{ {
return std::get<0>(rt)->size(); return std::get<0>(rt)->size();
} }
template <class IndexPack, class MetaType>
void RPackNum<0>::getMetaPos(MetaType& target,
const IndexPack& source)
{
std::get<0>(target) = std::get<0>(source)->meta();
}
template <class IndexPack, typename MetaType>
void RPackNum<0>::setMeta(IndexPack& target, const MetaType& source)
{
std::get<0>(target)->at( std::get<0>( source ) );
}
template <class SpaceClass> template <class SpaceClass>
inline std::shared_ptr<RangeBase> RPackNum<0>::getSub(const SpaceClass& space, size_t num) inline std::shared_ptr<RangeBase> RPackNum<0>::getSub(const SpaceClass& space, size_t num)
{ {
@ -383,21 +311,6 @@ namespace MultiArrayHelper
i = ownPos; i = ownPos;
} }
template <class MRange, class... Indices>
void RPackNum<0>::construct(std::tuple<std::shared_ptr<Indices>...>& ip,
const MRange& range)
{
typedef typename std::remove_reference<decltype(range.template get<0>())>::type SubRangeType;
typedef typename SubRangeType::IndexType SubIndexType;
typedef typename std::remove_reference<decltype(*std::get<0>(ip).get())>::type TypeFromIndexPack;
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
"inconsistent types");
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<0>() ) );
*std::get<0>(ip) = 0;
}
template <class IndexType, class... Indices> template <class IndexType, class... Indices>
void RPackNum<0>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip, void RPackNum<0>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind) const IndexType& ind)
@ -413,12 +326,6 @@ namespace MultiArrayHelper
std::get<0>(ip) = std::make_shared<SubType>( ind.template get<0>() ) ; std::get<0>(ip) = std::make_shared<SubType>( ind.template get<0>() ) ;
} }
template <class... Indices>
inline size_t RPackNum<0>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
{
return std::get<0>(iPtrTup)->pos();
}
template <class... Indices> template <class... Indices>
inline size_t RPackNum<0>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup, inline size_t RPackNum<0>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
const std::array<size_t,sizeof...(Indices)+1>& blockSize) const std::array<size_t,sizeof...(Indices)+1>& blockSize)

View file

@ -101,30 +101,16 @@ namespace MultiArrayHelper
template <size_t N> template <size_t N>
struct RPackNum struct RPackNum
{ {
template <class... Indices>
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
std::tuple<std::shared_ptr<Indices>...>& ip);
template <class RangeTuple> template <class RangeTuple>
static size_t getSize(const RangeTuple& rt); static size_t getSize(const RangeTuple& rt);
template <class IndexPack, class MetaType>
static void getMetaPos(MetaType& target,
const IndexPack& source);
template <class IndexPack, typename MetaType>
static void setMeta(IndexPack& target, const MetaType& source);
template <class SpaceClass> template <class SpaceClass>
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num); inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num);
template <class IndexPack> template <class IndexPack>
static void setIndexPack(IndexPack& iPack, size_t pos); static void setIndexPack(IndexPack& iPack, size_t pos);
template <class MRange, class... Indices>
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
const MRange& range);
template <class IndexType, class... Indices> template <class IndexType, class... Indices>
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip, static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind); const IndexType& ind);
@ -133,9 +119,6 @@ namespace MultiArrayHelper
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip, static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind); const IndexType& ind);
template <class... Indices>
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup);
template <class... Indices> template <class... Indices>
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup, static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
const std::array<size_t,sizeof...(Indices)+1>& blockSize); const std::array<size_t,sizeof...(Indices)+1>& blockSize);
@ -222,30 +205,15 @@ namespace MultiArrayHelper
struct RPackNum<0> struct RPackNum<0>
{ {
template <class... Indices>
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
std::tuple<std::shared_ptr<Indices>...>& ip);
template <class RangeTuple> template <class RangeTuple>
static size_t getSize(const RangeTuple& rt); static size_t getSize(const RangeTuple& rt);
template <class IndexPack, class MetaType>
static void getMetaPos(MetaType& target,
const IndexPack& source);
template <class IndexPack, typename MetaType>
static void setMeta(IndexPack& target, const MetaType& source);
template <class SpaceClass> template <class SpaceClass>
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num); inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num);
template <class IndexPack> template <class IndexPack>
static void setIndexPack(IndexPack& iPack, size_t pos); static void setIndexPack(IndexPack& iPack, size_t pos);
template <class MRange, class... Indices>
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
const MRange& range);
template <class IndexType, class... Indices> template <class IndexType, class... Indices>
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip, static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind); const IndexType& ind);
@ -254,9 +222,6 @@ namespace MultiArrayHelper
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip, static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind); const IndexType& ind);
template <class... Indices>
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup);
template <class... Indices> template <class... Indices>
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup, static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
const std::array<size_t,sizeof...(Indices)+1>& blockSize); const std::array<size_t,sizeof...(Indices)+1>& blockSize);