2017-02-16 11:20:40 +01:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
#ifndef __cxz_multi_range_h__
|
|
|
|
#define __cxz_multi_range_h__
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
#include "base/base.h"
|
2018-07-16 17:40:39 +02:00
|
|
|
#include <map>
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
#include "range_base.h"
|
|
|
|
#include "index_base.h"
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
#include "range_helper.h"
|
|
|
|
#include "multi_range_factory_product_map.h"
|
2017-11-20 21:35:25 +01:00
|
|
|
|
2021-05-05 20:04:13 +02:00
|
|
|
#include "statics/static_for.h"
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
template <class... Indices>
|
2017-12-11 18:49:43 +01:00
|
|
|
class MultiIndex : public IndexInterface<MultiIndex<Indices...>,
|
2022-09-11 02:48:30 +02:00
|
|
|
Tuple<typename Indices::MetaType...> >
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
2017-02-20 17:18:53 +01:00
|
|
|
public:
|
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
typedef IndexInterface<MultiIndex<Indices...>,
|
2022-09-11 02:48:30 +02:00
|
|
|
Tuple<typename Indices::MetaType...> > IB;
|
|
|
|
typedef Tuple<Sptr<Indices>...> IndexPack;
|
|
|
|
typedef Tuple<typename Indices::MetaType...> MetaType;
|
2017-08-11 15:26:10 +02:00
|
|
|
typedef MultiRange<typename Indices::RangeType...> RangeType;
|
2018-03-05 00:04:50 +01:00
|
|
|
typedef MultiIndex IType;
|
2018-01-05 13:56:16 +01:00
|
|
|
|
2018-03-02 16:37:11 +01:00
|
|
|
static constexpr IndexType sType() { return IndexType::MULTI; }
|
2022-09-11 02:48:30 +02:00
|
|
|
static constexpr SizeT sDim() { return sizeof...(Indices); }
|
|
|
|
static constexpr SizeT totalDim() { return (... * Indices::totalDim()); }
|
2018-07-28 15:27:11 +02:00
|
|
|
|
|
|
|
static constexpr SpaceType STYPE = SpaceType::ANY;
|
2022-09-11 02:48:30 +02:00
|
|
|
static constexpr bool PARALLEL = TupleElem<0,Tuple<Indices...>>::type::PARALLEL;
|
2019-01-15 17:41:43 +01:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
private:
|
|
|
|
|
2017-08-04 11:27:47 +02:00
|
|
|
IndexPack mIPack;
|
2022-09-11 02:48:30 +02:00
|
|
|
Arr<SizeT,sizeof...(Indices)+1> mBlockSizes;
|
|
|
|
MultiIndex() = default;
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
public:
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2018-01-05 13:56:16 +01:00
|
|
|
const IndexPack& pack() const { return mIPack; }
|
|
|
|
|
2017-02-28 19:29:52 +01:00
|
|
|
// NO DEFAULT HERE !!!
|
2017-07-26 16:45:09 +02:00
|
|
|
// ( have to assign sub-indices (ptr!) correctly )
|
2017-05-24 19:01:02 +02:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
template <class MRange>
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiIndex(const Sptr<MRange>& range);
|
2017-08-28 18:28:43 +02:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT DIR>
|
2017-07-26 16:45:09 +02:00
|
|
|
MultiIndex& up();
|
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT DIR>
|
2017-07-26 16:45:09 +02:00
|
|
|
MultiIndex& down();
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-08-04 11:27:47 +02:00
|
|
|
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
2017-08-07 17:11:03 +02:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-12-12 11:15:39 +01:00
|
|
|
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
|
2018-09-16 18:53:28 +02:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
|
|
|
SizeT getBlockSize() const { return std::get<N>(mBlockSizes); }
|
2017-12-12 11:15:39 +01:00
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
// raplace instances (in contrast to its analogon in ConstContainerIndex
|
2017-12-11 18:49:43 +01:00
|
|
|
// MultiIndices CANNOT be influences be its subindices, so there is
|
|
|
|
// NO foreign/external controll)
|
|
|
|
// Do NOT share index instances between two or more MultiIndex instances
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiIndex& operator()(Sptr<Indices>&... indices);
|
|
|
|
MultiIndex& operator()(const Tuple<Sptr<Indices>...>& indices);
|
2017-12-12 16:16:09 +01:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
2017-07-25 17:46:59 +02:00
|
|
|
|
2017-12-26 15:13:50 +01:00
|
|
|
IndexType type() const;
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiIndex& operator=(SizeT pos);
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
MultiIndex& operator++();
|
|
|
|
MultiIndex& operator--();
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
int pp(PtrId idxPtrNum);
|
|
|
|
int mm(PtrId idxPtrNum);
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2018-07-22 16:16:24 +02:00
|
|
|
std::string stringMeta() const;
|
|
|
|
MetaType meta() const;
|
2017-12-17 14:23:23 +01:00
|
|
|
MultiIndex& at(const MetaType& metaPos);
|
2017-02-20 17:18:53 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT dim();
|
2017-12-17 14:23:23 +01:00
|
|
|
bool first();
|
|
|
|
bool last();
|
2022-09-11 02:48:30 +02:00
|
|
|
Sptr<RangeType> range();
|
2017-12-12 11:15:39 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-12-17 14:23:23 +01:00
|
|
|
auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
|
2018-02-15 16:24:54 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT getStepSize(SizeT n);
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Exprs>
|
2022-09-11 02:48:30 +02:00
|
|
|
auto ifor(SizeT step, Exprs exs) const;
|
2018-01-15 14:56:22 +01:00
|
|
|
|
|
|
|
template <class Exprs>
|
2022-09-11 02:48:30 +02:00
|
|
|
auto iforh(SizeT step, Exprs exs) const;
|
2018-01-15 14:56:22 +01:00
|
|
|
|
2019-01-15 17:41:43 +01:00
|
|
|
template <class Exprs>
|
2022-09-11 02:48:30 +02:00
|
|
|
auto pifor(SizeT step, Exprs exs) const;
|
2019-01-15 17:41:43 +01:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
/*************************
|
|
|
|
* MultiRangeFactory *
|
|
|
|
*************************/
|
|
|
|
|
2018-07-16 17:40:39 +02:00
|
|
|
// NOT THREAD SAVE
|
2017-07-26 18:38:11 +02:00
|
|
|
template <class... Ranges>
|
2017-07-27 14:48:41 +02:00
|
|
|
class MultiRangeFactory : public RangeFactoryBase
|
2017-07-26 18:38:11 +02:00
|
|
|
{
|
|
|
|
public:
|
2017-07-28 11:33:31 +02:00
|
|
|
typedef MultiRange<Ranges...> oType;
|
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
MultiRangeFactory() = delete;
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiRangeFactory(const Sptr<Ranges>&... rs);
|
2018-07-21 18:05:53 +02:00
|
|
|
MultiRangeFactory(const typename MultiRange<Ranges...>::Space& space);
|
2018-02-15 20:06:14 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
virtual Sptr<RangeBase> create() override;
|
2018-07-16 17:40:39 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
Sptr<RangeBase> checkIfCreated(const Tuple<Sptr<Ranges>...>& ptp);
|
2018-07-16 17:40:39 +02:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
};
|
2017-02-21 17:41:48 +01:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
/******************
|
|
|
|
* MultiRange *
|
|
|
|
******************/
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
template <class... Ranges>
|
2017-07-25 17:46:59 +02:00
|
|
|
class MultiRange : public RangeInterface<MultiIndex<typename Ranges::IndexType...> >
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-08-04 11:27:47 +02:00
|
|
|
typedef RangeBase RB;
|
2022-09-11 02:48:30 +02:00
|
|
|
typedef Tuple<Sptr<Ranges>...> Space;
|
2018-03-05 00:04:50 +01:00
|
|
|
typedef MultiIndex<typename Ranges::IndexType...> IndexType;
|
2022-09-11 02:48:30 +02:00
|
|
|
typedef Tuple<typename Ranges::IndexType::MetaType...> MetaType;
|
2018-03-05 00:04:50 +01:00
|
|
|
typedef MultiRange RangeType;
|
2018-10-08 22:06:57 +02:00
|
|
|
typedef MultiRangeFactory<Ranges...> FType;
|
2017-02-20 17:18:53 +01:00
|
|
|
|
2017-08-04 11:27:47 +02:00
|
|
|
protected:
|
|
|
|
MultiRange() = delete;
|
|
|
|
MultiRange(const MultiRange& in) = delete;
|
|
|
|
MultiRange& operator=(const MultiRange& in) = delete;
|
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiRange(const Sptr<Ranges>&... rs);
|
2018-07-21 18:05:53 +02:00
|
|
|
MultiRange(const Space& space);
|
2017-08-04 11:27:47 +02:00
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
Space mSpace;
|
2017-12-15 14:47:02 +01:00
|
|
|
|
2017-08-04 11:27:47 +02:00
|
|
|
public:
|
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
static const SizeT sdim = sizeof...(Ranges);
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-08-04 11:27:47 +02:00
|
|
|
auto get() const -> decltype( *std::get<N>( mSpace ) )&;
|
2017-08-04 14:57:19 +02:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT getMeta(const MetaType& metaPos) const;
|
2021-01-11 11:16:29 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-08-04 14:57:19 +02:00
|
|
|
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
2017-07-25 17:46:59 +02:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
virtual Sptr<RangeBase> sub(SizeT num) const override;
|
2018-11-30 00:16:28 +01:00
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
virtual SizeT dim() const final;
|
|
|
|
virtual SizeT size() const final;
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2018-07-28 15:27:11 +02:00
|
|
|
virtual SpaceType spaceType() const final;
|
2018-11-07 10:58:07 +01:00
|
|
|
virtual DataHeader dataHeader() const final;
|
|
|
|
|
2022-09-11 02:48:30 +02:00
|
|
|
virtual Vector<SizeT> typeNum() const final;
|
|
|
|
virtual SizeT cmeta(char* target, SizeT pos) const final;
|
|
|
|
virtual SizeT cmetaSize() const final;
|
|
|
|
virtual std::string stringMeta(SizeT pos) const final;
|
|
|
|
virtual Vector<char> data() const final;
|
2017-02-28 19:29:52 +01:00
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
const Space& space() const;
|
2017-02-17 18:10:03 +01:00
|
|
|
|
2018-03-05 18:46:29 +01:00
|
|
|
virtual IndexType begin() const final;
|
|
|
|
virtual IndexType end() const final;
|
2017-05-24 19:01:02 +02:00
|
|
|
|
2018-05-20 20:03:44 +02:00
|
|
|
template <class... ERanges>
|
2022-09-11 02:48:30 +02:00
|
|
|
auto cat(const Sptr<MultiRange<ERanges...> >& erange)
|
|
|
|
-> Sptr<MultiRange<Ranges...,ERanges...> >;
|
2018-05-20 20:03:44 +02:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
friend MultiRangeFactory<Ranges...>;
|
2017-12-15 14:47:02 +01:00
|
|
|
|
2018-08-06 12:46:12 +02:00
|
|
|
static constexpr bool HASMETACONT = false;
|
2018-02-13 16:54:13 +01:00
|
|
|
static constexpr bool defaultable = false;
|
2022-09-11 02:48:30 +02:00
|
|
|
static constexpr SizeT ISSTATIC = (... & Ranges::ISSTATIC);
|
|
|
|
static constexpr SizeT SIZE = (... * Ranges::SIZE);
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2021-07-28 20:29:56 +02:00
|
|
|
using namespace CNORXZInternal;
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
2018-07-28 15:27:11 +02:00
|
|
|
// -> define in range_base.cc
|
2022-09-11 02:48:30 +02:00
|
|
|
Sptr<RangeFactoryBase> mkMULTI(const char** dp);
|
2018-07-28 15:27:11 +02:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/******************
|
|
|
|
* MultiIndex *
|
|
|
|
******************/
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
template <class MRange>
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiIndex<Indices...>::MultiIndex(const Sptr<MRange>& range) :
|
|
|
|
IndexInterface<MultiIndex<Indices...>,Tuple<typename Indices::MetaType...> >(range, 0)
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
2021-05-06 19:04:26 +02:00
|
|
|
sfor_mn<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) {
|
2021-05-05 20:04:13 +02:00
|
|
|
auto r = range->template getPtr<i>();
|
|
|
|
std::get<i>(mIPack) = r->beginPtr();
|
|
|
|
*std::get<i>(mIPack) = 0;
|
|
|
|
|
2021-05-06 19:04:26 +02:00
|
|
|
std::get<i>(mBlockSizes) = sfor_p<i,sizeof...(Indices)>
|
|
|
|
( [&](auto j) { return std::get<j>(mIPack)->max(); } ,
|
|
|
|
[&](auto a, auto b) { return a * b; });
|
2021-05-05 20:04:13 +02:00
|
|
|
return 0;
|
2021-05-06 19:04:26 +02:00
|
|
|
});
|
2021-05-05 20:04:13 +02:00
|
|
|
|
2021-05-07 17:35:59 +02:00
|
|
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
2021-05-06 19:04:26 +02:00
|
|
|
( [&](auto i) { return std::get<i>(mIPack); },
|
|
|
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT DIR>
|
2017-11-20 21:35:25 +01:00
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
|
|
|
{
|
|
|
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
2021-05-06 19:04:26 +02:00
|
|
|
IB::mPos += sfor_p<DIR,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
|
|
|
[&](auto a, auto b) { return a * b; } );
|
|
|
|
sfor_m<DIR+1,0>
|
|
|
|
( [&](auto i) {
|
|
|
|
auto& si = *std::get<i>( mIPack );
|
|
|
|
if(si.last() and i != 0) { si = 0; return true; }
|
|
|
|
else { ++si; return false; }
|
|
|
|
return false;
|
|
|
|
} );
|
2017-11-20 21:35:25 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT DIR>
|
2017-11-20 21:35:25 +01:00
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::down()
|
|
|
|
{
|
|
|
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
2021-05-06 19:04:26 +02:00
|
|
|
IB::mPos -= sfor_p<DIR,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
|
|
|
[&](auto a, auto b) { return a * b; } );
|
|
|
|
sfor_m<DIR+1,0>
|
|
|
|
( [&](auto i) {
|
|
|
|
auto& si = *std::get<i>( mIPack );
|
|
|
|
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
|
|
|
else { --si; return false; }
|
|
|
|
return false;
|
|
|
|
} );
|
2017-11-20 21:35:25 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-11-20 21:35:25 +01:00
|
|
|
auto MultiIndex<Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
|
|
|
|
{
|
|
|
|
return *std::get<N>(mIPack);
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:15:39 +01:00
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-12-12 11:15:39 +01:00
|
|
|
auto MultiIndex<Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
|
|
|
|
{
|
|
|
|
return std::get<N>(mIPack);
|
|
|
|
}
|
2018-11-30 00:16:28 +01:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(Sptr<Indices>&... indices)
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2021-05-07 17:35:59 +02:00
|
|
|
return (*this)(std::make_tuple(indices...));
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-12-17 14:23:23 +01:00
|
|
|
|
2020-08-29 23:36:01 +02:00
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(const Tuple<Sptr<Indices>...>& indices)
|
2020-08-29 23:36:01 +02:00
|
|
|
{
|
2021-05-07 17:35:59 +02:00
|
|
|
sfor_pn<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(indices); return 0; } );
|
2021-05-12 17:56:35 +02:00
|
|
|
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, IB::mPos);
|
2020-08-29 23:36:01 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <class... Indices>
|
2017-12-26 15:13:50 +01:00
|
|
|
IndexType MultiIndex<Indices...>::type() const
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return IndexType::MULTI;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(SizeT pos)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
2021-05-12 17:56:35 +02:00
|
|
|
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, pos);
|
2017-12-17 14:23:23 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
|
|
|
|
{
|
2021-05-06 19:04:26 +02:00
|
|
|
sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) {
|
|
|
|
auto& si = *std::get<i>( mIPack );
|
|
|
|
if(si.last() and i != 0) { si = 0; return true; }
|
|
|
|
else { ++si; return false; }
|
|
|
|
return false;
|
|
|
|
} );
|
2017-12-17 14:23:23 +01:00
|
|
|
++IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
|
|
|
|
{
|
2021-05-06 19:04:26 +02:00
|
|
|
sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) {
|
|
|
|
auto& si = *std::get<i>( mIPack );
|
|
|
|
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
|
|
|
else { --si; return false; }
|
|
|
|
return false;
|
|
|
|
} );
|
2017-12-17 14:23:23 +01:00
|
|
|
--IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-05-06 19:04:26 +02:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
int MultiIndex<Indices...>::pp(PtrId idxPtrNum)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
2021-05-27 23:29:04 +02:00
|
|
|
const int tmp = RangeHelper::ppx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
2017-12-17 14:23:23 +01:00
|
|
|
IB::mPos += tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
int MultiIndex<Indices...>::mm(PtrId idxPtrNum)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
2021-05-27 23:29:04 +02:00
|
|
|
const int tmp = RangeHelper::mmx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
2017-12-17 14:23:23 +01:00
|
|
|
IB::mPos -= tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2018-07-22 16:16:24 +02:00
|
|
|
std::string MultiIndex<Indices...>::stringMeta() const
|
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
MetaType metaTuple;
|
2021-05-07 17:35:59 +02:00
|
|
|
sfor_pn<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { std::get<i>(metaTuple) = std::get<i>(mIPack)->meta(); return 0; } );
|
2017-12-17 14:23:23 +01:00
|
|
|
return metaTuple;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos)
|
|
|
|
{
|
2021-05-07 17:35:59 +02:00
|
|
|
sfor_pn<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { std::get<i>(mIPack)->at( std::get<i>(metaPos) ); return 0; } );
|
2021-05-06 19:04:26 +02:00
|
|
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) { return std::get<i>(mIPack); },
|
|
|
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
2017-12-17 14:23:23 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT MultiIndex<Indices...>::dim()
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return sizeof...(Indices);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
bool MultiIndex<Indices...>::first()
|
|
|
|
{
|
|
|
|
return IB::mPos == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
bool MultiIndex<Indices...>::last()
|
|
|
|
{
|
|
|
|
return IB::mPos == IB::mMax - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
Sptr<typename MultiIndex<Indices...>::RangeType>
|
2017-12-17 14:23:23 +01:00
|
|
|
MultiIndex<Indices...>::range()
|
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-12-17 14:23:23 +01:00
|
|
|
auto MultiIndex<Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
|
|
|
|
{
|
|
|
|
return std::get<N>(mIPack);
|
|
|
|
}
|
2018-02-15 16:24:54 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT MultiIndex<Indices...>::getStepSize(SizeT n)
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
if(n >= sizeof...(Indices)){
|
|
|
|
assert(0);
|
|
|
|
// throw !!
|
|
|
|
}
|
|
|
|
return mBlockSizes[n+1];
|
|
|
|
}
|
|
|
|
|
2018-01-07 22:33:34 +01:00
|
|
|
template <class... Indices>
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Exprs>
|
2022-09-11 02:48:30 +02:00
|
|
|
auto MultiIndex<Indices...>::ifor(SizeT step, Exprs exs) const
|
2018-01-07 22:33:34 +01:00
|
|
|
{
|
2021-05-27 12:15:44 +02:00
|
|
|
return RangeHelper::mkFor<0>(step, mIPack, mBlockSizes, exs);
|
2018-01-07 22:33:34 +01:00
|
|
|
}
|
2018-01-15 14:56:22 +01:00
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
template <class Exprs>
|
2022-09-11 02:48:30 +02:00
|
|
|
auto MultiIndex<Indices...>::iforh(SizeT step, Exprs exs) const
|
2018-01-15 14:56:22 +01:00
|
|
|
{
|
2021-05-27 12:15:44 +02:00
|
|
|
return RangeHelper::mkForh<0>(step, mIPack, mBlockSizes, exs);
|
2018-01-15 14:56:22 +01:00
|
|
|
}
|
|
|
|
|
2019-01-15 17:41:43 +01:00
|
|
|
template <class... Indices>
|
|
|
|
template <class Exprs>
|
2022-09-11 02:48:30 +02:00
|
|
|
auto MultiIndex<Indices...>::pifor(SizeT step, Exprs exs) const
|
2019-01-15 17:41:43 +01:00
|
|
|
{
|
2021-05-27 12:15:44 +02:00
|
|
|
return RangeHelper::mkPFor<0>(step, mIPack, mBlockSizes, exs);
|
2019-01-15 17:41:43 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/*************************
|
|
|
|
* MultiRangeFactory *
|
|
|
|
*************************/
|
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiRangeFactory<Ranges...>::MultiRangeFactory(const Sptr<Ranges>&... rs)
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2022-09-11 02:48:30 +02:00
|
|
|
mProd = Sptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( rs... ) );
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
2018-07-21 18:05:53 +02:00
|
|
|
MultiRangeFactory<Ranges...>::MultiRangeFactory(const typename MultiRange<Ranges...>::Space& st)
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2022-09-11 02:48:30 +02:00
|
|
|
mProd = Sptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
Sptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2018-07-16 17:40:39 +02:00
|
|
|
mProd = checkIfCreated( std::dynamic_pointer_cast<oType>( mProd )->mSpace );
|
2017-11-20 21:35:25 +01:00
|
|
|
setSelf();
|
|
|
|
return mProd;
|
|
|
|
}
|
2018-07-16 17:40:39 +02:00
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
Sptr<RangeBase> MultiRangeFactory<Ranges...>::checkIfCreated(const Tuple<Sptr<Ranges>...>& ptp)
|
2018-07-16 17:40:39 +02:00
|
|
|
{
|
2022-09-11 02:48:30 +02:00
|
|
|
Sptr<RangeBase> out;
|
2018-07-16 17:40:39 +02:00
|
|
|
bool check = false;
|
|
|
|
for(auto& x: MultiRangeFactoryProductMap::mAleadyCreated){
|
|
|
|
if(x.second.size() == sizeof...(Ranges)){
|
2021-05-27 18:37:15 +02:00
|
|
|
check = sfor_p<0,sizeof...(Ranges)>
|
2022-09-11 02:48:30 +02:00
|
|
|
( [&](auto i) { return reinterpret_cast<PtrId>( std::get<i>(ptp).get() ) == x.second[i]; },
|
2021-05-27 18:37:15 +02:00
|
|
|
[&](auto a, auto b) { return a and b; } );
|
2018-07-16 17:40:39 +02:00
|
|
|
if(check){
|
|
|
|
out = x.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(not check){
|
2022-09-11 02:48:30 +02:00
|
|
|
Vector<PtrId> pv(sizeof...(Ranges));
|
2021-05-27 18:37:15 +02:00
|
|
|
sfor_pn<0,sizeof...(Ranges)>
|
2022-09-11 02:48:30 +02:00
|
|
|
( [&](auto i) { pv[i] = reinterpret_cast<PtrId>( std::get<i>(ptp).get() ); return 0; } );
|
2018-07-16 17:40:39 +02:00
|
|
|
MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
|
|
|
out = mProd;
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
2017-11-20 21:35:25 +01:00
|
|
|
|
|
|
|
/******************
|
|
|
|
* MultiRange *
|
|
|
|
******************/
|
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
MultiRange<Ranges...>::MultiRange(const Sptr<Ranges>&... rs) : mSpace(std::make_tuple(rs...)) {}
|
2017-11-20 21:35:25 +01:00
|
|
|
|
|
|
|
template <class... Ranges>
|
2018-07-21 18:05:53 +02:00
|
|
|
MultiRange<Ranges...>::MultiRange(const Space& space) : mSpace( space ) {}
|
2017-11-20 21:35:25 +01:00
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-11-20 21:35:25 +01:00
|
|
|
auto MultiRange<Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
|
|
|
|
{
|
|
|
|
return *std::get<N>(mSpace);
|
|
|
|
}
|
|
|
|
|
2021-01-11 11:16:29 +01:00
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT MultiRange<Ranges...>::getMeta(const MetaType& metaPos) const
|
2021-01-11 11:16:29 +01:00
|
|
|
{
|
2021-05-27 11:02:36 +02:00
|
|
|
return RangeHelper::getMeta<sizeof...(Ranges)-1>(mSpace,metaPos);
|
2021-01-11 11:16:29 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
template <SizeT N>
|
2017-11-20 21:35:25 +01:00
|
|
|
auto MultiRange<Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
|
|
|
|
{
|
|
|
|
return std::get<N>(mSpace);
|
|
|
|
}
|
|
|
|
|
2018-11-30 00:16:28 +01:00
|
|
|
template <class... Indices>
|
2022-09-11 02:48:30 +02:00
|
|
|
Sptr<RangeBase> MultiRange<Indices...>::sub(SizeT num) const
|
2018-11-30 00:16:28 +01:00
|
|
|
{
|
2021-05-12 17:56:35 +02:00
|
|
|
assert(num < sizeof...(Indices));
|
|
|
|
return sforx_p<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { return std::dynamic_pointer_cast<RangeBase>(std::get<i>(mSpace)); },
|
|
|
|
[&](auto i) { return num != i;} );
|
2018-11-30 00:16:28 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT MultiRange<Ranges...>::dim() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
return sdim;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT MultiRange<Ranges...>::size() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2021-05-27 11:02:36 +02:00
|
|
|
return sfor_p<0,sizeof...(Ranges)>
|
|
|
|
( [&](auto i) { return std::get<i>(mSpace)->size(); },
|
|
|
|
[&](auto a, auto b) { return a * b; } );
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
2018-07-28 15:27:11 +02:00
|
|
|
template <class... Ranges>
|
|
|
|
SpaceType MultiRange<Ranges...>::spaceType() const
|
|
|
|
{
|
|
|
|
return SpaceType::ANY;
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
template <class... Ranges>
|
2018-07-21 18:05:53 +02:00
|
|
|
const typename MultiRange<Ranges...>::Space& MultiRange<Ranges...>::space() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
return mSpace;
|
|
|
|
}
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2019-03-14 14:20:38 +01:00
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
Vector<SizeT> MultiRange<Ranges...>::typeNum() const
|
2019-03-14 14:20:38 +01:00
|
|
|
{
|
2022-09-11 02:48:30 +02:00
|
|
|
Vector<SizeT> o;
|
2021-05-27 11:02:36 +02:00
|
|
|
RangeHelper::getTypeNum<sizeof...(Ranges)-1>(o,mSpace);
|
2019-03-19 20:58:59 +01:00
|
|
|
return o;
|
2019-03-14 14:20:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT MultiRange<Ranges...>::cmeta(char* target, SizeT pos) const
|
2019-03-14 14:20:38 +01:00
|
|
|
{
|
2022-09-11 02:48:30 +02:00
|
|
|
const SizeT off = cmetaSize();
|
2019-11-12 13:30:26 +01:00
|
|
|
MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
2021-05-27 23:29:04 +02:00
|
|
|
return RangeHelper::getCMeta<sizeof...(Ranges)-1>(xtarget,pos,mSpace,off);
|
2019-03-14 14:20:38 +01:00
|
|
|
}
|
2019-03-19 20:58:59 +01:00
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
SizeT MultiRange<Ranges...>::cmetaSize() const
|
2019-03-19 20:58:59 +01:00
|
|
|
{
|
2021-05-27 23:29:04 +02:00
|
|
|
return RangeHelper::getCMetaSize<0>(mSpace);
|
2019-03-19 20:58:59 +01:00
|
|
|
}
|
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
std::string MultiRange<Ranges...>::stringMeta(SizeT pos) const
|
2018-07-21 18:05:53 +02:00
|
|
|
{
|
|
|
|
auto i = begin();
|
|
|
|
i = pos;
|
2021-05-27 23:29:04 +02:00
|
|
|
return "[" + RangeHelper::getStringMeta<0>(i) + "]";
|
2018-07-21 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
2022-09-11 02:48:30 +02:00
|
|
|
Vector<char> MultiRange<Ranges...>::data() const
|
2018-07-21 18:05:53 +02:00
|
|
|
{
|
2018-11-07 10:58:07 +01:00
|
|
|
DataHeader h = dataHeader();
|
2022-09-11 02:48:30 +02:00
|
|
|
Vector<char> out;
|
2018-07-21 18:05:53 +02:00
|
|
|
//out.reserve(h.metaSize + sizeof(DataHeader));
|
|
|
|
char* hcp = reinterpret_cast<char*>(&h);
|
|
|
|
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
|
2021-05-27 18:37:15 +02:00
|
|
|
sfor_pn<0,sizeof...(Ranges)>
|
|
|
|
( [&](auto i) {
|
2022-09-11 02:48:30 +02:00
|
|
|
Vector<char> part = std::get<i>(mSpace)->data();
|
2021-05-27 18:37:15 +02:00
|
|
|
out.insert(out.end(), part.begin(), part.end());
|
|
|
|
return 0;
|
|
|
|
} );
|
2018-07-21 18:05:53 +02:00
|
|
|
return out;
|
|
|
|
}
|
2018-11-07 10:58:07 +01:00
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
DataHeader MultiRange<Ranges...>::dataHeader() const
|
|
|
|
{
|
|
|
|
DataHeader h;
|
|
|
|
h.spaceType = static_cast<int>( SpaceType::ANY );
|
|
|
|
h.metaSize = sizeof...(Ranges);
|
|
|
|
h.multiple = 1;
|
|
|
|
return h;
|
|
|
|
}
|
2017-11-20 21:35:25 +01:00
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::begin() const
|
|
|
|
{
|
|
|
|
MultiIndex<typename Ranges::IndexType...>
|
|
|
|
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
2022-09-11 02:48:30 +02:00
|
|
|
( Sptr<RangeBase>( RB::mThis ) ) );
|
2017-11-20 21:35:25 +01:00
|
|
|
i = 0;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::end() const
|
|
|
|
{
|
|
|
|
MultiIndex<typename Ranges::IndexType...>
|
|
|
|
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
2022-09-11 02:48:30 +02:00
|
|
|
( Sptr<RangeBase>( RB::mThis )) );
|
2017-11-20 21:35:25 +01:00
|
|
|
i = size();
|
|
|
|
return i;
|
|
|
|
}
|
2018-05-20 20:03:44 +02:00
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
template <class... ERanges>
|
2022-09-11 02:48:30 +02:00
|
|
|
auto MultiRange<Ranges...>::cat(const Sptr<MultiRange<ERanges...> >& erange)
|
|
|
|
-> Sptr<MultiRange<Ranges...,ERanges...> >
|
2018-05-20 20:03:44 +02:00
|
|
|
{
|
|
|
|
auto crange = std::tuple_cat(mSpace, erange->space());
|
|
|
|
MultiRangeFactory<Ranges...,ERanges...> rf(crange);
|
|
|
|
return std::dynamic_pointer_cast<MultiRange<Ranges...,ERanges...> >(rf.create());
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
#endif
|