map range: use meta data of the output range + little fixes

This commit is contained in:
Christian Zimmermann 2019-04-02 19:39:11 +02:00
parent 844c7ef8e1
commit 505237c958
4 changed files with 80 additions and 65 deletions

View file

@ -14,9 +14,9 @@ namespace MultiArrayTools
* OpExpr *
**************/
template <class Op, class IndexPack, class Expr, SpaceType STYPE>
OpExpr<Op,IndexPack,Expr,STYPE>::OpExpr(const Op& mapf, const IndexPack& ipack,
const std::shared_ptr<OIType>& oind, size_t step, Expr ex) :
template <class Op, class Expr, SpaceType STYPE>
OpExpr<Op,Expr,STYPE>::OpExpr(const Op& mapf, const std::shared_ptr<OIType>& oind,
size_t step, Expr ex) :
mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mStep(step), mExpr( ex ),
mOp(mapf),
@ -27,9 +27,9 @@ namespace MultiArrayTools
assert(mIndPtr != nullptr);
}
template <class Op, class IndexPack, class Expr, SpaceType STYPE>
inline void OpExpr<Op,IndexPack,Expr,STYPE>::operator()(size_t mlast,
ExtType last)
template <class Op, class Expr, SpaceType STYPE>
inline void OpExpr<Op,Expr,STYPE>::operator()(size_t mlast,
ExtType last)
{
constexpr size_t NEXT = Op::SIZE;
const ExtType nxpos = last;
@ -41,8 +41,8 @@ namespace MultiArrayTools
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
}
template <class Op, class IndexPack, class Expr, SpaceType STYPE>
inline void OpExpr<Op,IndexPack,Expr,STYPE>::operator()(size_t mlast)
template <class Op, class Expr, SpaceType STYPE>
inline void OpExpr<Op,Expr,STYPE>::operator()(size_t mlast)
{
const ExtType last;
constexpr size_t NEXT = Op::SIZE;
@ -53,8 +53,8 @@ namespace MultiArrayTools
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
}
template <class Op, class IndexPack, class Expr, SpaceType STYPE>
auto OpExpr<Op,IndexPack,Expr,STYPE>::rootSteps(std::intptr_t iPtrNum) const
template <class Op, class Expr, SpaceType STYPE>
auto OpExpr<Op,Expr,STYPE>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mOp.rootSteps(iPtrNum).extend( mExpr.rootSteps(iPtrNum) );
@ -91,7 +91,7 @@ namespace MultiArrayTools
template <class Op, SpaceType XSTYPE, class... Indices>
template <class MRange>
GenMapIndex<Op,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>,typename Op::value_type>(range, 0)
{
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
@ -158,41 +158,48 @@ namespace MultiArrayTools
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator=(size_t pos)
{
IB::mPos = pos;
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
(*mOutIndex) = pos;
IB::mPos = mOutIndex->pos();
//RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator++()
{
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
++IB::mPos;
//RPackNum<sizeof...(Indices)-1>::pp( mIPack );
++(*mOutIndex);
IB::mPos = mOutIndex->pos();
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator--()
{
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
--IB::mPos;
//RPackNum<sizeof...(Indices)-1>::mm( mIPack );
--(*mOutIndex);
IB::mPos = mOutIndex->pos();
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
int GenMapIndex<Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
{
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
IB::mPos += tmp;
return tmp;
//int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
mOutIndex->pp(idxPtrNum);
IB::mPos = mOutIndex->pos();
//IB::mPos += tmp;
return 1;
}
template <class Op, SpaceType XSTYPE, class... Indices>
int GenMapIndex<Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
{
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
IB::mPos -= tmp;
return tmp;
//int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
mOutIndex->mm(idxPtrNum);
IB::mPos = mOutIndex->pos();
//IB::mPos -= tmp;
return 1;
}
template <class Op, SpaceType XSTYPE, class... Indices>
@ -204,16 +211,19 @@ namespace MultiArrayTools
template <class Op, SpaceType XSTYPE, class... Indices>
typename GenMapIndex<Op,XSTYPE,Indices...>::MetaType GenMapIndex<Op,XSTYPE,Indices...>::meta() const
{
MetaType metaTuple;
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
return metaTuple;
//MetaType metaTuple;
//RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
//assert(0);
return mOutIndex->meta();
}
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::at(const MetaType& metaPos)
{
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
//RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
//IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
mOutIndex->at(metaPos);
IB::mPos = mOutIndex->pos();
return *this;
}
@ -281,12 +291,12 @@ namespace MultiArrayTools
template <class Exprs>
auto GenMapIndex<Op,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<Op,IndexPack,Exprs,XSTYPE>
( range()->map(), mIPack, mOutIndex, step, exs ) ) )
(step, mIPack, mBlockSizes, OpExpr<Op,Exprs,XSTYPE>
( range()->map(), mOutIndex, step, exs ) ) )
{
return RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<Op,IndexPack,Exprs,XSTYPE>
( range()->map(), mIPack, mOutIndex, step, exs ) );
(step, mIPack, mBlockSizes, OpExpr<Op,Exprs,XSTYPE>
( range()->map(), mOutIndex, step, exs ) );
}
template <class Op, SpaceType XSTYPE, class... Indices>
@ -297,15 +307,14 @@ namespace MultiArrayTools
return ifor(step, exs);
}
/*
template <class Op, SpaceType XSTYPE, class... Indices>
template <class Exprs>
auto GenMapIndex<Op,XSTYPE,Indices...>::iforh(Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
auto GenMapIndex<Op,XSTYPE,Indices...>::iforh(size_t step, Exprs exs) const
-> decltype(ifor(step, exs))
{
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
return ifor(step, exs);
}
*/
/*************************
* MapRangeFactory *
*************************/

