utilities: metaSlice + map range: mapPos

This commit is contained in:
Christian Zimmermann 2019-03-08 13:09:10 +01:00
parent 9489544972
commit 8f25e0aeb0
4 changed files with 36 additions and 0 deletions

View file

@ -213,5 +213,20 @@ namespace MultiArrayTools
return ma.format(mNSpace); return ma.format(mNSpace);
} }
template <class Range>
auto metaSlice(const std::shared_ptr<Range>& r)
-> ConstSlice<typename Range::value_type,ClassicRange>
{
ClassicRF crf(r->size());
return ConstSlice<typename Range::value_type,ClassicRange>( createExplicit(crf), &r->get(0) );
}
template <class Range, class ORange>
auto metaSlice(const std::shared_ptr<Range>& r, const std::shared_ptr<ORange>& ro)
-> ConstSlice<typename Range::value_type,ORange>
{
return ConstSlice<typename Range::value_type,ORange>( ro, &r->get(0) );
}
} }

View file

@ -95,6 +95,14 @@ namespace MultiArrayTools
auto dynToAnonMove(MultiArray<T,DynamicRange<EC>>&& ma) auto dynToAnonMove(MultiArray<T,DynamicRange<EC>>&& ma)
-> MultiArray<T,AnonymousRange>; -> MultiArray<T,AnonymousRange>;
template <class Range>
auto metaSlice(const std::shared_ptr<Range>& r)
-> ConstSlice<typename Range::value_type,ClassicRange>;
template <class Range, class ORange>
auto metaSlice(const std::shared_ptr<Range>& r, const std::shared_ptr<ORange>& ro)
-> ConstSlice<typename Range::value_type,ORange>;
template <class IndexType> template <class IndexType>
inline void For(const std::shared_ptr<IndexType>& ind, const std::function<void(void)>& ll) inline void For(const std::shared_ptr<IndexType>& ind, const std::function<void(void)>& ll)
{ {

View file

@ -562,6 +562,17 @@ namespace MultiArrayTools
( std::shared_ptr<RangeBase>( RB::mThis )) ); ( std::shared_ptr<RangeBase>( RB::mThis )) );
} }
template <class MapF, SpaceType XSTYPE, class... Ranges>
std::vector<size_t> GenMapRange<MapF,XSTYPE,Ranges...>::mapPos() const
{
auto i = mMapf.begin();
std::vector<size_t> out(i.max());
for(; i.pos() != i.max(); ++i){
out[i.pos()] = mOutRange->getMeta( mMapf[i] );
}
return out;
}
/* /*
template <class MapF, SpaceType XSTYPE, class... Ranges> template <class MapF, SpaceType XSTYPE, class... Ranges>
template <class... ERanges> template <class... ERanges>

View file

@ -269,6 +269,8 @@ namespace MultiArrayTools
const MultiArray<size_t,ORType>& mapMultiplicity() const; const MultiArray<size_t,ORType>& mapMultiplicity() const;
MultiArray<size_t,GenMapRange> explMapMultiplicity() const; MultiArray<size_t,GenMapRange> explMapMultiplicity() const;
std::vector<size_t> mapPos() const;
/* /*
template <class... ERanges> template <class... ERanges>
auto cat(const std::shared_ptr<GenMapRange<ERanges...> >& erange) auto cat(const std::shared_ptr<GenMapRange<ERanges...> >& erange)