2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
#include "map_range.h"
|
2019-02-06 15:09:21 +01:00
|
|
|
#include <type_traits>
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace MultiArrayHelper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************
|
|
|
|
* OpExpr *
|
|
|
|
**************/
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
|
|
|
|
OpExpr<MapF,IndexPack,Expr,STYPE>::OpExpr(const MapF& mapf, const IndexPack& ipack,
|
2018-10-30 15:06:29 +01:00
|
|
|
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) ),
|
|
|
|
mOp(mkMapOp(mapf, ipack)),
|
|
|
|
//mExt(ex.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
|
|
|
mExt( mOp.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ) ).extend
|
|
|
|
( ex.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ) ) ) )
|
|
|
|
{
|
|
|
|
assert(mIndPtr != nullptr);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
|
|
|
|
inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast,
|
2019-02-26 18:56:57 +01:00
|
|
|
ExtType last)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
constexpr size_t NEXT = Op::SIZE;
|
|
|
|
const ExtType nxpos = last;
|
|
|
|
const size_t pos = mIndPtr->posAt( mOp.get( nxpos ) );
|
|
|
|
//VCHECK(pos);
|
|
|
|
const ExtType npos = last + mExt*pos;
|
|
|
|
//VCHECK(npos.next().next().val());
|
|
|
|
const size_t mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
|
|
|
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
|
2019-02-26 18:56:57 +01:00
|
|
|
inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
const ExtType last;
|
|
|
|
constexpr size_t NEXT = Op::SIZE;
|
|
|
|
const ExtType nxpos = last;
|
|
|
|
const size_t pos = mIndPtr->posAt( mOp.get( nxpos ) );
|
|
|
|
const ExtType npos = last + mExt*pos;
|
|
|
|
const size_t mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
|
|
|
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
|
|
|
|
auto OpExpr<MapF,IndexPack,Expr,STYPE>::rootSteps(std::intptr_t iPtrNum) const
|
2018-10-30 15:06:29 +01:00
|
|
|
-> ExtType
|
|
|
|
{
|
|
|
|
return mOp.rootSteps(iPtrNum).extend( mExpr.rootSteps(iPtrNum) );
|
|
|
|
//return mExpr.rootSteps(iPtrNum).extend( mOp.rootSteps(iPtrNum) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -> define in range_base.cc
|
|
|
|
//std::shared_ptr<RangeFactoryBase> mkMULTI(const char** dp);
|
|
|
|
|
|
|
|
/******************
|
|
|
|
* MapIndex *
|
|
|
|
******************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
template <class MapF, class... Indices>
|
|
|
|
MapIndex<MapF,Indices...>::MapIndex(const MapIndex<MapF,Indices...>& in) :
|
|
|
|
IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
|
|
|
|
{
|
|
|
|
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class MapF, class... Indices>
|
|
|
|
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator=(const MapIndex<MapF,Indices...>& in)
|
|
|
|
{
|
|
|
|
IndexI::operator=(in);
|
|
|
|
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <class MRange>
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
|
|
|
|
IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
|
|
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
|
|
|
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack); // has one more element!
|
|
|
|
mOutIndex = std::make_shared<OIType>
|
|
|
|
( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() );
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <size_t DIR>
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::up()
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
|
|
|
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
|
|
|
RPackNum<DIR>::pp( mIPack );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <size_t DIR>
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::down()
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
|
|
|
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
|
|
|
RPackNum<DIR>::mm( mIPack );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <size_t N>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapIndex<MapF,XSTYPE,Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return *std::get<N>(mIPack);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <size_t N>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapIndex<MapF,XSTYPE,Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return std::get<N>(mIPack);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
auto GenMapIndex<MapF,XSTYPE,Indices...>::outIndex() const -> std::shared_ptr<OIType>
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return mOutIndex;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator()(std::shared_ptr<Indices>&... indices)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
|
|
|
|
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
IndexType GenMapIndex<MapF,XSTYPE,Indices...>::type() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return IndexType::MULTI;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator=(size_t pos)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
|
|
|
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator++()
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
|
|
|
++IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::operator--()
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
|
|
|
--IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
int GenMapIndex<MapF,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
|
|
|
IB::mPos += tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
int GenMapIndex<MapF,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
|
|
|
IB::mPos -= tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
std::string GenMapIndex<MapF,XSTYPE,Indices...>::stringMeta() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
typename GenMapIndex<MapF,XSTYPE,Indices...>::MetaType GenMapIndex<MapF,XSTYPE,Indices...>::meta() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
MetaType metaTuple;
|
|
|
|
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
|
|
|
|
return metaTuple;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>& GenMapIndex<MapF,XSTYPE,Indices...>::at(const MetaType& metaPos)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
size_t GenMapIndex<MapF,XSTYPE,Indices...>::dim() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return sizeof...(Indices);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
bool GenMapIndex<MapF,XSTYPE,Indices...>::first() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return IB::mPos == 0;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
bool GenMapIndex<MapF,XSTYPE,Indices...>::last() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return IB::mPos == IB::mMax - 1;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
std::shared_ptr<typename GenMapIndex<MapF,XSTYPE,Indices...>::RangeType>
|
|
|
|
GenMapIndex<MapF,XSTYPE,Indices...>::range() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <size_t N>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapIndex<MapF,XSTYPE,Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return std::get<N>(mIPack);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
size_t GenMapIndex<MapF,XSTYPE,Indices...>::getStepSize(size_t n) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
if(n >= sizeof...(Indices)){
|
|
|
|
assert(0);
|
|
|
|
// throw !!
|
|
|
|
}
|
|
|
|
return mBlockSizes[n+1];
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
std::string GenMapIndex<MapF,XSTYPE,Indices...>::id() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return std::string("mul") + std::to_string(IB::mId);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
void GenMapIndex<MapF,XSTYPE,Indices...>::print(size_t offset) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
if(offset == 0){
|
|
|
|
std::cout << " === " << std::endl;
|
|
|
|
}
|
|
|
|
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
|
|
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
|
|
|
<< "]" << "(" << IB::mRangePtr << "): " << meta() << std::endl;
|
|
|
|
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <class Exprs>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapIndex<MapF,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const
|
2018-10-30 15:06:29 +01:00
|
|
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
|
2019-02-06 12:21:42 +01:00
|
|
|
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs,XSTYPE>
|
2018-10-30 15:06:29 +01:00
|
|
|
( range()->map(), mIPack, mOutIndex, step, exs ) ) )
|
|
|
|
{
|
|
|
|
return RPackNum<sizeof...(Indices)-1>::mkForh
|
2019-02-06 12:21:42 +01:00
|
|
|
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs,XSTYPE>
|
2018-10-30 15:06:29 +01:00
|
|
|
( range()->map(), mIPack, mOutIndex, step, exs ) );
|
|
|
|
}
|
2019-01-15 17:41:43 +01:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2019-01-15 17:41:43 +01:00
|
|
|
template <class Exprs>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapIndex<MapF,XSTYPE,Indices...>::pifor(size_t step, Exprs exs) const
|
2019-01-15 17:41:43 +01:00
|
|
|
-> decltype(ifor(step, exs))
|
|
|
|
{
|
|
|
|
return ifor(step, exs);
|
|
|
|
}
|
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
/*
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <class Exprs>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapIndex<MapF,XSTYPE,Indices...>::iforh(Exprs exs) const
|
2018-10-30 15:06:29 +01:00
|
|
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
|
|
|
{
|
|
|
|
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
/*************************
|
|
|
|
* MapRangeFactory *
|
|
|
|
*************************/
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
GenMapRangeFactory<MapF,XSTYPE,Ranges...>::GenMapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2019-02-06 12:21:42 +01:00
|
|
|
mProd = std::shared_ptr< GenMapRange<MapF,XSTYPE,Ranges...> >
|
|
|
|
( new GenMapRange<MapF,XSTYPE,Ranges...>( mapf, rs... ) );
|
2018-10-30 15:06:29 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
GenMapRangeFactory<MapF,XSTYPE,Ranges...>::GenMapRangeFactory(const MapF& mapf, const typename GenMapRange<MapF,XSTYPE,Ranges...>::Space& st)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2019-02-06 12:21:42 +01:00
|
|
|
mProd = std::shared_ptr< GenMapRange<MapF,XSTYPE,Ranges...> >
|
|
|
|
( new GenMapRange<MapF,XSTYPE,Ranges...>( mapf, st ) );
|
2018-10-30 15:06:29 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
std::shared_ptr<RangeBase> GenMapRangeFactory<MapF,XSTYPE,Ranges...>::create()
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
mProd = checkIfCreated( std::dynamic_pointer_cast<oType>( mProd )->mSpace );
|
|
|
|
setSelf();
|
|
|
|
return mProd;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
std::shared_ptr<RangeBase> GenMapRangeFactory<MapF,XSTYPE,Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
std::shared_ptr<RangeBase> out;
|
|
|
|
bool check = false;
|
|
|
|
for(auto& x: MapRangeFactoryProductMap::mAleadyCreated){
|
|
|
|
if(x.second.size() == sizeof...(Ranges)){
|
|
|
|
check = RPackNum<sizeof...(Ranges)-1>::checkIfCreated(ptp, x.second);
|
|
|
|
if(check){
|
|
|
|
out = x.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(not check){
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<std::intptr_t> pv(sizeof...(Ranges));
|
2018-10-30 15:06:29 +01:00
|
|
|
RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv);
|
|
|
|
pv.push_back( reinterpret_cast<std::intptr_t>
|
|
|
|
( &std::dynamic_pointer_cast<oType>( mProd )->mMapf ) );
|
|
|
|
MapRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
|
|
|
out = mProd;
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************
|
|
|
|
* MapRange *
|
|
|
|
******************/
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <SpaceType XSTYPE>
|
|
|
|
struct OutRangeMaker
|
|
|
|
{};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct OutRangeMaker<SpaceType::ANY>
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2019-02-06 12:21:42 +01:00
|
|
|
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]]++;
|
|
|
|
}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<typename MapF::value_type> outmeta(mult.size());
|
|
|
|
vector<size_t> outmult(mult.size());
|
2019-02-06 12:21:42 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2019-02-06 15:09:21 +01:00
|
|
|
static_assert( std::is_same<size_t,typename MapF::value_type>::value,
|
|
|
|
"out range value type for NONE must be size_t" );
|
2019-02-06 12:21:42 +01:00
|
|
|
size_t max = 0;
|
|
|
|
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
|
2019-02-06 15:09:21 +01:00
|
|
|
max = mapf[ii]+1 > max ? mapf[ii]+1 : max;
|
2019-02-06 12:21:42 +01:00
|
|
|
}
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<size_t> mult(max,0);
|
2019-02-06 12:21:42 +01:00
|
|
|
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
|
|
|
|
mult[mapf[ii]]++;
|
|
|
|
}
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<size_t> outmult(mult.size());
|
2019-02-06 12:21:42 +01:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
};
|
2018-10-30 15:06:29 +01:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
void GenMapRange<MapF,XSTYPE,Ranges...>::mkOutRange()
|
|
|
|
{
|
|
|
|
//FunctionalMultiArray<typename MapF::value_type,MapF,Ranges...> fma(mSpace, mMapf);
|
|
|
|
OutRangeMaker<XSTYPE>::mk(mOutRange,mMapMult,mMapf);
|
2018-10-30 15:06:29 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
GenMapRange<MapF,XSTYPE,Ranges...>::GenMapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs) :
|
2018-10-30 15:06:29 +01:00
|
|
|
mSpace(std::make_tuple(rs...)),
|
|
|
|
mMapf(mapf)
|
|
|
|
{
|
|
|
|
mkOutRange();
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
GenMapRange<MapF,XSTYPE,Ranges...>::GenMapRange(const MapF& mapf, const Space& space) :
|
2018-10-30 15:06:29 +01:00
|
|
|
mSpace( space ),
|
|
|
|
mMapf(mapf)
|
|
|
|
{
|
|
|
|
mkOutRange();
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <size_t N>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return *std::get<N>(mSpace);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <size_t N>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return std::get<N>(mSpace);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::outRange() const -> std::shared_ptr<ORType>
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return mOutRange;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
const MapF& GenMapRange<MapF,XSTYPE,Ranges...>::map() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return mMapf;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
size_t GenMapRange<MapF,XSTYPE,Ranges...>::dim() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return sdim;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
size_t GenMapRange<MapF,XSTYPE,Ranges...>::size() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return mOutRange->size();
|
|
|
|
//return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
SpaceType GenMapRange<MapF,XSTYPE,Ranges...>::spaceType() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return SpaceType::ANY;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
const typename GenMapRange<MapF,XSTYPE,Ranges...>::Space& GenMapRange<MapF,XSTYPE,Ranges...>::space() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return mSpace;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
std::string GenMapRange<MapF,XSTYPE,Ranges...>::stringMeta(size_t pos) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
auto i = begin();
|
|
|
|
i = pos;
|
|
|
|
return "[ " + RPackNum<sizeof...(Ranges)-1>::metaTupleToString(i.meta()) + " ]";
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> GenMapRange<MapF,XSTYPE,Ranges...>::data() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2018-11-07 10:58:07 +01:00
|
|
|
DataHeader h = dataHeader();
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> out;
|
2018-10-30 15:06:29 +01:00
|
|
|
//out.reserve(h.metaSize + sizeof(DataHeader));
|
|
|
|
char* hcp = reinterpret_cast<char*>(&h);
|
|
|
|
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
|
|
|
|
RPackNum<sizeof...(Ranges)-1>::fillRangeDataVec(out, mSpace);
|
|
|
|
return out;
|
|
|
|
}
|
2018-11-07 10:58:07 +01:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
DataHeader GenMapRange<MapF,XSTYPE,Ranges...>::dataHeader() const
|
2018-11-07 10:58:07 +01:00
|
|
|
{
|
|
|
|
DataHeader h;
|
|
|
|
h.spaceType = static_cast<int>( SpaceType::ANY );
|
|
|
|
h.metaSize = sizeof...(Ranges);
|
|
|
|
h.multiple = 1;
|
|
|
|
return h;
|
|
|
|
}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
typename GenMapRange<MapF,XSTYPE,Ranges...>::IndexType GenMapRange<MapF,XSTYPE,Ranges...>::begin() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2019-02-06 14:11:17 +01:00
|
|
|
GenMapIndex<MapF,XSTYPE,typename Ranges::IndexType...>
|
2019-02-06 12:21:42 +01:00
|
|
|
i( std::dynamic_pointer_cast<GenMapRange<MapF,XSTYPE,Ranges...> >
|
2018-10-30 15:06:29 +01:00
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = 0;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
typename GenMapRange<MapF,XSTYPE,Ranges...>::IndexType GenMapRange<MapF,XSTYPE,Ranges...>::end() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2019-02-06 14:11:17 +01:00
|
|
|
GenMapIndex<MapF,XSTYPE,typename Ranges::IndexType...>
|
2019-02-06 12:21:42 +01:00
|
|
|
i( std::dynamic_pointer_cast<GenMapRange<MapF,XSTYPE,Ranges...> >
|
2018-10-30 15:06:29 +01:00
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis )) );
|
|
|
|
i = size();
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::mapMultiplicity() const
|
2018-10-30 15:06:29 +01:00
|
|
|
-> const MultiArray<size_t,ORType>&
|
|
|
|
{
|
|
|
|
return mMapMult;
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::explMapMultiplicity() const
|
|
|
|
-> MultiArray<size_t,GenMapRange>
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
auto tmp = mMapMult;
|
2019-02-06 12:21:42 +01:00
|
|
|
return tmp.format( std::dynamic_pointer_cast<GenMapRange<MapF,XSTYPE,Ranges...> >
|
2018-10-30 15:06:29 +01:00
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis )) );
|
|
|
|
}
|
2019-02-06 12:21:42 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
2018-10-30 15:06:29 +01:00
|
|
|
template <class... ERanges>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto GenMapRange<MapF,XSTYPE,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
|
|
|
|
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
auto crange = std::tuple_cat(mSpace, erange->space());
|
|
|
|
MapRangeFactory<Ranges...,ERanges...> rf(crange);
|
|
|
|
return std::dynamic_pointer_cast<MapRange<Ranges...,ERanges...> >(rf.create());
|
|
|
|
}
|
2019-02-06 12:21:42 +01:00
|
|
|
*/
|
2018-10-30 15:06:29 +01:00
|
|
|
}
|