2018-08-07 21:49:21 +02:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
|
|
|
#ifndef __map_range_h__
|
|
|
|
#define __map_range_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <tuple>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
|
2018-08-18 16:24:13 +02:00
|
|
|
#include "mbase_def.h"
|
2018-08-07 21:49:21 +02:00
|
|
|
#include "ranges/range_base.h"
|
|
|
|
#include "ranges/index_base.h"
|
|
|
|
|
|
|
|
#include "ranges/rpack_num.h"
|
2018-08-18 16:24:13 +02:00
|
|
|
#include "map_range_factory_product_map.h"
|
2018-08-07 21:49:21 +02:00
|
|
|
#include "ranges/x_to_string.h"
|
|
|
|
#include "ranges/type_map.h"
|
|
|
|
|
2018-08-07 23:15:31 +02:00
|
|
|
#include "xfor/xfor.h"
|
|
|
|
|
2018-08-07 21:49:21 +02:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace MultiArrayHelper;
|
|
|
|
}
|
2018-08-08 18:20:08 +02:00
|
|
|
|
|
|
|
template <class MA, class... Indices>
|
|
|
|
auto mkMapOp(const MA& ma,
|
|
|
|
const std::tuple<std::shared_ptr<Indices>...>& itp)
|
2018-08-20 17:50:04 +02:00
|
|
|
-> decltype(PackNum<sizeof...(Indices)-1>::mkMapOp(ma, itp))
|
2018-08-08 18:20:08 +02:00
|
|
|
{
|
|
|
|
return PackNum<sizeof...(Indices)-1>::mkMapOp(ma, itp);
|
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
|
2018-08-08 18:20:08 +02:00
|
|
|
class OpExpr
|
|
|
|
{
|
|
|
|
public:
|
2019-03-12 21:00:15 +01:00
|
|
|
typedef decltype(mkMapOp(std::declval<MapF>(), std::declval<IndexPack>())) Op;
|
2019-02-06 12:21:42 +01:00
|
|
|
typedef SingleIndex<typename MapF::value_type,STYPE> OIType;
|
2018-08-20 17:50:04 +02:00
|
|
|
//typedef typename MapF::IndexPack IndexPack;
|
2018-08-08 18:20:08 +02:00
|
|
|
static constexpr size_t LAYER = Expr::LAYER + 1;
|
2019-03-12 21:00:15 +01:00
|
|
|
static constexpr size_t SIZE = Expr::SIZE + Op::SIZE;
|
2018-08-08 18:20:08 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
OpExpr() = default;
|
|
|
|
|
2018-08-18 16:24:13 +02:00
|
|
|
const OIType* mIndPtr;
|
2018-08-08 18:20:08 +02:00
|
|
|
size_t mSPos;
|
|
|
|
size_t mMax;
|
2018-09-17 16:21:23 +02:00
|
|
|
size_t mStep;
|
2018-08-08 18:20:08 +02:00
|
|
|
Expr mExpr;
|
|
|
|
Op mOp;
|
|
|
|
|
2018-08-18 16:24:13 +02:00
|
|
|
typedef decltype(mOp.rootSteps(std::declval<intptr_t>()).extend( mExpr.rootSteps(std::declval<intptr_t>()) )) ExtType;
|
|
|
|
ExtType mExt;
|
|
|
|
|
2018-08-08 18:20:08 +02:00
|
|
|
public:
|
|
|
|
OpExpr(const OpExpr& in) = default;
|
|
|
|
OpExpr(OpExpr&& in) = default;
|
|
|
|
OpExpr& operator=(const OpExpr& in) = default;
|
|
|
|
OpExpr& operator=(OpExpr&& in) = default;
|
|
|
|
|
2018-09-18 14:30:49 +02:00
|
|
|
OpExpr(const MapF& mapf, const IndexPack& ipack, const std::shared_ptr<OIType>& oind, size_t step, Expr ex);
|
2018-08-08 18:20:08 +02:00
|
|
|
|
2019-02-26 18:56:57 +01:00
|
|
|
inline void operator()(size_t mlast, ExtType last);
|
|
|
|
inline void operator()(size_t mlast = 0);
|
2018-08-08 18:20:08 +02:00
|
|
|
|
|
|
|
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
|
|
|
|
|
|
|
};
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Indices>
|
|
|
|
class GenMapIndex : public IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,
|
|
|
|
std::tuple<typename Indices::MetaType...> >
|
2018-08-07 21:49:21 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
typedef IndexInterface<GenMapIndex<MapF,XSTYPE,Indices...>,
|
2018-08-07 21:49:21 +02:00
|
|
|
std::tuple<typename Indices::MetaType...> > IB;
|
|
|
|
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
|
|
|
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
2019-02-06 12:21:42 +01:00
|
|
|
typedef GenMapRange<MapF,XSTYPE,typename Indices::RangeType...> RangeType;
|
|
|
|
typedef GenMapIndex IType;
|
|
|
|
typedef SingleIndex<typename MapF::value_type,XSTYPE> OIType;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
static constexpr IndexType sType() { return IndexType::MULTI; }
|
|
|
|
static constexpr size_t sDim() { return sizeof...(Indices); }
|
2018-08-20 17:50:04 +02:00
|
|
|
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
static constexpr SpaceType STYPE = XSTYPE;
|
2019-01-15 17:41:43 +01:00
|
|
|
static constexpr bool PARALLEL = false;
|
|
|
|
|
2018-08-07 21:49:21 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
IndexPack mIPack;
|
|
|
|
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
|
|
|
|
std::shared_ptr<OIType> mOutIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const IndexPack& pack() const { return mIPack; }
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex() = delete;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
// NO DEFAULT HERE !!!
|
|
|
|
// ( have to assign sub-indices (ptr!) correctly )
|
|
|
|
//MapIndex(const MapIndex& in);
|
|
|
|
//MapIndex& operator=(const MapIndex& in);
|
|
|
|
|
|
|
|
template <class MRange>
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex(const std::shared_ptr<MRange>& range);
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
template <size_t DIR>
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex& up();
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
template <size_t DIR>
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex& down();
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
|
|
|
|
|
2018-09-17 11:06:24 +02:00
|
|
|
template <size_t N>
|
|
|
|
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
|
|
|
|
|
2018-08-07 21:49:21 +02:00
|
|
|
std::shared_ptr<OIType> outIndex() const;
|
|
|
|
|
|
|
|
// raplace instances (in contrast to its analogon in ContainerIndex
|
|
|
|
// MultiIndices CANNOT be influences be its subindices, so there is
|
|
|
|
// NO foreign/external controll)
|
|
|
|
// Do NOT share index instances between two or more MapIndex instances
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex& operator()(std::shared_ptr<Indices>&... indices);
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
|
|
|
|
|
|
|
IndexType type() const;
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex& operator=(size_t pos);
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex& operator++();
|
|
|
|
GenMapIndex& operator--();
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
int pp(std::intptr_t idxPtrNum);
|
|
|
|
int mm(std::intptr_t idxPtrNum);
|
|
|
|
|
|
|
|
std::string stringMeta() const;
|
|
|
|
MetaType meta() const;
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapIndex& at(const MetaType& metaPos);
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2018-08-20 17:50:04 +02:00
|
|
|
size_t dim() const;
|
|
|
|
bool first() const;
|
|
|
|
bool last() const;
|
|
|
|
std::shared_ptr<RangeType> range() const;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
|
|
|
|
|
2018-08-20 17:50:04 +02:00
|
|
|
size_t getStepSize(size_t n) const;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
std::string id() const;
|
2018-08-20 17:50:04 +02:00
|
|
|
void print(size_t offset) const;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
template <class Exprs>
|
2018-09-17 16:21:23 +02:00
|
|
|
auto ifor(size_t step, Exprs exs) const
|
2018-08-20 17:50:04 +02:00
|
|
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
|
2019-02-06 12:21:42 +01:00
|
|
|
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs,XSTYPE>( range()->map(), mIPack, mOutIndex, step, exs ) ) );
|
2018-09-17 16:21:23 +02:00
|
|
|
// first step arg not used!
|
2019-01-15 17:41:43 +01:00
|
|
|
|
|
|
|
template <class Exprs>
|
|
|
|
auto pifor(size_t step, Exprs exs) const
|
|
|
|
-> decltype(ifor(step, exs)); // NO MULTITHREADING
|
|
|
|
|
2018-08-07 21:49:21 +02:00
|
|
|
/*
|
|
|
|
template <class Exprs>
|
|
|
|
auto iforh(Exprs exs) const
|
|
|
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*************************
|
|
|
|
* MapRangeFactory *
|
|
|
|
*************************/
|
|
|
|
|
|
|
|
// NOT THREAD SAVE
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
class GenMapRangeFactory : public RangeFactoryBase
|
2018-08-07 21:49:21 +02:00
|
|
|
{
|
|
|
|
public:
|
2019-02-06 12:21:42 +01:00
|
|
|
typedef GenMapRange<MapF,XSTYPE,Ranges...> oType;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapRangeFactory() = delete;
|
|
|
|
GenMapRangeFactory(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
|
|
|
|
GenMapRangeFactory(const MapF& mapf, const typename GenMapRange<MapF,XSTYPE,Ranges...>::Space& space);
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
virtual std::shared_ptr<RangeBase> create() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
std::shared_ptr<RangeBase> checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************
|
|
|
|
* MapRange *
|
|
|
|
******************/
|
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
template <class MapF, SpaceType XSTYPE, class... Ranges>
|
|
|
|
class GenMapRange : public RangeInterface<GenMapIndex<MapF,XSTYPE,typename Ranges::IndexType...> >
|
2018-08-07 21:49:21 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef RangeBase RB;
|
|
|
|
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
|
2019-02-06 12:21:42 +01:00
|
|
|
typedef GenMapIndex<MapF,XSTYPE,typename Ranges::IndexType...> IndexType;
|
|
|
|
typedef GenMapRange RangeType;
|
|
|
|
typedef SingleRange<typename MapF::value_type,XSTYPE> ORType;
|
|
|
|
typedef SingleRangeFactory<typename MapF::value_type,XSTYPE> ORFType;
|
2018-08-07 21:49:21 +02:00
|
|
|
//typedef typename RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
|
|
|
|
|
|
|
protected:
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapRange() = delete;
|
|
|
|
GenMapRange(const GenMapRange& in) = delete;
|
|
|
|
GenMapRange& operator=(const GenMapRange& in) = delete;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
GenMapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs);
|
|
|
|
GenMapRange(const MapF& mapf, const Space& space);
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
Space mSpace;
|
2018-08-08 18:20:08 +02:00
|
|
|
const MapF& mMapf;
|
2018-08-18 16:24:13 +02:00
|
|
|
std::shared_ptr<ORType> mOutRange;
|
2018-08-20 17:50:04 +02:00
|
|
|
MultiArray<size_t,ORType> mMapMult;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2018-08-20 17:50:04 +02:00
|
|
|
private:
|
|
|
|
void mkOutRange();
|
|
|
|
|
2018-08-07 21:49:21 +02:00
|
|
|
public:
|
|
|
|
|
2018-08-20 17:50:04 +02:00
|
|
|
static constexpr size_t sdim = sizeof...(Ranges);
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto get() const -> decltype( *std::get<N>( mSpace ) )&;
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
|
|
|
|
2018-08-18 16:24:13 +02:00
|
|
|
std::shared_ptr<ORType> outRange() const;
|
2018-08-08 18:20:08 +02:00
|
|
|
const MapF& map() const;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
virtual size_t dim() const final;
|
|
|
|
virtual size_t size() const final;
|
|
|
|
|
|
|
|
virtual SpaceType spaceType() const final;
|
2018-11-07 10:58:07 +01:00
|
|
|
virtual DataHeader dataHeader() const final;
|
|
|
|
|
2019-03-14 14:20:38 +01:00
|
|
|
virtual size_t typeNum() const final;
|
|
|
|
virtual size_t cmeta(char* target, size_t pos) const final;
|
2018-08-07 21:49:21 +02:00
|
|
|
virtual std::string stringMeta(size_t pos) const final;
|
2019-02-13 21:59:13 +01:00
|
|
|
virtual vector<char> data() const final;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
const Space& space() const;
|
|
|
|
|
|
|
|
virtual IndexType begin() const final;
|
|
|
|
virtual IndexType end() const final;
|
|
|
|
|
2018-08-20 17:50:04 +02:00
|
|
|
const MultiArray<size_t,ORType>& mapMultiplicity() const;
|
2019-02-06 12:21:42 +01:00
|
|
|
MultiArray<size_t,GenMapRange> explMapMultiplicity() const;
|
2018-09-17 11:06:24 +02:00
|
|
|
|
2019-03-11 19:24:34 +01:00
|
|
|
vector<size_t> mapPos() const;
|
2019-03-08 13:09:10 +01:00
|
|
|
|
2019-02-06 12:21:42 +01:00
|
|
|
/*
|
2018-08-07 21:49:21 +02:00
|
|
|
template <class... ERanges>
|
2019-02-06 12:21:42 +01:00
|
|
|
auto cat(const std::shared_ptr<GenMapRange<ERanges...> >& erange)
|
|
|
|
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >;
|
|
|
|
*/
|
|
|
|
friend GenMapRangeFactory<MapF,XSTYPE,Ranges...>;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
static constexpr bool HASMETACONT = false;
|
|
|
|
static constexpr bool defaultable = false;
|
|
|
|
static constexpr size_t ISSTATIC = SubProp<MapF,Ranges...>::ISSTATIC;
|
|
|
|
static constexpr size_t SIZE = SubProp<MapF,Ranges...>::SIZE;
|
|
|
|
};
|
2019-02-06 12:21:42 +01:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2018-08-07 21:49:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|