View file

@ -48,14 +48,12 @@ namespace MultiArrayTools
template <class Op, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
template <class Op, class Expr, SpaceType STYPE = SpaceType::ANY>
//template <class MapF, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
class OpExpr
{
public:
//typedef decltype(mkMapOp(std::declval<MapF>(), std::declval<IndexPack>())) Op;
typedef SingleIndex<typename Op::value_type,STYPE> OIType;
//typedef typename MapF::IndexPack IndexPack;
static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE + Op::SIZE;
@ -78,8 +76,7 @@ namespace MultiArrayTools
OpExpr& operator=(const OpExpr& in) = default;
OpExpr& operator=(OpExpr&& in) = default;
OpExpr(const Op& mapf, const IndexPack& ipack, const std::shared_ptr<OIType>& oind, size_t step, Expr ex);
//OpExpr(const MapF& mapf, const IndexPack& ipack, const std::shared_ptr<OIType>& oind, size_t step, Expr ex);
OpExpr(const Op& mapf, const std::shared_ptr<OIType>& oind, size_t step, Expr ex);
inline void operator()(size_t mlast, ExtType last);
inline void operator()(size_t mlast = 0);
@ -90,14 +87,17 @@ namespace MultiArrayTools
template <class Op, SpaceType XSTYPE, class... Indices>
class GenMapIndex : public IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>,
std::tuple<typename Indices::MetaType...> >
typename Op::value_type>
//std::tuple<typename Indices::MetaType...> >
{
public:
typedef IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>,
std::tuple<typename Indices::MetaType...> > IB;
typename Op::value_type> IB;
//std::tuple<typename Indices::MetaType...> > IB;
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
typedef std::tuple<typename Indices::MetaType...> MetaType;
//typedef std::tuple<typename Indices::MetaType...> MetaType;
typedef typename Op::value_type MetaType;
typedef GenMapRange<Op,XSTYPE,typename Indices::RangeType...> RangeType;
typedef GenMapIndex IType;
typedef SingleIndex<typename Op::value_type,XSTYPE> OIType;
@ -184,18 +184,18 @@ namespace MultiArrayTools
template <class Exprs>
auto ifor(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<Op,IndexPack,Exprs,XSTYPE>( range()->map(), mIPack, mOutIndex, step, exs ) ) );
(step, mIPack, mBlockSizes, OpExpr<Op,Exprs,XSTYPE>( range()->map(), mOutIndex, step, exs ) ) );
// first step arg not used!
template <class Exprs>
auto pifor(size_t step, Exprs exs) const
-> decltype(ifor(step, exs)); // NO MULTITHREADING
/*
template <class Exprs>
auto iforh(Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
*/
auto iforh(size_t step, Exprs exs) const
-> decltype(ifor(step, exs));
};
@ -241,6 +241,7 @@ namespace MultiArrayTools
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 RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
protected:

View file

@ -68,12 +68,14 @@ namespace MultiArrayTools
// CHECK / IMPLEMENT !!!!!!
template <class Expr>
auto ifor(const Expr ex) const -> decltype(THIS().template ifor<Expr>(ex))
{ return THIS().template ifor<Expr>(ex); }
auto ifor(size_t step, const Expr ex) const
-> decltype(THIS().template ifor<Expr>(step,ex))
{ return THIS().template ifor<Expr>(step,ex); }
template <class Expr>
auto iforh(const Expr ex) const -> decltype(THIS().template iforh<Expr>(ex))
{ return THIS().template iforh<Expr>(ex); }
auto iforh(size_t step, const Expr ex) const
-> decltype(THIS().template iforh<Expr>(step,ex))
{ return THIS().template iforh<Expr>(step,ex); }
std::intptr_t ptrNum() const;

View file

@ -107,6 +107,16 @@ namespace MultiArrayTools
template <class Range>
class SubRange : public RangeInterface<SubIndex<typename Range::IndexType>>
{
private:
SubRange() = delete;
SubRange(const SubRange& in) = delete;
SubRange(const std::shared_ptr<Range>& fullRange, const vector<size_t>& subset);
std::shared_ptr<Range> mFullRange;
vector<size_t> mSubSet;
public:
typedef RangeBase RB;
typedef SubIndex<typename Range::IndexType> IndexType;
@ -128,7 +138,8 @@ namespace MultiArrayTools
bool isMeta(const MetaType& metaPos) const;
const MetaType& get(size_t pos) const;
auto get(size_t pos) const
-> decltype(mFullRange->get(mSubSet[pos]));
size_t getMeta(const MetaType& metaPos) const;
virtual IndexType begin() const final;
@ -145,15 +156,6 @@ namespace MultiArrayTools
static constexpr size_t SIZE = -1;
static constexpr bool HASMETACONT = false;
private:
SubRange() = delete;
SubRange(const SubRange& in) = delete;
SubRange(const std::shared_ptr<Range>& fullRange, const vector<size_t>& subset);
std::shared_ptr<Range> mFullRange;
vector<size_t> mSubSet;
};
} // namespace MultiArrayTools
@ -457,7 +459,8 @@ namespace MultiArrayTools
}
template <class Range>
const typename SubRange<Range>::MetaType& SubRange<Range>::get(size_t pos) const
auto SubRange<Range>::get(size_t pos) const
-> decltype(mFullRange->get(mSubSet[pos]))
{
return mFullRange->get( mSubSet[pos] );
}