generalize map range: specification of out range type

This commit is contained in:
Christian Zimmermann 2019-02-06 12:21:42 +01:00
parent 75ead6fdba
commit 3ccc5277e3
5 changed files with 258 additions and 197 deletions

View file

@ -6,6 +6,7 @@
#include "slice.h"
#include <ostream>
#include "pack_num.h"
#include "map_range.h"
#include <functional>
namespace MultiArrayTools

View file

@ -13,8 +13,8 @@ namespace MultiArrayTools
* OpExpr *
**************/
template <class MapF, class IndexPack, class Expr>
OpExpr<MapF,IndexPack,Expr>::OpExpr(const MapF& mapf, const IndexPack& ipack,
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
OpExpr<MapF,IndexPack,Expr,STYPE>::OpExpr(const MapF& mapf, const IndexPack& ipack,
const std::shared_ptr<OIType>& oind, size_t step, Expr ex) :
mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mStep(step), mExpr( std::forward<Expr>(ex) ),
@ -26,8 +26,8 @@ namespace MultiArrayTools
assert(mIndPtr != nullptr);
}
template <class MapF, class IndexPack, class Expr>
inline void OpExpr<MapF,IndexPack,Expr>::operator()(size_t mlast,
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast,
ExtType last) const
{
constexpr size_t NEXT = Op::SIZE;
@ -40,8 +40,8 @@ namespace MultiArrayTools
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
}
template <class MapF, class IndexPack, class Expr>
inline void OpExpr<MapF,IndexPack,Expr>::operator()(size_t mlast) const
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast) const
{
const ExtType last;
constexpr size_t NEXT = Op::SIZE;
@ -52,8 +52,8 @@ namespace MultiArrayTools
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
}
template <class MapF, class IndexPack, class Expr>
auto OpExpr<MapF,IndexPack,Expr>::rootSteps(std::intptr_t iPtrNum) const
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
auto OpExpr<MapF,IndexPack,Expr,STYPE>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mOp.rootSteps(iPtrNum).extend( mExpr.rootSteps(iPtrNum) );
@ -87,10 +87,10 @@ namespace MultiArrayTools
}
*/
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <class MRange>
MapIndex<MapF,Indices...>::MapIndex(const std::shared_ptr<MRange>& range) :
IndexInterface<MapIndex<MapF,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
GenMapIndex<MapF,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
{
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
@ -100,9 +100,9 @@ namespace MultiArrayTools
( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() );
}
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <size_t DIR>
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::up()
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::up()
{
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
@ -110,9 +110,9 @@ namespace MultiArrayTools
return *this;
}
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <size_t DIR>
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::down()
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::down()
{
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
@ -120,136 +120,136 @@ namespace MultiArrayTools
return *this;
}
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <size_t N>
auto MapIndex<MapF,Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
auto GenMapIndex<MapF,XSTYPE,Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
{
return *std::get<N>(mIPack);
}
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <size_t N>
auto MapIndex<MapF,Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
auto GenMapIndex<MapF,XSTYPE,Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>(mIPack);
}
template <class MapF, class... Indices>
auto MapIndex<MapF,Indices...>::outIndex() const -> std::shared_ptr<OIType>
template <class MapF, SpaceType XSTYPE, class... Indices>
auto GenMapIndex<MapF,XSTYPE,Indices...>::outIndex() const -> std::shared_ptr<OIType>
{
return mOutIndex;
}
template <class MapF, class... Indices>
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator()(std::shared_ptr<Indices>&... indices)
template <class MapF, SpaceType XSTYPE, class... Indices>
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator()(std::shared_ptr<Indices>&... indices)
{
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
return *this;
}
template <class MapF, class... Indices>
IndexType MapIndex<MapF,Indices...>::type() const
template <class MapF, SpaceType XSTYPE, class... Indices>
IndexType GenMapIndex<MapF,XSTYPE,Indices...>::type() const
{
return IndexType::MULTI;
}
template <class MapF, class... Indices>
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator=(size_t pos)
template <class MapF, SpaceType XSTYPE, class... Indices>
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator=(size_t pos)
{
IB::mPos = pos;
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
return *this;
}
template <class MapF, class... Indices>
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator++()
template <class MapF, SpaceType XSTYPE, class... Indices>
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator++()
{
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
++IB::mPos;
return *this;
}
template <class MapF, class... Indices>
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator--()
template <class MapF, SpaceType XSTYPE, class... Indices>
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator--()
{
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
--IB::mPos;
return *this;
}
template <class MapF, class... Indices>
int MapIndex<MapF,Indices...>::pp(std::intptr_t idxPtrNum)
template <class MapF, SpaceType XSTYPE, class... Indices>
int GenMapIndex<MapF,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
{
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
IB::mPos += tmp;
return tmp;
}
template <class MapF, class... Indices>
int MapIndex<MapF,Indices...>::mm(std::intptr_t idxPtrNum)
template <class MapF, SpaceType XSTYPE, class... Indices>
int GenMapIndex<MapF,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
{
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
IB::mPos -= tmp;
return tmp;
}
template <class MapF, class... Indices>
std::string MapIndex<MapF,Indices...>::stringMeta() const
template <class MapF, SpaceType XSTYPE, class... Indices>
std::string GenMapIndex<MapF,XSTYPE,Indices...>::stringMeta() const
{
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
}
template <class MapF, class... Indices>
typename MapIndex<MapF,Indices...>::MetaType MapIndex<MapF,Indices...>::meta() const
template <class MapF, SpaceType XSTYPE, class... Indices>
typename GenMapIndex<MapF,XSTYPE,Indices...>::MetaType GenMapIndex<MapF,XSTYPE,Indices...>::meta() const
{
MetaType metaTuple;
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
return metaTuple;
}
template <class MapF, class... Indices>
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::at(const MetaType& metaPos)
template <class MapF, SpaceType XSTYPE, class... Indices>
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::at(const MetaType& metaPos)
{
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this;
}
template <class MapF, class... Indices>
size_t MapIndex<MapF,Indices...>::dim() const
template <class MapF, SpaceType XSTYPE, class... Indices>
size_t GenMapIndex<MapF,XSTYPE,Indices...>::dim() const
{
return sizeof...(Indices);
}
template <class MapF, class... Indices>
bool MapIndex<MapF,Indices...>::first() const
template <class MapF, SpaceType XSTYPE, class... Indices>
bool GenMapIndex<MapF,XSTYPE,Indices...>::first() const
{
return IB::mPos == 0;
}
template <class MapF, class... Indices>
bool MapIndex<MapF,Indices...>::last() const
template <class MapF, SpaceType XSTYPE, class... Indices>
bool GenMapIndex<MapF,XSTYPE,Indices...>::last() const
{
return IB::mPos == IB::mMax - 1;
}
template <class MapF, class... Indices>
std::shared_ptr<typename MapIndex<MapF,Indices...>::RangeType>
MapIndex<MapF,Indices...>::range() const
template <class MapF, SpaceType XSTYPE, class... Indices>
std::shared_ptr<typename GenMapIndex<MapF,XSTYPE,Indices...>::RangeType>
GenMapIndex<MapF,XSTYPE,Indices...>::range() const
{
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
}
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <size_t N>
auto MapIndex<MapF,Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
auto GenMapIndex<MapF,XSTYPE,Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>(mIPack);
}
template <class MapF, class... Indices>
size_t MapIndex<MapF,Indices...>::getStepSize(size_t n) const
template <class MapF, SpaceType XSTYPE, class... Indices>
size_t GenMapIndex<MapF,XSTYPE,Indices...>::getStepSize(size_t n) const
{
if(n >= sizeof...(Indices)){
assert(0);
@ -258,14 +258,14 @@ namespace MultiArrayTools
return mBlockSizes[n+1];
}
template <class MapF, class... Indices>
std::string MapIndex<MapF,Indices...>::id() const
template <class MapF, SpaceType XSTYPE, class... Indices>
std::string GenMapIndex<MapF,XSTYPE,Indices...>::id() const
{
return std::string("mul") + std::to_string(IB::mId);
}
template <class MapF, class... Indices>
void MapIndex<MapF,Indices...>::print(size_t offset) const
template <class MapF, SpaceType XSTYPE, class... Indices>
void GenMapIndex<MapF,XSTYPE,Indices...>::print(size_t offset) const
{
if(offset == 0){
std::cout << " === " << std::endl;
@ -276,30 +276,30 @@ namespace MultiArrayTools
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
}
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <class Exprs>
auto MapIndex<MapF,Indices...>::ifor(size_t step, Exprs exs) const
auto GenMapIndex<MapF,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs>
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs,XSTYPE>
( range()->map(), mIPack, mOutIndex, step, exs ) ) )
{
return RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs>
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs,XSTYPE>
( range()->map(), mIPack, mOutIndex, step, exs ) );
}
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <class Exprs>
auto MapIndex<MapF,Indices...>::pifor(size_t step, Exprs exs) const
auto GenMapIndex<MapF,XSTYPE,Indices...>::pifor(size_t step, Exprs exs) const
-> decltype(ifor(step, exs))
{
return ifor(step, exs);
}
/*
template <class MapF, class... Indices>
template <class MapF, SpaceType XSTYPE, class... Indices>
template <class Exprs>
auto MapIndex<MapF,Indices...>::iforh(Exprs exs) const
auto GenMapIndex<MapF,XSTYPE,Indices...>::iforh(Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
{
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
@ -309,28 +309,30 @@ namespace MultiArrayTools
* MapRangeFactory *
*************************/
template <class MapF, class... Ranges>
MapRangeFactory<MapF,Ranges...>::MapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs)
template <class MapF, SpaceType XSTYPE, class... Ranges>
GenMapRangeFactory<MapF,XSTYPE,Ranges...>::GenMapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs)
{
mProd = std::shared_ptr< MapRange<MapF,Ranges...> >( new MapRange<MapF,Ranges...>( mapf, rs... ) );
mProd = std::shared_ptr< GenMapRange<MapF,XSTYPE,Ranges...> >
( new GenMapRange<MapF,XSTYPE,Ranges...>( mapf, rs... ) );
}
template <class MapF, class... Ranges>
MapRangeFactory<MapF,Ranges...>::MapRangeFactory(const MapF& mapf, const typename MapRange<MapF,Ranges...>::Space& st)
template <class MapF, SpaceType XSTYPE, class... Ranges>
GenMapRangeFactory<MapF,XSTYPE,Ranges...>::GenMapRangeFactory(const MapF& mapf, const typename GenMapRange<MapF,XSTYPE,Ranges...>::Space& st)
{
mProd = std::shared_ptr< MapRange<MapF,Ranges...> >( new MapRange<MapF,Ranges...>( mapf, st ) );
mProd = std::shared_ptr< GenMapRange<MapF,XSTYPE,Ranges...> >
( new GenMapRange<MapF,XSTYPE,Ranges...>( mapf, st ) );
}
template <class MapF, class... Ranges>
std::shared_ptr<RangeBase> MapRangeFactory<MapF,Ranges...>::create()
template <class MapF, SpaceType XSTYPE, class... Ranges>
std::shared_ptr<RangeBase> GenMapRangeFactory<MapF,XSTYPE,Ranges...>::create()
{
mProd = checkIfCreated( std::dynamic_pointer_cast<oType>( mProd )->mSpace );
setSelf();
return mProd;
}
template <class MapF, class... Ranges>
std::shared_ptr<RangeBase> MapRangeFactory<MapF,Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
template <class MapF, SpaceType XSTYPE, class... Ranges>
std::shared_ptr<RangeBase> GenMapRangeFactory<MapF,XSTYPE,Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
{
std::shared_ptr<RangeBase> out;
bool check = false;
@ -358,107 +360,151 @@ namespace MultiArrayTools
* MapRange *
******************/
template <class MapF, class... Ranges>
void MapRange<MapF,Ranges...>::mkOutRange()
template <SpaceType XSTYPE>
struct OutRangeMaker
{};
template <>
struct OutRangeMaker<SpaceType::ANY>
{
template <class MapF, class ORType>
static void mk(std::shared_ptr<ORType>& outRange, MultiArray<size_t,ORType>& mapMult, const MapF& mapf)
{
std::map<typename MapF::value_type,size_t> mult;
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
mult[mapf[ii]]++;
}
std::vector<typename MapF::value_type> outmeta(mult.size());
std::vector<size_t> outmult(mult.size());
size_t cnt = 0;
for(auto& x: mult){
outmeta[cnt] = x.first;
outmult[cnt] = x.second;
++cnt;
}
typename ORType::FType orf(outmeta);
outRange = std::dynamic_pointer_cast<ORType>( orf.create() );
mapMult = MultiArray<size_t,ORType>( outRange, outmult );
}
};
template <>
struct OutRangeMaker<SpaceType::NONE>
{
template <class MapF, class ORType>
static void mk(std::shared_ptr<ORType>& outRange, MultiArray<size_t,ORType>& mapMult, const MapF& mapf)
{
static_assert( std::is_same<size_t,typename MapF::value_type>::value,
"out range value type for NONE must be size_t" );
size_t max = 0;
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
max = mapf[ii] > max ? mapf[ii]+1 : max;
}
std::vector<size_t> mult(max,0);
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
mult[mapf[ii]]++;
}
std::vector<size_t> outmult(mult.size());
size_t cnt = 0;
for(auto& x: mult){
outmult[cnt++] = x;
}
typename ORType::FType orf(max);
outRange = std::dynamic_pointer_cast<ORType>( orf.create() );
mapMult = MultiArray<size_t,ORType>( outRange, outmult );
}
};
template <class MapF, SpaceType XSTYPE, class... Ranges>
void GenMapRange<MapF,XSTYPE,Ranges...>::mkOutRange()
{
//FunctionalMultiArray<typename MapF::value_type,MapF,Ranges...> fma(mSpace, mMapf);
std::map<typename MapF::value_type,size_t> mult;
for(auto ii = mMapf.begin(); ii.max() != ii.pos(); ++ii) {
mult[mMapf[ii]]++;
}
std::vector<typename MapF::value_type> outmeta(mult.size());
std::vector<size_t> outmult(mult.size());
size_t cnt = 0;
for(auto& x: mult){
outmeta[cnt] = x.first;
outmult[cnt] = x.second;
++cnt;
}
ORFType orf(outmeta);
mOutRange = std::dynamic_pointer_cast<ORType>( orf.create() );
mMapMult = MultiArray<size_t,ORType>( mOutRange, outmult );
OutRangeMaker<XSTYPE>::mk(mOutRange,mMapMult,mMapf);
}
template <class MapF, class... Ranges>
MapRange<MapF,Ranges...>::MapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs) :
template <class MapF, SpaceType XSTYPE, class... Ranges>
GenMapRange<MapF,XSTYPE,Ranges...>::GenMapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs) :
mSpace(std::make_tuple(rs...)),
mMapf(mapf)
{
mkOutRange();
}
template <class MapF, class... Ranges>
MapRange<MapF,Ranges...>::MapRange(const MapF& mapf, const Space& space) :
template <class MapF, SpaceType XSTYPE, class... Ranges>
GenMapRange<MapF,XSTYPE,Ranges...>::GenMapRange(const MapF& mapf, const Space& space) :
mSpace( space ),
mMapf(mapf)
{
mkOutRange();
}
template <class MapF, class... Ranges>
template <class MapF, SpaceType XSTYPE, class... Ranges>
template <size_t N>
auto MapRange<MapF,Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
auto GenMapRange<MapF,XSTYPE,Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
{
return *std::get<N>(mSpace);
}
template <class MapF, class... Ranges>
template <class MapF, SpaceType XSTYPE, class... Ranges>
template <size_t N>
auto MapRange<MapF,Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
auto GenMapRange<MapF,XSTYPE,Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
{
return std::get<N>(mSpace);
}
template <class MapF, class... Ranges>
auto MapRange<MapF,Ranges...>::outRange() const -> std::shared_ptr<ORType>
template <class MapF, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<MapF,XSTYPE,Ranges...>::outRange() const -> std::shared_ptr<ORType>
{
return mOutRange;
}
template <class MapF, class... Ranges>
const MapF& MapRange<MapF,Ranges...>::map() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
const MapF& GenMapRange<MapF,XSTYPE,Ranges...>::map() const
{
return mMapf;
}
template <class MapF, class... Ranges>
size_t MapRange<MapF,Ranges...>::dim() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<MapF,XSTYPE,Ranges...>::dim() const
{
return sdim;
}
template <class MapF, class... Ranges>
size_t MapRange<MapF,Ranges...>::size() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<MapF,XSTYPE,Ranges...>::size() const
{
return mOutRange->size();
//return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
}
template <class MapF, class... Ranges>
SpaceType MapRange<MapF,Ranges...>::spaceType() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
SpaceType GenMapRange<MapF,XSTYPE,Ranges...>::spaceType() const
{
return SpaceType::ANY;
}
template <class MapF, class... Ranges>
const typename MapRange<MapF,Ranges...>::Space& MapRange<MapF,Ranges...>::space() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
const typename GenMapRange<MapF,XSTYPE,Ranges...>::Space& GenMapRange<MapF,XSTYPE,Ranges...>::space() const
{
return mSpace;
}
template <class MapF, class... Ranges>
std::string MapRange<MapF,Ranges...>::stringMeta(size_t pos) const
template <class MapF, SpaceType XSTYPE, class... Ranges>
std::string GenMapRange<MapF,XSTYPE,Ranges...>::stringMeta(size_t pos) const
{
auto i = begin();
i = pos;
return "[ " + RPackNum<sizeof...(Ranges)-1>::metaTupleToString(i.meta()) + " ]";
}
template <class MapF, class... Ranges>
std::vector<char> MapRange<MapF,Ranges...>::data() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
std::vector<char> GenMapRange<MapF,XSTYPE,Ranges...>::data() const
{
DataHeader h = dataHeader();
std::vector<char> out;
@ -469,8 +515,8 @@ namespace MultiArrayTools
return out;
}
template <class MapF, class... Ranges>
DataHeader MapRange<MapF,Ranges...>::dataHeader() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
DataHeader GenMapRange<MapF,XSTYPE,Ranges...>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::ANY );
@ -479,50 +525,51 @@ namespace MultiArrayTools
return h;
}
template <class MapF, class... Ranges>
typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::begin() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
typename GenMapRange<MapF,XSTYPE,Ranges...>::IndexType GenMapRange<MapF,XSTYPE,Ranges...>::begin() const
{
MapIndex<MapF,typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MapRange<MapF,Ranges...> >
i( std::dynamic_pointer_cast<GenMapRange<MapF,XSTYPE,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
template <class MapF, class... Ranges>
typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::end() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
typename GenMapRange<MapF,XSTYPE,Ranges...>::IndexType GenMapRange<MapF,XSTYPE,Ranges...>::end() const
{
MapIndex<MapF,typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MapRange<MapF,Ranges...> >
i( std::dynamic_pointer_cast<GenMapRange<MapF,XSTYPE,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis )) );
i = size();
return i;
}
template <class MapF, class... Ranges>
auto MapRange<MapF,Ranges...>::mapMultiplicity() const
template <class MapF, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<MapF,XSTYPE,Ranges...>::mapMultiplicity() const
-> const MultiArray<size_t,ORType>&
{
return mMapMult;
}
template <class MapF, class... Ranges>
auto MapRange<MapF,Ranges...>::explMapMultiplicity() const
-> MultiArray<size_t,MapRange>
template <class MapF, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<MapF,XSTYPE,Ranges...>::explMapMultiplicity() const
-> MultiArray<size_t,GenMapRange>
{
auto tmp = mMapMult;
return tmp.format( std::dynamic_pointer_cast<MapRange<MapF,Ranges...> >
return tmp.format( std::dynamic_pointer_cast<GenMapRange<MapF,XSTYPE,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis )) );
}
template <class MapF, class... Ranges>
/*
template <class MapF, SpaceType XSTYPE, class... Ranges>
template <class... ERanges>
auto MapRange<MapF,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
-> std::shared_ptr<MapRange<Ranges...,ERanges...> >
auto GenMapRange<MapF,XSTYPE,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >
{
auto crange = std::tuple_cat(mSpace, erange->space());
MapRangeFactory<Ranges...,ERanges...> rf(crange);
return std::dynamic_pointer_cast<MapRange<Ranges...,ERanges...> >(rf.create());
}
*/
}

