generalize map range: specification of out range type
This commit is contained in:
parent
75ead6fdba
commit
3ccc5277e3
5 changed files with 258 additions and 197 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include "slice.h"
|
#include "slice.h"
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include "pack_num.h"
|
#include "pack_num.h"
|
||||||
|
#include "map_range.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
|
|
|
@ -13,8 +13,8 @@ namespace MultiArrayTools
|
||||||
* OpExpr *
|
* OpExpr *
|
||||||
**************/
|
**************/
|
||||||
|
|
||||||
template <class MapF, class IndexPack, class Expr>
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
|
||||||
OpExpr<MapF,IndexPack,Expr>::OpExpr(const MapF& mapf, const IndexPack& ipack,
|
OpExpr<MapF,IndexPack,Expr,STYPE>::OpExpr(const MapF& mapf, const IndexPack& ipack,
|
||||||
const std::shared_ptr<OIType>& oind, size_t step, Expr ex) :
|
const std::shared_ptr<OIType>& oind, 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( std::forward<Expr>(ex) ),
|
mStep(step), mExpr( std::forward<Expr>(ex) ),
|
||||||
|
@ -26,8 +26,8 @@ namespace MultiArrayTools
|
||||||
assert(mIndPtr != nullptr);
|
assert(mIndPtr != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class IndexPack, class Expr>
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
|
||||||
inline void OpExpr<MapF,IndexPack,Expr>::operator()(size_t mlast,
|
inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast,
|
||||||
ExtType last) const
|
ExtType last) const
|
||||||
{
|
{
|
||||||
constexpr size_t NEXT = Op::SIZE;
|
constexpr size_t NEXT = Op::SIZE;
|
||||||
|
@ -40,8 +40,8 @@ namespace MultiArrayTools
|
||||||
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
|
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class IndexPack, class Expr>
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
|
||||||
inline void OpExpr<MapF,IndexPack,Expr>::operator()(size_t mlast) const
|
inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast) const
|
||||||
{
|
{
|
||||||
const ExtType last;
|
const ExtType last;
|
||||||
constexpr size_t NEXT = Op::SIZE;
|
constexpr size_t NEXT = Op::SIZE;
|
||||||
|
@ -52,8 +52,8 @@ namespace MultiArrayTools
|
||||||
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
|
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class IndexPack, class Expr>
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
|
||||||
auto OpExpr<MapF,IndexPack,Expr>::rootSteps(std::intptr_t iPtrNum) const
|
auto OpExpr<MapF,IndexPack,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) );
|
||||||
|
@ -87,10 +87,10 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
template <class MRange>
|
template <class MRange>
|
||||||
MapIndex<MapF,Indices...>::MapIndex(const std::shared_ptr<MRange>& range) :
|
GenMapIndex<MapF,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
|
||||||
IndexInterface<MapIndex<MapF,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,std::tuple<typename Indices::MetaType...> >(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);
|
||||||
|
@ -100,9 +100,9 @@ namespace MultiArrayTools
|
||||||
( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() );
|
( 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>
|
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");
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||||
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||||
|
@ -110,9 +110,9 @@ namespace MultiArrayTools
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
template <size_t DIR>
|
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");
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||||
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||||
|
@ -120,136 +120,136 @@ namespace MultiArrayTools
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
template <size_t N>
|
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);
|
return *std::get<N>(mIPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
template <size_t N>
|
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);
|
return std::get<N>(mIPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
auto MapIndex<MapF,Indices...>::outIndex() const -> std::shared_ptr<OIType>
|
auto GenMapIndex<MapF,XSTYPE,Indices...>::outIndex() const -> std::shared_ptr<OIType>
|
||||||
{
|
{
|
||||||
return mOutIndex;
|
return mOutIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator()(std::shared_ptr<Indices>&... 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>::swapIndices(mIPack, indices...);
|
||||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
IndexType MapIndex<MapF,Indices...>::type() const
|
IndexType GenMapIndex<MapF,XSTYPE,Indices...>::type() const
|
||||||
{
|
{
|
||||||
return IndexType::MULTI;
|
return IndexType::MULTI;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator=(size_t pos)
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator=(size_t pos)
|
||||||
{
|
{
|
||||||
IB::mPos = pos;
|
IB::mPos = pos;
|
||||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator++()
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator++()
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||||
++IB::mPos;
|
++IB::mPos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator--()
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator--()
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||||
--IB::mPos;
|
--IB::mPos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
int MapIndex<MapF,Indices...>::pp(std::intptr_t idxPtrNum)
|
int GenMapIndex<MapF,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;
|
IB::mPos += tmp;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
int MapIndex<MapF,Indices...>::mm(std::intptr_t idxPtrNum)
|
int GenMapIndex<MapF,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;
|
IB::mPos -= tmp;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
std::string MapIndex<MapF,Indices...>::stringMeta() const
|
std::string GenMapIndex<MapF,XSTYPE,Indices...>::stringMeta() const
|
||||||
{
|
{
|
||||||
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
typename MapIndex<MapF,Indices...>::MetaType MapIndex<MapF,Indices...>::meta() const
|
typename GenMapIndex<MapF,XSTYPE,Indices...>::MetaType GenMapIndex<MapF,XSTYPE,Indices...>::meta() const
|
||||||
{
|
{
|
||||||
MetaType metaTuple;
|
MetaType metaTuple;
|
||||||
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
|
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
|
||||||
return metaTuple;
|
return metaTuple;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::at(const MetaType& metaPos)
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,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);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
size_t MapIndex<MapF,Indices...>::dim() const
|
size_t GenMapIndex<MapF,XSTYPE,Indices...>::dim() const
|
||||||
{
|
{
|
||||||
return sizeof...(Indices);
|
return sizeof...(Indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
bool MapIndex<MapF,Indices...>::first() const
|
bool GenMapIndex<MapF,XSTYPE,Indices...>::first() const
|
||||||
{
|
{
|
||||||
return IB::mPos == 0;
|
return IB::mPos == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
bool MapIndex<MapF,Indices...>::last() const
|
bool GenMapIndex<MapF,XSTYPE,Indices...>::last() const
|
||||||
{
|
{
|
||||||
return IB::mPos == IB::mMax - 1;
|
return IB::mPos == IB::mMax - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
std::shared_ptr<typename MapIndex<MapF,Indices...>::RangeType>
|
std::shared_ptr<typename GenMapIndex<MapF,XSTYPE,Indices...>::RangeType>
|
||||||
MapIndex<MapF,Indices...>::range() const
|
GenMapIndex<MapF,XSTYPE,Indices...>::range() const
|
||||||
{
|
{
|
||||||
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
template <size_t N>
|
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);
|
return std::get<N>(mIPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
size_t MapIndex<MapF,Indices...>::getStepSize(size_t n) const
|
size_t GenMapIndex<MapF,XSTYPE,Indices...>::getStepSize(size_t n) const
|
||||||
{
|
{
|
||||||
if(n >= sizeof...(Indices)){
|
if(n >= sizeof...(Indices)){
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -258,14 +258,14 @@ namespace MultiArrayTools
|
||||||
return mBlockSizes[n+1];
|
return mBlockSizes[n+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
std::string MapIndex<MapF,Indices...>::id() const
|
std::string GenMapIndex<MapF,XSTYPE,Indices...>::id() const
|
||||||
{
|
{
|
||||||
return std::string("mul") + std::to_string(IB::mId);
|
return std::string("mul") + std::to_string(IB::mId);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
void MapIndex<MapF,Indices...>::print(size_t offset) const
|
void GenMapIndex<MapF,XSTYPE,Indices...>::print(size_t offset) const
|
||||||
{
|
{
|
||||||
if(offset == 0){
|
if(offset == 0){
|
||||||
std::cout << " === " << std::endl;
|
std::cout << " === " << std::endl;
|
||||||
|
@ -276,30 +276,30 @@ namespace MultiArrayTools
|
||||||
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
|
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
template <class Exprs>
|
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
|
-> 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 ) ) )
|
( range()->map(), mIPack, mOutIndex, step, exs ) ) )
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkForh
|
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 ) );
|
( range()->map(), mIPack, mOutIndex, step, exs ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
template <class Exprs>
|
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))
|
-> decltype(ifor(step, exs))
|
||||||
{
|
{
|
||||||
return ifor(step, exs);
|
return ifor(step, exs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
template <class Exprs>
|
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))
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
||||||
|
@ -309,28 +309,30 @@ namespace MultiArrayTools
|
||||||
* MapRangeFactory *
|
* MapRangeFactory *
|
||||||
*************************/
|
*************************/
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
MapRangeFactory<MapF,Ranges...>::MapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs)
|
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>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
MapRangeFactory<MapF,Ranges...>::MapRangeFactory(const MapF& mapf, const typename MapRange<MapF,Ranges...>::Space& st)
|
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>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
std::shared_ptr<RangeBase> MapRangeFactory<MapF,Ranges...>::create()
|
std::shared_ptr<RangeBase> GenMapRangeFactory<MapF,XSTYPE,Ranges...>::create()
|
||||||
{
|
{
|
||||||
mProd = checkIfCreated( std::dynamic_pointer_cast<oType>( mProd )->mSpace );
|
mProd = checkIfCreated( std::dynamic_pointer_cast<oType>( mProd )->mSpace );
|
||||||
setSelf();
|
setSelf();
|
||||||
return mProd;
|
return mProd;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
std::shared_ptr<RangeBase> MapRangeFactory<MapF,Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
|
std::shared_ptr<RangeBase> GenMapRangeFactory<MapF,XSTYPE,Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
|
||||||
{
|
{
|
||||||
std::shared_ptr<RangeBase> out;
|
std::shared_ptr<RangeBase> out;
|
||||||
bool check = false;
|
bool check = false;
|
||||||
|
@ -358,107 +360,151 @@ namespace MultiArrayTools
|
||||||
* MapRange *
|
* MapRange *
|
||||||
******************/
|
******************/
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <SpaceType XSTYPE>
|
||||||
void MapRange<MapF,Ranges...>::mkOutRange()
|
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);
|
//FunctionalMultiArray<typename MapF::value_type,MapF,Ranges...> fma(mSpace, mMapf);
|
||||||
std::map<typename MapF::value_type,size_t> mult;
|
OutRangeMaker<XSTYPE>::mk(mOutRange,mMapMult,mMapf);
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
MapRange<MapF,Ranges...>::MapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs) :
|
GenMapRange<MapF,XSTYPE,Ranges...>::GenMapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs) :
|
||||||
mSpace(std::make_tuple(rs...)),
|
mSpace(std::make_tuple(rs...)),
|
||||||
mMapf(mapf)
|
mMapf(mapf)
|
||||||
{
|
{
|
||||||
mkOutRange();
|
mkOutRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
MapRange<MapF,Ranges...>::MapRange(const MapF& mapf, const Space& space) :
|
GenMapRange<MapF,XSTYPE,Ranges...>::GenMapRange(const MapF& mapf, const Space& space) :
|
||||||
mSpace( space ),
|
mSpace( space ),
|
||||||
mMapf(mapf)
|
mMapf(mapf)
|
||||||
{
|
{
|
||||||
mkOutRange();
|
mkOutRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
template <size_t N>
|
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);
|
return *std::get<N>(mSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
template <size_t N>
|
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);
|
return std::get<N>(mSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
auto MapRange<MapF,Ranges...>::outRange() const -> std::shared_ptr<ORType>
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::outRange() const -> std::shared_ptr<ORType>
|
||||||
{
|
{
|
||||||
return mOutRange;
|
return mOutRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
const MapF& MapRange<MapF,Ranges...>::map() const
|
const MapF& GenMapRange<MapF,XSTYPE,Ranges...>::map() const
|
||||||
{
|
{
|
||||||
return mMapf;
|
return mMapf;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
size_t MapRange<MapF,Ranges...>::dim() const
|
size_t GenMapRange<MapF,XSTYPE,Ranges...>::dim() const
|
||||||
{
|
{
|
||||||
return sdim;
|
return sdim;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
size_t MapRange<MapF,Ranges...>::size() const
|
size_t GenMapRange<MapF,XSTYPE,Ranges...>::size() const
|
||||||
{
|
{
|
||||||
return mOutRange->size();
|
return mOutRange->size();
|
||||||
//return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
//return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
SpaceType MapRange<MapF,Ranges...>::spaceType() const
|
SpaceType GenMapRange<MapF,XSTYPE,Ranges...>::spaceType() const
|
||||||
{
|
{
|
||||||
return SpaceType::ANY;
|
return SpaceType::ANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
const typename MapRange<MapF,Ranges...>::Space& MapRange<MapF,Ranges...>::space() const
|
const typename GenMapRange<MapF,XSTYPE,Ranges...>::Space& GenMapRange<MapF,XSTYPE,Ranges...>::space() const
|
||||||
{
|
{
|
||||||
return mSpace;
|
return mSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
std::string MapRange<MapF,Ranges...>::stringMeta(size_t pos) const
|
std::string GenMapRange<MapF,XSTYPE,Ranges...>::stringMeta(size_t pos) const
|
||||||
{
|
{
|
||||||
auto i = begin();
|
auto i = begin();
|
||||||
i = pos;
|
i = pos;
|
||||||
return "[ " + RPackNum<sizeof...(Ranges)-1>::metaTupleToString(i.meta()) + " ]";
|
return "[ " + RPackNum<sizeof...(Ranges)-1>::metaTupleToString(i.meta()) + " ]";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
std::vector<char> MapRange<MapF,Ranges...>::data() const
|
std::vector<char> GenMapRange<MapF,XSTYPE,Ranges...>::data() const
|
||||||
{
|
{
|
||||||
DataHeader h = dataHeader();
|
DataHeader h = dataHeader();
|
||||||
std::vector<char> out;
|
std::vector<char> out;
|
||||||
|
@ -469,8 +515,8 @@ namespace MultiArrayTools
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
DataHeader MapRange<MapF,Ranges...>::dataHeader() const
|
DataHeader GenMapRange<MapF,XSTYPE,Ranges...>::dataHeader() const
|
||||||
{
|
{
|
||||||
DataHeader h;
|
DataHeader h;
|
||||||
h.spaceType = static_cast<int>( SpaceType::ANY );
|
h.spaceType = static_cast<int>( SpaceType::ANY );
|
||||||
|
@ -479,50 +525,51 @@ namespace MultiArrayTools
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::begin() const
|
typename GenMapRange<MapF,XSTYPE,Ranges...>::IndexType GenMapRange<MapF,XSTYPE,Ranges...>::begin() const
|
||||||
{
|
{
|
||||||
MapIndex<MapF,typename Ranges::IndexType...>
|
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 ) ) );
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||||
i = 0;
|
i = 0;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::end() const
|
typename GenMapRange<MapF,XSTYPE,Ranges...>::IndexType GenMapRange<MapF,XSTYPE,Ranges...>::end() const
|
||||||
{
|
{
|
||||||
MapIndex<MapF,typename Ranges::IndexType...>
|
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 )) );
|
( std::shared_ptr<RangeBase>( RB::mThis )) );
|
||||||
i = size();
|
i = size();
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
auto MapRange<MapF,Ranges...>::mapMultiplicity() const
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::mapMultiplicity() const
|
||||||
-> const MultiArray<size_t,ORType>&
|
-> const MultiArray<size_t,ORType>&
|
||||||
{
|
{
|
||||||
return mMapMult;
|
return mMapMult;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
auto MapRange<MapF,Ranges...>::explMapMultiplicity() const
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::explMapMultiplicity() const
|
||||||
-> MultiArray<size_t,MapRange>
|
-> MultiArray<size_t,GenMapRange>
|
||||||
{
|
{
|
||||||
auto tmp = mMapMult;
|
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 )) );
|
( std::shared_ptr<RangeBase>( RB::mThis )) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
/*
|
||||||
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
template <class... ERanges>
|
template <class... ERanges>
|
||||||
auto MapRange<MapF,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
|
||||||
-> std::shared_ptr<MapRange<Ranges...,ERanges...> >
|
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >
|
||||||
{
|
{
|
||||||
auto crange = std::tuple_cat(mSpace, erange->space());
|
auto crange = std::tuple_cat(mSpace, erange->space());
|
||||||
MapRangeFactory<Ranges...,ERanges...> rf(crange);
|
MapRangeFactory<Ranges...,ERanges...> rf(crange);
|
||||||
return std::dynamic_pointer_cast<MapRange<Ranges...,ERanges...> >(rf.create());
|
return std::dynamic_pointer_cast<MapRange<Ranges...,ERanges...> >(rf.create());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,11 @@ namespace MultiArrayTools
|
||||||
return PackNum<sizeof...(Indices)-1>::mkMapOp(ma, itp);
|
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
|
class OpExpr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef SingleIndex<typename MapF::value_type,SpaceType::ANY> OIType;
|
typedef SingleIndex<typename MapF::value_type,STYPE> OIType;
|
||||||
//typedef typename MapF::IndexPack IndexPack;
|
//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;
|
static constexpr size_t SIZE = Expr::SIZE;
|
||||||
|
@ -73,25 +73,25 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
class MapIndex : public IndexInterface<MapIndex<MapF,Indices...>,
|
class GenMapIndex : public IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,
|
||||||
std::tuple<typename Indices::MetaType...> >
|
std::tuple<typename Indices::MetaType...> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef IndexInterface<MapIndex<MapF,Indices...>,
|
typedef IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,
|
||||||
std::tuple<typename Indices::MetaType...> > 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 MapRange<MapF,typename Indices::RangeType...> RangeType;
|
typedef GenMapRange<MapF,XSTYPE,typename Indices::RangeType...> RangeType;
|
||||||
typedef MapIndex IType;
|
typedef GenMapIndex IType;
|
||||||
typedef SingleIndex<typename MapF::value_type,SpaceType::ANY> OIType;
|
typedef SingleIndex<typename MapF::value_type,XSTYPE> OIType;
|
||||||
|
|
||||||
static constexpr IndexType sType() { return IndexType::MULTI; }
|
static constexpr IndexType sType() { return IndexType::MULTI; }
|
||||||
static constexpr size_t sDim() { return sizeof...(Indices); }
|
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||||
static constexpr size_t totalDim() { return mkTotalDim<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;
|
static constexpr bool PARALLEL = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -104,7 +104,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
const IndexPack& pack() const { return mIPack; }
|
const IndexPack& pack() const { return mIPack; }
|
||||||
|
|
||||||
MapIndex() = delete;
|
GenMapIndex() = delete;
|
||||||
|
|
||||||
// NO DEFAULT HERE !!!
|
// NO DEFAULT HERE !!!
|
||||||
// ( have to assign sub-indices (ptr!) correctly )
|
// ( have to assign sub-indices (ptr!) correctly )
|
||||||
|
@ -112,13 +112,13 @@ namespace MultiArrayTools
|
||||||
//MapIndex& operator=(const MapIndex& in);
|
//MapIndex& operator=(const MapIndex& in);
|
||||||
|
|
||||||
template <class MRange>
|
template <class MRange>
|
||||||
MapIndex(const std::shared_ptr<MRange>& range);
|
GenMapIndex(const std::shared_ptr<MRange>& range);
|
||||||
|
|
||||||
template <size_t DIR>
|
template <size_t DIR>
|
||||||
MapIndex& up();
|
GenMapIndex& up();
|
||||||
|
|
||||||
template <size_t DIR>
|
template <size_t DIR>
|
||||||
MapIndex& down();
|
GenMapIndex& down();
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
||||||
|
@ -135,23 +135,23 @@ namespace MultiArrayTools
|
||||||
// MultiIndices CANNOT be influences be its subindices, so there is
|
// MultiIndices CANNOT be influences be its subindices, so there is
|
||||||
// NO foreign/external controll)
|
// NO foreign/external controll)
|
||||||
// Do NOT share index instances between two or more MapIndex instances
|
// 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 <<<<< ====
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||||
|
|
||||||
IndexType type() const;
|
IndexType type() const;
|
||||||
|
|
||||||
MapIndex& operator=(size_t pos);
|
GenMapIndex& operator=(size_t pos);
|
||||||
|
|
||||||
MapIndex& operator++();
|
GenMapIndex& operator++();
|
||||||
MapIndex& operator--();
|
GenMapIndex& operator--();
|
||||||
|
|
||||||
int pp(std::intptr_t idxPtrNum);
|
int pp(std::intptr_t idxPtrNum);
|
||||||
int mm(std::intptr_t idxPtrNum);
|
int mm(std::intptr_t idxPtrNum);
|
||||||
|
|
||||||
std::string stringMeta() const;
|
std::string stringMeta() const;
|
||||||
MetaType meta() const;
|
MetaType meta() const;
|
||||||
MapIndex& at(const MetaType& metaPos);
|
GenMapIndex& at(const MetaType& metaPos);
|
||||||
|
|
||||||
size_t dim() const;
|
size_t dim() const;
|
||||||
bool first() const;
|
bool first() const;
|
||||||
|
@ -169,7 +169,7 @@ 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<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!
|
// first step arg not used!
|
||||||
|
|
||||||
template <class Exprs>
|
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 *
|
* MapRangeFactory *
|
||||||
*************************/
|
*************************/
|
||||||
|
|
||||||
// NOT THREAD SAVE
|
// NOT THREAD SAVE
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
class MapRangeFactory : public RangeFactoryBase
|
class GenMapRangeFactory : public RangeFactoryBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef MapRange<MapF,Ranges...> oType;
|
typedef GenMapRange<MapF,XSTYPE,Ranges...> oType;
|
||||||
|
|
||||||
MapRangeFactory() = delete;
|
GenMapRangeFactory() = delete;
|
||||||
MapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
|
GenMapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
|
||||||
MapRangeFactory(const MapF& mapf, const typename MapRange<MapF,Ranges...>::Space& space);
|
GenMapRangeFactory(const MapF& mapf, const typename GenMapRange<MapF,XSTYPE,Ranges...>::Space& space);
|
||||||
|
|
||||||
virtual std::shared_ptr<RangeBase> create() override;
|
virtual std::shared_ptr<RangeBase> create() override;
|
||||||
|
|
||||||
|
@ -217,25 +211,25 @@ namespace MultiArrayTools
|
||||||
* MapRange *
|
* MapRange *
|
||||||
******************/
|
******************/
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
class MapRange : public RangeInterface<MapIndex<MapF,typename Ranges::IndexType...> >
|
class GenMapRange : public RangeInterface<GenMapIndex<MapF,XSTYPE,typename Ranges::IndexType...> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef RangeBase RB;
|
typedef RangeBase RB;
|
||||||
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
|
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
|
||||||
typedef MapIndex<MapF,typename Ranges::IndexType...> IndexType;
|
typedef GenMapIndex<MapF,XSTYPE,typename Ranges::IndexType...> IndexType;
|
||||||
typedef MapRange RangeType;
|
typedef GenMapRange RangeType;
|
||||||
typedef SingleRange<typename MapF::value_type,SpaceType::ANY> ORType;
|
typedef SingleRange<typename MapF::value_type,XSTYPE> ORType;
|
||||||
typedef SingleRangeFactory<typename MapF::value_type,SpaceType::ANY> ORFType;
|
typedef SingleRangeFactory<typename MapF::value_type,XSTYPE> ORFType;
|
||||||
//typedef typename RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
//typedef typename RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MapRange() = delete;
|
GenMapRange() = delete;
|
||||||
MapRange(const MapRange& in) = delete;
|
GenMapRange(const GenMapRange& in) = delete;
|
||||||
MapRange& operator=(const MapRange& in) = delete;
|
GenMapRange& operator=(const GenMapRange& in) = delete;
|
||||||
|
|
||||||
MapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
|
GenMapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
|
||||||
MapRange(const MapF& mapf, const Space& space);
|
GenMapRange(const MapF& mapf, const Space& space);
|
||||||
|
|
||||||
Space mSpace;
|
Space mSpace;
|
||||||
const MapF& mMapf;
|
const MapF& mMapf;
|
||||||
|
@ -273,14 +267,14 @@ namespace MultiArrayTools
|
||||||
virtual IndexType end() const final;
|
virtual IndexType end() const final;
|
||||||
|
|
||||||
const MultiArray<size_t,ORType>& mapMultiplicity() const;
|
const MultiArray<size_t,ORType>& mapMultiplicity() const;
|
||||||
MultiArray<size_t,MapRange> explMapMultiplicity() const;
|
MultiArray<size_t,GenMapRange> explMapMultiplicity() const;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
template <class... ERanges>
|
template <class... ERanges>
|
||||||
auto cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
|
auto cat(const std::shared_ptr<GenMapRange<ERanges...> >& erange)
|
||||||
-> std::shared_ptr<MapRange<Ranges...,ERanges...> >;
|
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >;
|
||||||
|
*/
|
||||||
friend MapRangeFactory<MapF,Ranges...>;
|
friend GenMapRangeFactory<MapF,XSTYPE,Ranges...>;
|
||||||
|
|
||||||
static constexpr bool HASMETACONT = false;
|
static constexpr bool HASMETACONT = false;
|
||||||
static constexpr bool defaultable = false;
|
static constexpr bool defaultable = false;
|
||||||
|
@ -288,6 +282,23 @@ namespace MultiArrayTools
|
||||||
static constexpr size_t SIZE = SubProp<MapF,Ranges...>::SIZE;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
friend class MapRangeFactory;
|
friend class GenMapRangeFactory;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated;
|
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#ifndef __mbase_def_h__
|
#ifndef __mbase_def_h__
|
||||||
#define __mbase_def_h__
|
#define __mbase_def_h__
|
||||||
|
|
||||||
|
#include "ranges/rbase_def.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
/***********************
|
/***********************
|
||||||
|
@ -76,16 +78,16 @@ namespace MultiArrayTools
|
||||||
class ConstSliceDef;
|
class ConstSliceDef;
|
||||||
|
|
||||||
// map_range.h
|
// map_range.h
|
||||||
template <class MapF, class... Indices>
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
||||||
class MapIndex;
|
class GenMapIndex;
|
||||||
|
|
||||||
// map_range.h
|
// map_range.h
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
class MapRangeFactory;
|
class GenMapRangeFactory;
|
||||||
|
|
||||||
// map_range.h
|
// map_range.h
|
||||||
template <class MapF, class... Ranges>
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
||||||
class MapRange;
|
class GenMapRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue