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 * * OpExpr *
**************/ **************/
template <class Op, class IndexPack, class Expr, SpaceType STYPE> template <class Op, class Expr, SpaceType STYPE>
OpExpr<Op,IndexPack,Expr,STYPE>::OpExpr(const Op& mapf, const IndexPack& ipack, OpExpr<Op,Expr,STYPE>::OpExpr(const Op& mapf, const std::shared_ptr<OIType>& oind,
const std::shared_ptr<OIType>& oind, size_t step, Expr ex) : size_t step, Expr ex) :
mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mStep(step), mExpr( ex ), mStep(step), mExpr( ex ),
mOp(mapf), mOp(mapf),
@ -27,9 +27,9 @@ namespace MultiArrayTools
assert(mIndPtr != nullptr); assert(mIndPtr != nullptr);
} }
template <class Op, class IndexPack, class Expr, SpaceType STYPE> template <class Op, class Expr, SpaceType STYPE>
inline void OpExpr<Op,IndexPack,Expr,STYPE>::operator()(size_t mlast, inline void OpExpr<Op,Expr,STYPE>::operator()(size_t mlast,
ExtType last) ExtType last)
{ {
constexpr size_t NEXT = Op::SIZE; constexpr size_t NEXT = Op::SIZE;
const ExtType nxpos = last; const ExtType nxpos = last;
@ -41,8 +41,8 @@ namespace MultiArrayTools
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) ); mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
} }
template <class Op, class IndexPack, class Expr, SpaceType STYPE> template <class Op, class Expr, SpaceType STYPE>
inline void OpExpr<Op,IndexPack,Expr,STYPE>::operator()(size_t mlast) inline void OpExpr<Op,Expr,STYPE>::operator()(size_t mlast)
{ {
const ExtType last; const ExtType last;
constexpr size_t NEXT = Op::SIZE; constexpr size_t NEXT = Op::SIZE;
@ -53,8 +53,8 @@ namespace MultiArrayTools
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos )); mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
} }
template <class Op, class IndexPack, class Expr, SpaceType STYPE> template <class Op, class Expr, SpaceType STYPE>
auto OpExpr<Op,IndexPack,Expr,STYPE>::rootSteps(std::intptr_t iPtrNum) const auto OpExpr<Op,Expr,STYPE>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType -> ExtType
{ {
return mOp.rootSteps(iPtrNum).extend( mExpr.rootSteps(iPtrNum) ); return mOp.rootSteps(iPtrNum).extend( mExpr.rootSteps(iPtrNum) );
@ -91,7 +91,7 @@ namespace MultiArrayTools
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
template <class MRange> template <class MRange>
GenMapIndex<Op,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) : 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); RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
@ -158,41 +158,48 @@ namespace MultiArrayTools
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator=(size_t pos) GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator=(size_t pos)
{ {
IB::mPos = pos; (*mOutIndex) = pos;
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos); IB::mPos = mOutIndex->pos();
//RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
return *this; return *this;
} }
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator++() GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator++()
{ {
RPackNum<sizeof...(Indices)-1>::pp( mIPack ); //RPackNum<sizeof...(Indices)-1>::pp( mIPack );
++IB::mPos; ++(*mOutIndex);
IB::mPos = mOutIndex->pos();
return *this; return *this;
} }
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator--() GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator--()
{ {
RPackNum<sizeof...(Indices)-1>::mm( mIPack ); //RPackNum<sizeof...(Indices)-1>::mm( mIPack );
--IB::mPos; --(*mOutIndex);
IB::mPos = mOutIndex->pos();
return *this; return *this;
} }
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
int GenMapIndex<Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum) int GenMapIndex<Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
{ {
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum); //int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
IB::mPos += tmp; mOutIndex->pp(idxPtrNum);
return tmp; IB::mPos = mOutIndex->pos();
//IB::mPos += tmp;
return 1;
} }
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
int GenMapIndex<Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum) int GenMapIndex<Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
{ {
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum); //int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
IB::mPos -= tmp; mOutIndex->mm(idxPtrNum);
return tmp; IB::mPos = mOutIndex->pos();
//IB::mPos -= tmp;
return 1;
} }
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
@ -204,16 +211,19 @@ namespace MultiArrayTools
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
typename GenMapIndex<Op,XSTYPE,Indices...>::MetaType GenMapIndex<Op,XSTYPE,Indices...>::meta() const typename GenMapIndex<Op,XSTYPE,Indices...>::MetaType GenMapIndex<Op,XSTYPE,Indices...>::meta() const
{ {
MetaType metaTuple; //MetaType metaTuple;
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack); //RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
return metaTuple; //assert(0);
return mOutIndex->meta();
} }
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::at(const MetaType& metaPos) GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::at(const MetaType& metaPos)
{ {
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos); //RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack); //IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
mOutIndex->at(metaPos);
IB::mPos = mOutIndex->pos();
return *this; return *this;
} }
@ -281,12 +291,12 @@ namespace MultiArrayTools
template <class Exprs> template <class Exprs>
auto GenMapIndex<Op,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const auto GenMapIndex<Op,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh -> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<Op,IndexPack,Exprs,XSTYPE> (step, mIPack, mBlockSizes, OpExpr<Op,Exprs,XSTYPE>
( range()->map(), mIPack, mOutIndex, step, exs ) ) ) ( range()->map(), mOutIndex, step, exs ) ) )
{ {
return RPackNum<sizeof...(Indices)-1>::mkForh return RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<Op,IndexPack,Exprs,XSTYPE> (step, mIPack, mBlockSizes, OpExpr<Op,Exprs,XSTYPE>
( range()->map(), mIPack, mOutIndex, step, exs ) ); ( range()->map(), mOutIndex, step, exs ) );
} }
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
@ -297,15 +307,14 @@ namespace MultiArrayTools
return ifor(step, exs); return ifor(step, exs);
} }
/*
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
template <class Exprs> template <class Exprs>
auto GenMapIndex<Op,XSTYPE,Indices...>::iforh(Exprs exs) const auto GenMapIndex<Op,XSTYPE,Indices...>::iforh(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs)) -> decltype(ifor(step, exs))
{ {
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs); return ifor(step, exs);
} }
*/
/************************* /*************************
* MapRangeFactory * * 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> //template <class MapF, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
class OpExpr class OpExpr
{ {
public: public:
//typedef decltype(mkMapOp(std::declval<MapF>(), std::declval<IndexPack>())) Op;
typedef SingleIndex<typename Op::value_type,STYPE> OIType; 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 LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE + Op::SIZE; static constexpr size_t SIZE = Expr::SIZE + Op::SIZE;
@ -78,8 +76,7 @@ namespace MultiArrayTools
OpExpr& operator=(const OpExpr& in) = default; OpExpr& operator=(const OpExpr& in) = default;
OpExpr& operator=(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 Op& mapf, 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);
inline void operator()(size_t mlast, ExtType last); inline void operator()(size_t mlast, ExtType last);
inline void operator()(size_t mlast = 0); inline void operator()(size_t mlast = 0);
@ -90,14 +87,17 @@ namespace MultiArrayTools
template <class Op, SpaceType XSTYPE, class... Indices> template <class Op, SpaceType XSTYPE, class... Indices>
class GenMapIndex : public IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>, class GenMapIndex : public IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>,
std::tuple<typename Indices::MetaType...> > typename Op::value_type>
//std::tuple<typename Indices::MetaType...> >
{ {
public: public:
typedef IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>, 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<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 GenMapRange<Op,XSTYPE,typename Indices::RangeType...> RangeType;
typedef GenMapIndex IType; typedef GenMapIndex IType;
typedef SingleIndex<typename Op::value_type,XSTYPE> OIType; typedef SingleIndex<typename Op::value_type,XSTYPE> OIType;
@ -184,18 +184,18 @@ namespace MultiArrayTools
template <class Exprs> template <class Exprs>
auto ifor(size_t step, Exprs exs) const auto ifor(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh -> 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! // 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
-> decltype(ifor(step, exs)); // NO MULTITHREADING -> decltype(ifor(step, exs)); // NO MULTITHREADING
/*
template <class Exprs> template <class Exprs>
auto iforh(Exprs exs) const auto iforh(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs)); -> decltype(ifor(step, exs));
*/
}; };
@ -241,6 +241,7 @@ namespace MultiArrayTools
typedef GenMapRange RangeType; typedef GenMapRange RangeType;
typedef SingleRange<typename Op::value_type,XSTYPE> ORType; typedef SingleRange<typename Op::value_type,XSTYPE> ORType;
typedef SingleRangeFactory<typename Op::value_type,XSTYPE> ORFType; typedef SingleRangeFactory<typename Op::value_type,XSTYPE> ORFType;
typedef typename Op::value_type MetaType;
//typedef typename RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType; //typedef typename RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
protected: protected:

View file

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

View file

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