map range: allow more general out ranges

This commit is contained in:
Christian Zimmermann 2021-01-09 00:45:24 +01:00
parent b8071fff94
commit cfb3d4919b
7 changed files with 192 additions and 195 deletions

View file

@ -99,18 +99,18 @@ namespace MultiArrayTools
template <SpaceType STYPE, class Op, class MA, class... RangeTypes>
auto mkGenMapR(const std::tuple<Op,MA>& f, std::shared_ptr<RangeTypes>... ranges)
-> std::shared_ptr<GenMapRange<Op,STYPE,RangeTypes...> >
-> std::shared_ptr<GenMapRange<MapORType<Op,STYPE>,Op,STYPE,RangeTypes...> >
{
GenMapRangeFactory<Op,STYPE,RangeTypes...> mrf(f, ranges... );
GenMapRangeFactory<MapORType<Op,STYPE>,Op,STYPE,RangeTypes...> mrf(f, ranges... );
return createExplicit( mrf );
}
template <SpaceType STYPE, class Op, class MA, class... RangeTypes>
auto mkGenMapRwith(const std::shared_ptr<MapORType<Op,STYPE>>& outr, const std::tuple<Op,MA>& f,
template <SpaceType STYPE, class ORType, class Op, class MA, class... RangeTypes>
auto mkGenMapRwith(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& f,
std::shared_ptr<RangeTypes>... ranges)
-> std::shared_ptr<GenMapRange<Op,STYPE,RangeTypes...> >
-> std::shared_ptr<GenMapRange<ORType,Op,STYPE,RangeTypes...> >
{
GenMapRangeFactory<Op,STYPE,RangeTypes...> mrf(outr, f, ranges... );
GenMapRangeFactory<ORType,Op,STYPE,RangeTypes...> mrf(outr, f, ranges... );
return createExplicit( mrf );
}
@ -130,8 +130,8 @@ namespace MultiArrayTools
return mkGenMapR<SpaceType::ANY>(f, ranges... );
}
template <class Op, class MA, class... RangeTypes>
auto mkMapRwith(const std::shared_ptr<MapORType<Op,SpaceType::ANY>>& outr, const std::tuple<Op,MA>& f,
template <class ORType, class Op, class MA, class... RangeTypes>
auto mkMapRwith(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& f,
std::shared_ptr<RangeTypes>... ranges)
-> decltype( mkGenMapRwith<SpaceType::ANY>(outr, f, ranges... ) )
{
@ -145,8 +145,8 @@ namespace MultiArrayTools
return mkMapR( mkMapOp( func, is... ), is->range()... );
}
template <class TarRange, class Func, class... Indices>
auto mkMapRwith(const std::shared_ptr<MapORType<Func,SpaceType::ANY>>& outr, const std::shared_ptr<Func>& func, const std::shared_ptr<Indices>&... is)
template <class ORType, class Func, class... Indices>
auto mkMapRwith(const std::shared_ptr<ORType>& outr, const std::shared_ptr<Func>& func, const std::shared_ptr<Indices>&... is)
-> decltype( mkMapRwith(outr, mkMapOp( func, is... ), is->range()... ) )
{
return mkMapRwith(outr, mkMapOp( func, is... ), is->range()... );

View file

@ -28,17 +28,17 @@ namespace MultiArrayTools
auto mkMulti(std::shared_ptr<RangeTypes>... ranges)
-> std::shared_ptr<MultiRange<RangeTypes...> >;
template <SpaceType STYPE, class Op, class MA, class... RangeTypes>
auto mkGenMapR(const std::tuple<Op,MA>& f, std::shared_ptr<RangeTypes>... ranges)
-> std::shared_ptr<GenMapRange<Op,STYPE,RangeTypes...> >;
template <class Op, SpaceType XSTYPE>
using MapORType = SingleRange<typename Op::value_type,XSTYPE>;
template <SpaceType STYPE, class Op, class MA, class... RangeTypes>
auto mkGenMapRwith(const std::shared_ptr<MapORType<Op,STYPE>>& outr, const std::tuple<Op,MA>& f,
auto mkGenMapR(const std::tuple<Op,MA>& f, std::shared_ptr<RangeTypes>... ranges)
-> std::shared_ptr<GenMapRange<MapORType<Op,STYPE>,Op,STYPE,RangeTypes...> >;
template <SpaceType STYPE, class ORType, class Op, class MA, class... RangeTypes>
auto mkGenMapRwith(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& f,
std::shared_ptr<RangeTypes>... ranges)
-> std::shared_ptr<GenMapRange<Op,STYPE,RangeTypes...> >;
-> std::shared_ptr<GenMapRange<ORType,Op,STYPE,RangeTypes...> >;
template <SpaceType STYPE, class Op, class MA, class... IndexTypes>
auto mkGenMapI(const std::tuple<Op,MA>& f, std::shared_ptr<IndexTypes>... indices)
@ -48,23 +48,18 @@ namespace MultiArrayTools
auto mkMapR(const std::tuple<Op,MA>& f, std::shared_ptr<RangeTypes>... ranges)
-> decltype( mkGenMapR<SpaceType::ANY>(f, ranges... ) );
template <class Op, class MA, class... RangeTypes>
auto mkMapRwith(const std::shared_ptr<MapORType<Op,SpaceType::ANY>>& outr, const std::tuple<Op,MA>& f, std::shared_ptr<RangeTypes>... ranges)
template <class ORType, class Op, class MA, class... RangeTypes>
auto mkMapRwith(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& f, std::shared_ptr<RangeTypes>... ranges)
-> decltype( mkGenMapRwith<SpaceType::ANY>(outr, f, ranges... ) );
template <class Func, class... Indices>
auto mkMapR(const std::shared_ptr<Func>& func, const std::shared_ptr<Indices>&... is)
-> decltype( mkMapR( mkMapOp( func, is... ), is->range()... ) );
template <class TarRange, class Func, class... Indices>
auto mkMapRwith(const std::shared_ptr<MapORType<Func,SpaceType::ANY>>& outr, const std::shared_ptr<Func>& func, const std::shared_ptr<Indices>&... is)
template <class ORType, class Func, class... Indices>
auto mkMapRwith(const std::shared_ptr<ORType>& outr, const std::shared_ptr<Func>& func, const std::shared_ptr<Indices>&... is)
-> decltype( mkMapRwith(outr, mkMapOp( func, is... ), is->range()... ) );
template <class Op, class MA, class... RangeTypes>
auto mkMapRwith(const std::shared_ptr<MapORType<Op,SpaceType::ANY>>& outr, const std::tuple<Op,MA>& f,
std::shared_ptr<RangeTypes>... ranges)
-> decltype( mkGenMapRwith<SpaceType::ANY>(outr, f, ranges... ) );
template <class Op, class MA, class... IndexTypes>
auto mkMapI(const std::tuple<Op,MA>& f, std::shared_ptr<IndexTypes>... indices)
-> decltype( mkGenMapI<SpaceType::ANY>(f, indices... ) );

View file

@ -90,10 +90,10 @@ namespace MultiArrayTools
}
*/
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, 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...>,typename Op::value_type>(range, 0)
GenMapIndex<OIType,Op,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
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);
@ -103,9 +103,9 @@ namespace MultiArrayTools
( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() );
}
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <size_t DIR>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::up()
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::up()
{
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
@ -113,9 +113,9 @@ namespace MultiArrayTools
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <size_t DIR>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::down()
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::down()
{
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
@ -123,42 +123,42 @@ namespace MultiArrayTools
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <size_t N>
auto GenMapIndex<Op,XSTYPE,Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
{
return *std::get<N>(mIPack);
}
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <size_t N>
auto GenMapIndex<Op,XSTYPE,Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>(mIPack);
}
template <class Op, SpaceType XSTYPE, class... Indices>
auto GenMapIndex<Op,XSTYPE,Indices...>::outIndex() const -> std::shared_ptr<OIType>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::outIndex() const -> std::shared_ptr<OIType>
{
return mOutIndex;
}
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator()(const std::shared_ptr<Indices>&... 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)
{
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
IndexType GenMapIndex<Op,XSTYPE,Indices...>::type() const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
IndexType GenMapIndex<OIType,Op,XSTYPE,Indices...>::type() const
{
return IndexType::MULTI;
}
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator=(size_t pos)
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator=(size_t pos)
{
(*mOutIndex) = pos;
IB::mPos = mOutIndex->pos();
@ -166,8 +166,8 @@ namespace MultiArrayTools
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator++()
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator++()
{
//RPackNum<sizeof...(Indices)-1>::pp( mIPack );
++(*mOutIndex);
@ -175,8 +175,8 @@ namespace MultiArrayTools
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::operator--()
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator--()
{
//RPackNum<sizeof...(Indices)-1>::mm( mIPack );
--(*mOutIndex);
@ -184,8 +184,8 @@ namespace MultiArrayTools
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
int GenMapIndex<Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
{
//int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
mOutIndex->pp(idxPtrNum);
@ -194,8 +194,8 @@ namespace MultiArrayTools
return 1;
}
template <class Op, SpaceType XSTYPE, class... Indices>
int GenMapIndex<Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
{
//int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
mOutIndex->mm(idxPtrNum);
@ -204,14 +204,14 @@ namespace MultiArrayTools
return 1;
}
template <class Op, SpaceType XSTYPE, class... Indices>
std::string GenMapIndex<Op,XSTYPE,Indices...>::stringMeta() const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
std::string GenMapIndex<OIType,Op,XSTYPE,Indices...>::stringMeta() const
{
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
}
template <class Op, SpaceType XSTYPE, class... Indices>
typename GenMapIndex<Op,XSTYPE,Indices...>::MetaType GenMapIndex<Op,XSTYPE,Indices...>::meta() const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
typename GenMapIndex<OIType,Op,XSTYPE,Indices...>::MetaType GenMapIndex<OIType,Op,XSTYPE,Indices...>::meta() const
{
//MetaType metaTuple;
//RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
@ -219,8 +219,8 @@ namespace MultiArrayTools
return mOutIndex->meta();
}
template <class Op, SpaceType XSTYPE, class... Indices>
GenMapIndex<Op,XSTYPE,Indices...>& GenMapIndex<Op,XSTYPE,Indices...>::at(const MetaType& metaPos)
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
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);
@ -229,46 +229,46 @@ namespace MultiArrayTools
return *this;
}
template <class Op, SpaceType XSTYPE, class... Indices>
size_t GenMapIndex<Op,XSTYPE,Indices...>::posAt(const MetaType& metaPos) const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
size_t GenMapIndex<OIType,Op,XSTYPE,Indices...>::posAt(const MetaType& metaPos) const
{
return range()->outRange()->getMeta(metaPos);
}
template <class Op, SpaceType XSTYPE, class... Indices>
size_t GenMapIndex<Op,XSTYPE,Indices...>::dim() const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
size_t GenMapIndex<OIType,Op,XSTYPE,Indices...>::dim() const
{
return sizeof...(Indices);
}
template <class Op, SpaceType XSTYPE, class... Indices>
bool GenMapIndex<Op,XSTYPE,Indices...>::first() const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
bool GenMapIndex<OIType,Op,XSTYPE,Indices...>::first() const
{
return IB::mPos == 0;
}
template <class Op, SpaceType XSTYPE, class... Indices>
bool GenMapIndex<Op,XSTYPE,Indices...>::last() const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
bool GenMapIndex<OIType,Op,XSTYPE,Indices...>::last() const
{
return IB::mPos == IB::mMax - 1;
}
template <class Op, SpaceType XSTYPE, class... Indices>
std::shared_ptr<typename GenMapIndex<Op,XSTYPE,Indices...>::RangeType>
GenMapIndex<Op,XSTYPE,Indices...>::range() const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
std::shared_ptr<typename GenMapIndex<OIType,Op,XSTYPE,Indices...>::RangeType>
GenMapIndex<OIType,Op,XSTYPE,Indices...>::range() const
{
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
}
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <size_t N>
auto GenMapIndex<Op,XSTYPE,Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>(mIPack);
}
template <class Op, SpaceType XSTYPE, class... Indices>
size_t GenMapIndex<Op,XSTYPE,Indices...>::getStepSize(size_t n) const
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
size_t GenMapIndex<OIType,Op,XSTYPE,Indices...>::getStepSize(size_t n) const
{
if(n >= sizeof...(Indices)){
assert(0);
@ -277,14 +277,14 @@ namespace MultiArrayTools
return mBlockSizes[n+1];
}
template <class Op, SpaceType XSTYPE, class... Indices>
std::string GenMapIndex<Op,XSTYPE,Indices...>::id() const
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 Op, SpaceType XSTYPE, class... Indices>
void GenMapIndex<Op,XSTYPE,Indices...>::print(size_t offset) const
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;
@ -295,29 +295,29 @@ namespace MultiArrayTools
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
}
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <class Exprs>
auto GenMapIndex<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<Op,XSTYPE,Indices...>,Exprs,XSTYPE>
(step, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE>
( range()->map(), this, step, exs ) ) )
{
return RPackNum<sizeof...(Indices)-1>::mkForh
(0, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<Op,XSTYPE,Indices...>,Exprs,XSTYPE>
(0, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE>
( range()->map(), this, step, exs ) );
}
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <class Exprs>
auto GenMapIndex<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);
}
template <class Op, SpaceType XSTYPE, class... Indices>
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
template <class Exprs>
auto GenMapIndex<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);
@ -327,54 +327,54 @@ namespace MultiArrayTools
* MapRangeFactory *
*************************/
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
GenMapRangeFactory<Op,XSTYPE,Ranges...>::GenMapRangeFactory(const std::shared_ptr<ORType>& outr,
GenMapRangeFactory<ORType,Op,XSTYPE,Ranges...>::GenMapRangeFactory(const std::shared_ptr<ORType>& outr,
const std::tuple<Op,MA>& mapf,
const std::shared_ptr<Ranges>&... rs)
{
mProd = std::shared_ptr< GenMapRange<Op,XSTYPE,Ranges...> >
( new GenMapRange<Op,XSTYPE,Ranges...>( outr, mapf, rs... ) );
mProd = std::shared_ptr< GenMapRange<ORType,Op,XSTYPE,Ranges...> >
( new GenMapRange<ORType,Op,XSTYPE,Ranges...>( outr, mapf, rs... ) );
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
GenMapRangeFactory<Op,XSTYPE,Ranges...>::GenMapRangeFactory(const std::shared_ptr<ORType>& outr,
GenMapRangeFactory<ORType,Op,XSTYPE,Ranges...>::GenMapRangeFactory(const std::shared_ptr<ORType>& outr,
const std::tuple<Op,MA>& mapf,
const typename GenMapRange<Op,XSTYPE,Ranges...>::Space& st)
const typename GenMapRange<ORType,Op,XSTYPE,Ranges...>::Space& st)
{
mProd = std::shared_ptr< GenMapRange<Op,XSTYPE,Ranges...> >
( new GenMapRange<Op,XSTYPE,Ranges...>( outr, mapf, st ) );
mProd = std::shared_ptr< GenMapRange<ORType,Op,XSTYPE,Ranges...> >
( new GenMapRange<ORType,Op,XSTYPE,Ranges...>( outr, mapf, st ) );
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
GenMapRangeFactory<Op,XSTYPE,Ranges...>::GenMapRangeFactory(const std::tuple<Op,MA>& mapf,
GenMapRangeFactory<ORType,Op,XSTYPE,Ranges...>::GenMapRangeFactory(const std::tuple<Op,MA>& mapf,
const std::shared_ptr<Ranges>&... rs)
{
mProd = std::shared_ptr< GenMapRange<Op,XSTYPE,Ranges...> >
( new GenMapRange<Op,XSTYPE,Ranges...>( mapf, rs... ) );
mProd = std::shared_ptr< GenMapRange<ORType,Op,XSTYPE,Ranges...> >
( new GenMapRange<ORType,Op,XSTYPE,Ranges...>( mapf, rs... ) );
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
GenMapRangeFactory<Op,XSTYPE,Ranges...>::GenMapRangeFactory(const std::tuple<Op,MA>& mapf,
const typename GenMapRange<Op,XSTYPE,Ranges...>::Space& st)
GenMapRangeFactory<ORType,Op,XSTYPE,Ranges...>::GenMapRangeFactory(const std::tuple<Op,MA>& mapf,
const typename GenMapRange<ORType,Op,XSTYPE,Ranges...>::Space& st)
{
mProd = std::shared_ptr< GenMapRange<Op,XSTYPE,Ranges...> >
( new GenMapRange<Op,XSTYPE,Ranges...>( mapf, st ) );
mProd = std::shared_ptr< GenMapRange<ORType,Op,XSTYPE,Ranges...> >
( new GenMapRange<ORType,Op,XSTYPE,Ranges...>( mapf, st ) );
}
template <class Op, SpaceType XSTYPE, class... Ranges>
std::shared_ptr<RangeBase> GenMapRangeFactory<Op,XSTYPE,Ranges...>::create()
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
std::shared_ptr<RangeBase> GenMapRangeFactory<ORType,Op,XSTYPE,Ranges...>::create()
{
mProd = checkIfCreated( std::dynamic_pointer_cast<oType>( mProd )->mSpace );
setSelf();
return mProd;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
std::shared_ptr<RangeBase> GenMapRangeFactory<Op,XSTYPE,Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
std::shared_ptr<RangeBase> GenMapRangeFactory<ORType,Op,XSTYPE,Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
{
std::shared_ptr<RangeBase> out;
bool check = false;
@ -463,9 +463,9 @@ namespace MultiArrayTools
}
};
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
void GenMapRange<Op,XSTYPE,Ranges...>::mkOutRange(const MA& mapf)
void GenMapRange<ORType,Op,XSTYPE,Ranges...>::mkOutRange(const MA& mapf)
{
//FunctionalMultiArray<typename MapF::value_type,MapF,Ranges...> fma(mSpace, mMapf);
OutRangeMaker<XSTYPE>::mk(mOutRange,mMapMult,mapf);
@ -477,9 +477,9 @@ namespace MultiArrayTools
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
GenMapRange<Op,XSTYPE,Ranges...>::GenMapRange(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
GenMapRange<ORType,Op,XSTYPE,Ranges...>::GenMapRange(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
const std::shared_ptr<Ranges>&... rs) :
mSpace(std::make_tuple(rs...)),
mMapf(std::get<0>(mapf)),
@ -495,9 +495,9 @@ namespace MultiArrayTools
}
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
GenMapRange<Op,XSTYPE,Ranges...>::GenMapRange(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
GenMapRange<ORType,Op,XSTYPE,Ranges...>::GenMapRange(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
const Space& space) :
mSpace(space),
mMapf(std::get<0>(mapf)),
@ -513,9 +513,9 @@ namespace MultiArrayTools
}
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
GenMapRange<Op,XSTYPE,Ranges...>::GenMapRange(const std::tuple<Op,MA>& mapf,
GenMapRange<ORType,Op,XSTYPE,Ranges...>::GenMapRange(const std::tuple<Op,MA>& mapf,
const std::shared_ptr<Ranges>&... rs) :
mSpace(std::make_tuple(rs...)),
mMapf(std::get<0>(mapf))
@ -523,76 +523,76 @@ namespace MultiArrayTools
mkOutRange(std::get<1>(mapf));
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class MA>
GenMapRange<Op,XSTYPE,Ranges...>::GenMapRange(const std::tuple<Op,MA>& mapf, const Space& space) :
GenMapRange<ORType,Op,XSTYPE,Ranges...>::GenMapRange(const std::tuple<Op,MA>& mapf, const Space& space) :
mSpace( space ),
mMapf(std::get<0>(mapf))
{
mkOutRange(std::get<1>(mapf));
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <size_t N>
auto GenMapRange<Op,XSTYPE,Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
{
return *std::get<N>(mSpace);
}
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <size_t N>
auto GenMapRange<Op,XSTYPE,Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
{
return std::get<N>(mSpace);
}
template <class Op, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<Op,XSTYPE,Ranges...>::outRange() const -> std::shared_ptr<ORType>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::outRange() const -> std::shared_ptr<ORType>
{
return mOutRange;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
const Op& GenMapRange<Op,XSTYPE,Ranges...>::map() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
const Op& GenMapRange<ORType,Op,XSTYPE,Ranges...>::map() const
{
return mMapf;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<Op,XSTYPE,Ranges...>::dim() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::dim() const
{
return sdim;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<Op,XSTYPE,Ranges...>::size() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::size() const
{
return mOutRange->size();
//return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
}
template <class Op, SpaceType XSTYPE, class... Ranges>
SpaceType GenMapRange<Op,XSTYPE,Ranges...>::spaceType() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
SpaceType GenMapRange<ORType,Op,XSTYPE,Ranges...>::spaceType() const
{
return SpaceType::ANY;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
const typename GenMapRange<Op,XSTYPE,Ranges...>::Space& GenMapRange<Op,XSTYPE,Ranges...>::space() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
const typename GenMapRange<ORType,Op,XSTYPE,Ranges...>::Space& GenMapRange<ORType,Op,XSTYPE,Ranges...>::space() const
{
return mSpace;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
vector<size_t> GenMapRange<Op,XSTYPE,Ranges...>::typeNum() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
vector<size_t> GenMapRange<ORType,Op,XSTYPE,Ranges...>::typeNum() const
{
vector<size_t> o;
RPackNum<sizeof...(Ranges)-1>::getTypeNum(o,mSpace);
return o;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<Op,XSTYPE,Ranges...>::cmeta(char* target, size_t pos) const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::cmeta(char* target, size_t pos) const
{
//MetaType* xtarget = reinterpret_cast<MetaType*>(target);
assert(0);
@ -600,22 +600,22 @@ namespace MultiArrayTools
//return RPackNum<sizeof...(Ranges)-1>::getCMeta(xtarget,pos,mSpace,cmetaSize());
}
template <class Op, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<Op,XSTYPE,Ranges...>::cmetaSize() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::cmetaSize() const
{
return RPackNum<sizeof...(Ranges)-1>::getCMetaSize(mSpace);
}
template <class Op, SpaceType XSTYPE, class... Ranges>
std::string GenMapRange<Op,XSTYPE,Ranges...>::stringMeta(size_t pos) const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
std::string GenMapRange<ORType,Op,XSTYPE,Ranges...>::stringMeta(size_t pos) const
{
auto i = begin();
i = pos;
return "[ " + RPackNum<sizeof...(Ranges)-1>::getStringMeta(i) + " ]";
}
template <class Op, SpaceType XSTYPE, class... Ranges>
vector<char> GenMapRange<Op,XSTYPE,Ranges...>::data() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
vector<char> GenMapRange<ORType,Op,XSTYPE,Ranges...>::data() const
{
DataHeader h = dataHeader();
vector<char> out;
@ -626,8 +626,8 @@ namespace MultiArrayTools
return out;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
DataHeader GenMapRange<Op,XSTYPE,Ranges...>::dataHeader() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
DataHeader GenMapRange<ORType,Op,XSTYPE,Ranges...>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::ANY );
@ -636,56 +636,56 @@ namespace MultiArrayTools
return h;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
typename GenMapRange<Op,XSTYPE,Ranges...>::IndexType GenMapRange<Op,XSTYPE,Ranges...>::begin() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
typename GenMapRange<ORType,Op,XSTYPE,Ranges...>::IndexType GenMapRange<ORType,Op,XSTYPE,Ranges...>::begin() const
{
GenMapIndex<Op,XSTYPE,typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<GenMapRange<Op,XSTYPE,Ranges...> >
GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<GenMapRange<ORType,Op,XSTYPE,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
typename GenMapRange<Op,XSTYPE,Ranges...>::IndexType GenMapRange<Op,XSTYPE,Ranges...>::end() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
typename GenMapRange<ORType,Op,XSTYPE,Ranges...>::IndexType GenMapRange<ORType,Op,XSTYPE,Ranges...>::end() const
{
GenMapIndex<Op,XSTYPE,typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<GenMapRange<Op,XSTYPE,Ranges...> >
GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<GenMapRange<ORType,Op,XSTYPE,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis )) );
i = size();
return i;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<Op,XSTYPE,Ranges...>::mapMultiplicity() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::mapMultiplicity() const
-> const MultiArray<size_t,ORType>&
{
return mMapMult;
}
template <class Op, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<Op,XSTYPE,Ranges...>::explMapMultiplicity() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::explMapMultiplicity() const
-> ConstSlice<size_t,GenMapRange>
{
/*
auto tmp = mMapMult;
return tmp.format( std::dynamic_pointer_cast<GenMapRange<Op,XSTYPE,Ranges...> >
return tmp.format( std::dynamic_pointer_cast<GenMapRange<ORType,Op,XSTYPE,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis )) );
*/
return mMapMult.slformat(std::dynamic_pointer_cast<GenMapRange<Op,XSTYPE,Ranges...> >
return mMapMult.slformat(std::dynamic_pointer_cast<GenMapRange<ORType,Op,XSTYPE,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis )));
}
template <class Op, SpaceType XSTYPE, class... Ranges>
vector<size_t> GenMapRange<Op,XSTYPE,Ranges...>::mapPos() const
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
vector<size_t> GenMapRange<ORType,Op,XSTYPE,Ranges...>::mapPos() const
{
return mMapPos;
}
/*
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
template <class... ERanges>
auto GenMapRange<Op,XSTYPE,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >
{
auto crange = std::tuple_cat(mSpace, erange->space());

View file

@ -87,26 +87,27 @@ namespace MultiArrayTools
};
template <class Op, SpaceType XSTYPE, class... Indices>
class GenMapIndex : public IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>,
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
class GenMapIndex : public IndexInterface<GenMapIndex<OIType,Op,XSTYPE,Indices...>,
typename Op::value_type>
//std::tuple<typename Indices::MetaType...> >
{
public:
typedef IndexInterface<GenMapIndex<Op,XSTYPE,Indices...>,
typedef IndexInterface<GenMapIndex<OIType,Op,XSTYPE,Indices...>,
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 typename Op::value_type MetaType;
typedef GenMapRange<Op,XSTYPE,typename Indices::RangeType...> RangeType;
typedef GenMapRange<typename OIType::RangeType,Op,XSTYPE,typename Indices::RangeType...> RangeType;
typedef GenMapIndex IType;
typedef SingleIndex<typename Op::value_type,XSTYPE> OIType;
//typedef SingleIndex<typename Op::value_type,XSTYPE> OIType;
static constexpr IndexType sType() { return IndexType::SINGLE; }
static constexpr size_t sDim() { return sizeof...(Indices); }
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
static void check_type() { static_assert( std::is_same<typename OIType::MetaType,typename Op::value_type>::value, "inconsitent value types" ); }
static constexpr SpaceType STYPE = XSTYPE;
static constexpr bool PARALLEL = false;
@ -207,12 +208,12 @@ namespace MultiArrayTools
*************************/
// NOT THREAD SAVE
template <class Op, SpaceType XSTYPE, class... Ranges>
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
class GenMapRangeFactory : public RangeFactoryBase
{
public:
typedef SingleRange<typename Op::value_type,XSTYPE> ORType;
typedef GenMapRange<Op,XSTYPE,Ranges...> oType;
//typedef SingleRange<typename Op::value_type,XSTYPE> ORType;
typedef GenMapRange<ORType,Op,XSTYPE,Ranges...> oType;
GenMapRangeFactory() = delete;
@ -222,14 +223,14 @@ namespace MultiArrayTools
template <class MA>
GenMapRangeFactory(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
const typename GenMapRange<Op,XSTYPE,Ranges...>::Space& st);
const typename GenMapRange<ORType,Op,XSTYPE,Ranges...>::Space& st);
template <class MA>
GenMapRangeFactory(const std::tuple<Op,MA>& mapf, const std::shared_ptr<Ranges>&... rs);
template <class MA>
GenMapRangeFactory(const std::tuple<Op,MA>& mapf,
const typename GenMapRange<Op,XSTYPE,Ranges...>::Space& space);
const typename GenMapRange<ORType,Op,XSTYPE,Ranges...>::Space& space);
virtual std::shared_ptr<RangeBase> create() override;
@ -243,16 +244,16 @@ namespace MultiArrayTools
* MapRange *
******************/
template <class Op, SpaceType XSTYPE, class... Ranges>
class GenMapRange : public RangeInterface<GenMapIndex<Op,XSTYPE,typename Ranges::IndexType...> >
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
class GenMapRange : public RangeInterface<GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...> >
{
public:
typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
typedef GenMapIndex<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 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 RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
@ -326,7 +327,7 @@ namespace MultiArrayTools
auto cat(const std::shared_ptr<GenMapRange<ERanges...> >& erange)
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >;
*/
friend GenMapRangeFactory<Op,XSTYPE,Ranges...>;
friend GenMapRangeFactory<ORType,Op,XSTYPE,Ranges...>;
static constexpr bool HASMETACONT = false;
static constexpr bool defaultable = false;
@ -335,17 +336,17 @@ namespace MultiArrayTools
};
// for legacy
template <class Op, class... Indices>
using MapIndex = GenMapIndex<Op,SpaceType::ANY,Indices...>;
template <class OIType, class Op, class... Indices>
using MapIndex = GenMapIndex<OIType,Op,SpaceType::ANY,Indices...>;
template <class Op, class... Ranges>
using MapRangeFactory = GenMapRangeFactory<Op,SpaceType::ANY,Ranges...>;
template <class ORType, class Op, class... Ranges>
using MapRangeFactory = GenMapRangeFactory<ORType,Op,SpaceType::ANY,Ranges...>;
template <class Op, class... Ranges>
using MapRange = GenMapRange<Op,SpaceType::ANY,Ranges...>;
template <class ORType, class Op, class... Ranges>
using MapRange = GenMapRange<ORType,Op,SpaceType::ANY,Ranges...>;
template <class Op, class... Indices>
auto mapResult/*<MapIndex<Op,Indices...> >*/(const std::shared_ptr<MapIndex<Op,Indices...> >& ind)
template <class OIType, class Op, class... Indices>
auto mapResult/*<MapIndex<Op,Indices...> >*/(const std::shared_ptr<MapIndex<OIType,Op,Indices...> >& ind)
-> decltype(ind->outIndex())
{
return ind->outIndex();

View file

@ -14,7 +14,7 @@ namespace MultiArrayTools
{
public:
template <class MapF, SpaceType XSTYPE, class... Ranges>
template <class ORType, class MapF, SpaceType XSTYPE, class... Ranges>
friend class GenMapRangeFactory;
private:

View file

@ -79,15 +79,15 @@ namespace MultiArrayTools
class ConstSliceDef;
// map_range.h
template <class MapF, SpaceType XSTYPE, class... Indices>
template <class OITpye, class MapF, SpaceType XSTYPE, class... Indices>
class GenMapIndex;
// map_range.h
template <class MapF, SpaceType XSTYPE, class... Ranges>
template <class ORType, class MapF, SpaceType XSTYPE, class... Ranges>
class GenMapRangeFactory;
// map_range.h
template <class MapF, SpaceType XSTYPE, class... Ranges>
template <class ORType, class MapF, SpaceType XSTYPE, class... Ranges>
class GenMapRange;
}

View file

@ -55,7 +55,8 @@ namespace
typedef std::remove_reference<decltype(*mkMapR( mkMapOp(std::make_shared<plus<size_t>>(),getIndex(sr1ptr),getIndex(sr2ptr)) , sr1ptr, sr2ptr ))>::type MpRange;
std::shared_ptr<MpRange> mpr1ptr;
typedef MpRange::ORType TRange;
//typedef MpRange::ORType TRange;
typedef std::remove_reference<decltype(*mpr1ptr->outRange())>::type TRange;
MapTest()
{