cnorxz/orig/include/map_range.h

355 lines
11 KiB
C
Raw Normal View History

2018-08-07 21:49:21 +02:00
// -*- C++ -*-
#ifndef __cxz_map_range_h__
#define __cxz_map_range_h__
2018-08-07 21:49:21 +02:00
#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"
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"
2021-07-28 20:29:56 +02:00
namespace CNORXZ
2018-08-07 21:49:21 +02:00
{
namespace
{
2021-07-28 20:29:56 +02:00
using namespace CNORXZInternal;
2018-08-07 21:49:21 +02:00
}
2019-03-29 12:58:39 +01:00
template <class Func, class... Indices>
auto mkMapOp(const std::shared_ptr<Func>& func,
const std::shared_ptr<Indices>&... is)
-> decltype(std::make_tuple(FunctionalArray<typename Func::value_type,Func,
2019-03-29 12:58:39 +01:00
typename Indices::RangeType...>().exec(is...),
FunctionalArray<typename Func::value_type,Func,
2019-03-29 12:58:39 +01:00
typename Indices::RangeType...>()))
{
typedef FunctionalArray<typename Func::value_type,Func,typename Indices::RangeType...> FMA;
2019-03-29 12:58:39 +01:00
if(Func::FISSTATIC){
FMA fma(is->range()...);
return std::make_tuple(fma.exec(is...),fma);
}
else {
FMA fma(is->range()...,func);
return std::make_tuple(fma.exec(is...),fma);
}
}
2019-03-29 12:58:39 +01:00
2019-04-03 16:26:53 +02:00
template <class Op, class Index, class Expr, SpaceType STYPE = SpaceType::ANY>
2019-03-29 12:58:39 +01:00
//template <class MapF, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
2021-01-14 17:40:08 +01:00
class OpExpr : public ExpressionBase
{
public:
2019-05-10 18:14:13 +02:00
//typedef typename Index::OIType OIType;
2019-04-03 16:26:53 +02:00
//typedef SingleIndex<typename Op::value_type,STYPE> OIType;
static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE + Op::SIZE;
2021-01-24 02:10:06 +01:00
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
private:
OpExpr() = default;
2019-04-03 16:26:53 +02:00
const Index* mIndPtr;
//const OIType* mIndPtr;
size_t mSPos;
size_t mMax;
size_t mStep;
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;
public:
OpExpr(const OpExpr& in) = default;
OpExpr(OpExpr&& in) = default;
OpExpr& operator=(const OpExpr& in) = default;
OpExpr& operator=(OpExpr&& in) = default;
2019-03-29 12:58:39 +01:00
2019-04-03 16:26:53 +02:00
OpExpr(const Op& mapf, const Index* ind, size_t step, Expr ex);
2021-01-14 17:40:08 +01:00
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final;
2021-01-23 19:40:15 +01:00
template <size_t VS>
inline auto vec() const { return *this; }
2021-01-14 17:40:08 +01:00
inline void operator()(size_t mlast, DExt last) override final;
2019-02-26 18:56:57 +01:00
inline void operator()(size_t mlast, ExtType last);
2021-01-14 17:40:08 +01:00
inline void operator()(size_t mlast = 0) override final;
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
2021-01-14 17:40:08 +01:00
virtual DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
virtual DExt dExtension() const override final;
};
2018-08-07 21:49:21 +02:00
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...> >
2018-08-07 21:49:21 +02:00
{
public:
typedef IndexInterface<GenMapIndex<OIType,Op,XSTYPE,Indices...>,
typename Op::value_type> IB;
//std::tuple<typename Indices::MetaType...> > IB;
2018-08-07 21:49:21 +02:00
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
//typedef std::tuple<typename Indices::MetaType...> MetaType;
typedef typename Op::value_type MetaType;
typedef GenMapRange<typename OIType::RangeType,Op,XSTYPE,typename Indices::RangeType...> RangeType;
typedef GenMapIndex IType;
//typedef SingleIndex<typename Op::value_type,XSTYPE> OIType;
2018-08-07 21:49:21 +02:00
2019-04-03 16:26:53 +02:00
static constexpr IndexType sType() { return IndexType::SINGLE; }
2018-08-07 21:49:21 +02:00
static constexpr size_t sDim() { return sizeof...(Indices); }
2021-05-27 23:29:04 +02:00
static constexpr size_t totalDim() { return (... * Indices::totalDim()); }
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;
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; }
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>
GenMapIndex(const std::shared_ptr<MRange>& range);
2018-08-07 21:49:21 +02:00
template <size_t DIR>
GenMapIndex& up();
2018-08-07 21:49:21 +02:00
template <size_t DIR>
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;
2021-05-28 17:29:13 +02:00
// raplace instances (in contrast to its analogon in ConstContainerIndex
2018-08-07 21:49:21 +02:00
// 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-04-03 16:26:53 +02:00
GenMapIndex& operator()(const std::shared_ptr<Indices>&... indices);
2021-05-07 17:35:59 +02:00
GenMapIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& indices);
2018-08-07 21:49:21 +02:00
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
IndexType type() const;
GenMapIndex& operator=(size_t pos);
2018-08-07 21:49:21 +02: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;
GenMapIndex& at(const MetaType& metaPos);
2019-04-03 16:26:53 +02:00
size_t posAt(const MetaType& metaPos) const;
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 ) )&;
size_t getStepSize(size_t n) const;
2018-08-07 21:49:21 +02:00
template <class Exprs>
2021-05-07 17:35:59 +02:00
auto ifor(size_t step, Exprs exs) const; // first step arg not used!
2019-01-15 17:41:43 +01:00
template <class Exprs>
2021-05-07 17:35:59 +02:00
auto pifor(size_t step, Exprs exs) const; // NO MULTITHREADING
2018-08-07 21:49:21 +02:00
template <class Exprs>
2021-05-07 17:35:59 +02:00
auto iforh(size_t step, Exprs exs) const;
2018-08-07 21:49:21 +02:00
};
/*************************
* MapRangeFactory *
*************************/
// NOT THREAD SAVE
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
class GenMapRangeFactory : public RangeFactoryBase
2018-08-07 21:49:21 +02:00
{
public:
//typedef SingleRange<typename Op::value_type,XSTYPE> ORType;
typedef GenMapRange<ORType,Op,XSTYPE,Ranges...> oType;
2018-08-07 21:49:21 +02:00
GenMapRangeFactory() = delete;
2019-03-29 12:58:39 +01:00
template <class MA>
GenMapRangeFactory(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
const std::shared_ptr<Ranges>&... rs);
template <class MA>
GenMapRangeFactory(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
const typename GenMapRange<ORType,Op,XSTYPE,Ranges...>::Space& st);
2019-03-29 12:58:39 +01:00
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<ORType,Op,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 *
******************/
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
class GenMapRange : public RangeInterface<GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...> >
2018-08-07 21:49:21 +02:00
{
public:
typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
typedef GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...> IndexType;
typedef typename Op::value_type MetaType;
2018-08-07 21:49:21 +02:00
protected:
GenMapRange() = delete;
GenMapRange(const GenMapRange& in) = delete;
GenMapRange& operator=(const GenMapRange& in) = delete;
2019-03-29 12:58:39 +01:00
template <class MA>
GenMapRange(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
const std::shared_ptr<Ranges>&... rs);
template <class MA>
GenMapRange(const std::shared_ptr<ORType>& outr, const std::tuple<Op,MA>& mapf,
const Space& space);
2019-03-29 12:58:39 +01:00
template <class MA>
GenMapRange(const std::tuple<Op,MA>& mapf, const Space& space);
template <class MA>
GenMapRange(const std::tuple<Op,MA>& mapf, const std::shared_ptr<Ranges>&... rs);
2018-08-07 21:49:21 +02:00
Space mSpace;
2019-03-29 12:58:39 +01:00
Op mMapf;
//Op mMapf;
2018-08-18 16:24:13 +02:00
std::shared_ptr<ORType> mOutRange;
Array<size_t,ORType> mMapMult;
2019-03-29 16:36:15 +01:00
vector<size_t> mMapPos;
private:
2019-03-29 12:58:39 +01:00
template <class MA>
void mkOutRange(const MA& mapf);
2018-08-07 21:49:21 +02:00
public:
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 ) )&;
2019-04-03 16:26:53 +02:00
std::shared_ptr<ORType> outRange() const;
2019-03-29 12:58:39 +01:00
const Op& 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;
virtual vector<size_t> typeNum() const final;
2019-03-14 14:20:38 +01:00
virtual size_t cmeta(char* target, size_t pos) const final;
virtual size_t cmetaSize() 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;
const Array<size_t,ORType>& mapMultiplicity() const;
2019-04-03 16:26:53 +02:00
ConstSlice<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;
/*
2018-08-07 21:49:21 +02:00
template <class... ERanges>
auto cat(const std::shared_ptr<GenMapRange<ERanges...> >& erange)
-> std::shared_ptr<GenMapRange<Ranges...,ERanges...> >;
*/
friend GenMapRangeFactory<ORType,Op,XSTYPE,Ranges...>;
2018-08-07 21:49:21 +02:00
static constexpr bool HASMETACONT = false;
static constexpr bool defaultable = false;
2021-05-27 23:29:04 +02:00
static constexpr size_t ISSTATIC = Op::ISSTATIC & (... & Ranges::ISSTATIC);
static constexpr size_t SIZE = Op::SIZE * (... * Ranges::SIZE);
2018-08-07 21:49:21 +02:00
};
// for legacy
template <class OIType, class Op, class... Indices>
using MapIndex = GenMapIndex<OIType,Op,SpaceType::ANY,Indices...>;
template <class ORType, class Op, class... Ranges>
using MapRangeFactory = GenMapRangeFactory<ORType,Op,SpaceType::ANY,Ranges...>;
template <class ORType, class Op, class... Ranges>
using MapRange = GenMapRange<ORType,Op,SpaceType::ANY,Ranges...>;
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();
}
2018-08-07 21:49:21 +02:00
}
#endif