View file

@ -34,11 +34,11 @@ namespace MultiArrayTools
return PackNum<sizeof...(Indices)-1>::mkMapOp(ma, itp);
}
template <class MapF, class IndexPack, class Expr>
template <class MapF, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
class OpExpr
{
public:
typedef SingleIndex<typename MapF::value_type,SpaceType::ANY> OIType;
typedef SingleIndex<typename MapF::value_type,STYPE> OIType;
//typedef typename MapF::IndexPack IndexPack;
static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE;
@ -73,25 +73,25 @@ namespace MultiArrayTools
};
template <class MapF, class... Indices>
class MapIndex : public IndexInterface<MapIndex<MapF,Indices...>,
std::tuple<typename Indices::MetaType...> >
template <class MapF, SpaceType XSTYPE, class... Indices>
class GenMapIndex : public IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,
std::tuple<typename Indices::MetaType...> >
{
public:
typedef IndexInterface<MapIndex<MapF,Indices...>,
typedef IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,
std::tuple<typename Indices::MetaType...> > IB;
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
typedef std::tuple<typename Indices::MetaType...> MetaType;
typedef MapRange<MapF,typename Indices::RangeType...> RangeType;
typedef MapIndex IType;
typedef SingleIndex<typename MapF::value_type,SpaceType::ANY> OIType;
typedef GenMapRange<MapF,XSTYPE,typename Indices::RangeType...> RangeType;
typedef GenMapIndex IType;
typedef SingleIndex<typename MapF::value_type,XSTYPE> OIType;
static constexpr IndexType sType() { return IndexType::MULTI; }
static constexpr size_t sDim() { return sizeof...(Indices); }
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
static constexpr SpaceType STYPE = SpaceType::ANY;
static constexpr SpaceType STYPE = XSTYPE;
static constexpr bool PARALLEL = false;
private:
@ -104,7 +104,7 @@ namespace MultiArrayTools
const IndexPack& pack() const { return mIPack; }
MapIndex() = delete;
GenMapIndex() = delete;
// NO DEFAULT HERE !!!
// ( have to assign sub-indices (ptr!) correctly )
@ -112,13 +112,13 @@ namespace MultiArrayTools
//MapIndex& operator=(const MapIndex& in);
template <class MRange>
MapIndex(const std::shared_ptr<MRange>& range);
GenMapIndex(const std::shared_ptr<MRange>& range);
template <size_t DIR>
MapIndex& up();
GenMapIndex& up();
template <size_t DIR>
MapIndex& down();
GenMapIndex& down();
template <size_t N>
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
@ -135,23 +135,23 @@ namespace MultiArrayTools
// MultiIndices CANNOT be influences be its subindices, so there is
// NO foreign/external controll)
// Do NOT share index instances between two or more MapIndex instances
MapIndex& operator()(std::shared_ptr<Indices>&... indices);
GenMapIndex& operator()(std::shared_ptr<Indices>&... indices);
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
IndexType type() const;
MapIndex& operator=(size_t pos);
GenMapIndex& operator=(size_t pos);
MapIndex& operator++();
MapIndex& operator--();
GenMapIndex& operator++();
GenMapIndex& operator--();
int pp(std::intptr_t idxPtrNum);
int mm(std::intptr_t idxPtrNum);
std::string stringMeta() const;
MetaType meta() const;
MapIndex& at(const MetaType& metaPos);
GenMapIndex& at(const MetaType& metaPos);
size_t dim() const;
bool first() const;
@ -169,7 +169,7 @@ namespace MultiArrayTools
template <class Exprs>
auto ifor(size_t step, Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, step, exs ) ) );
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs,XSTYPE>( range()->map(), mIPack, mOutIndex, step, exs ) ) );
// first step arg not used!
template <class Exprs>
@ -183,27 +183,21 @@ namespace MultiArrayTools
*/
};
template <class MapF, class... Indices>
auto mapResult/*<MapIndex<MapF,Indices...> >*/(const std::shared_ptr<MapIndex<MapF,Indices...> >& ind)
-> decltype(ind->outIndex())
{
return ind->outIndex();
}
/*************************
* MapRangeFactory *
*************************/
// NOT THREAD SAVE
template <class MapF, class... Ranges>
class MapRangeFactory : public RangeFactoryBase
template <class MapF, SpaceType XSTYPE, class... Ranges>
class GenMapRangeFactory : public RangeFactoryBase
{
public:
typedef MapRange<MapF,Ranges...> oType;
typedef GenMapRange<MapF,XSTYPE,Ranges...> oType;
MapRangeFactory() = delete;
MapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
MapRangeFactory(const MapF& mapf, const typename MapRange<MapF,Ranges...>::Space& space);
GenMapRangeFactory() = delete;
GenMapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
GenMapRangeFactory(const MapF& mapf, const typename GenMapRange<MapF,XSTYPE,Ranges...>::Space& space);
virtual std::shared_ptr<RangeBase> create() override;
@ -217,25 +211,25 @@ namespace MultiArrayTools
* MapRange *
******************/
template <class MapF, class... Ranges>
class MapRange : public RangeInterface<MapIndex<MapF,typename Ranges::IndexType...> >
template <class MapF, SpaceType XSTYPE, class... Ranges>
class GenMapRange : public RangeInterface<GenMapIndex<MapF,XSTYPE,typename Ranges::IndexType...> >
{
public:
typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
typedef MapIndex<MapF,typename Ranges::IndexType...> IndexType;
typedef MapRange RangeType;
typedef SingleRange<typename MapF::value_type,SpaceType::ANY> ORType;
typedef SingleRangeFactory<typename MapF::value_type,SpaceType::ANY> ORFType;
typedef GenMapIndex<MapF,XSTYPE,typename Ranges::IndexType...> IndexType;
typedef GenMapRange RangeType;
typedef SingleRange<typename MapF::value_type,XSTYPE> ORType;
typedef SingleRangeFactory<typename MapF::value_type,XSTYPE> ORFType;
//typedef typename RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
protected:
MapRange() = delete;
MapRange(const MapRange& in) = delete;
MapRange& operator=(const MapRange& in) = delete;
GenMapRange() = delete;
GenMapRange(const GenMapRange& in) = delete;
GenMapRange& operator=(const GenMapRange& in) = delete;
MapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
MapRange(const MapF& mapf, const Space& space);
GenMapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
GenMapRange(const MapF& mapf, const Space& space);
Space mSpace;
const MapF& mMapf;
@ -273,21 +267,38 @@ namespace MultiArrayTools
virtual IndexType end() const final;
const MultiArray<size_t,ORType>& mapMultiplicity() const;
MultiArray<size_t,MapRange> explMapMultiplicity() const;
MultiArray<size_t,GenMapRange> explMapMultiplicity() const;
/*
template <class... ERanges>
auto cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
-> std::shared_ptr<MapRange<Ranges...,ERanges...> >;
friend MapRangeFactory<MapF,Ranges...>;
auto cat(const std::shared_ptr<GenMapRange<ERanges...> >& erange)
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >;
*/
friend GenMapRangeFactory<MapF,XSTYPE,Ranges...>;
static constexpr bool HASMETACONT = false;
static constexpr bool defaultable = false;
static constexpr size_t ISSTATIC = SubProp<MapF,Ranges...>::ISSTATIC;
static constexpr size_t SIZE = SubProp<MapF,Ranges...>::SIZE;
};
// for legacy
template <class MapF, class... Indices>
using MapIndex = GenMapIndex<MapF,SpaceType::ANY,Indices...>;
template <class MapF, class... Ranges>
using MapRangeFactory = GenMapRangeFactory<MapF,SpaceType::ANY,Ranges...>;
template <class MapF, class... Ranges>
using MapRange = GenMapRange<MapF,SpaceType::ANY,Ranges...>;
template <class MapF, class... Indices>
auto mapResult/*<MapIndex<MapF,Indices...> >*/(const std::shared_ptr<MapIndex<MapF,Indices...> >& ind)
-> decltype(ind->outIndex())
{
return ind->outIndex();
}
}

View file

@ -14,8 +14,8 @@ namespace MultiArrayTools
{
public:
template <class MapF, class... Ranges>
friend class MapRangeFactory;
template <class MapF, SpaceType XSTYPE, class... Ranges>
friend class GenMapRangeFactory;
private:
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated;

View file

@ -2,6 +2,8 @@
#ifndef __mbase_def_h__
#define __mbase_def_h__
#include "ranges/rbase_def.h"
namespace MultiArrayTools
{
/***********************
@ -76,16 +78,16 @@ namespace MultiArrayTools
class ConstSliceDef;
// map_range.h
template <class MapF, class... Indices>
class MapIndex;
template <class MapF, SpaceType XSTYPE, class... Indices>
class GenMapIndex;
// map_range.h
template <class MapF, class... Ranges>
class MapRangeFactory;
template <class MapF, SpaceType XSTYPE, class... Ranges>
class GenMapRangeFactory;
// map_range.h
template <class MapF, class... Ranges>
class MapRange;
template <class MapF, SpaceType XSTYPE, class... Ranges>
class GenMapRange;
}
#endif