2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
#ifndef __dynamic_range_h__
|
|
|
|
#define __dynamic_range_h__
|
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
#include <cassert>
|
2020-08-27 12:00:47 +02:00
|
|
|
#include <map>
|
2018-10-30 15:06:29 +01:00
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
#include "ranges/rbase_def.h"
|
|
|
|
#include "ranges/range_base.h"
|
|
|
|
#include "ranges/index_base.h"
|
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
#include "xfor/xfor.h"
|
2018-10-22 14:27:55 +02:00
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
//#include "ranges/rpheader.h"
|
2018-10-29 14:19:42 +01:00
|
|
|
#include "ranges/x_to_string.h"
|
|
|
|
#include "ranges/type_map.h"
|
|
|
|
#include "ranges/dynamic_meta.h"
|
2018-10-22 14:27:55 +02:00
|
|
|
|
2020-08-27 12:00:47 +02:00
|
|
|
#include "index_wrapper.h"
|
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2018-11-01 22:11:08 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace MultiArrayHelper;
|
|
|
|
}
|
|
|
|
//using MultiArrayHelper::DynamicExpression;
|
2018-10-23 20:02:01 +02:00
|
|
|
|
2018-11-01 22:11:08 +01:00
|
|
|
//using MultiArrayHelper::ExpressionHolder;
|
2020-07-08 17:55:51 +02:00
|
|
|
/*
|
2018-11-06 16:35:37 +01:00
|
|
|
class AbstractIW
|
2018-10-22 14:27:55 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-11-06 16:35:37 +01:00
|
|
|
AbstractIW() = default;
|
|
|
|
AbstractIW(const AbstractIW& in) = default;
|
|
|
|
AbstractIW(AbstractIW&& in) = default;
|
|
|
|
AbstractIW& operator=(const AbstractIW& in) = default;
|
|
|
|
AbstractIW& operator=(AbstractIW&& in) = default;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
};
|
|
|
|
*/
|
2018-10-23 20:02:01 +02:00
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
//typedef SingleRange<size_t,SpaceType::DYN> DynamicRange;
|
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
class DynamicIndex : public IndexInterface<DynamicIndex,vector<char>>
|
2018-10-22 14:27:55 +02:00
|
|
|
{
|
|
|
|
private:
|
2020-07-08 17:55:51 +02:00
|
|
|
typedef vector<std::pair<std::shared_ptr<IndexW>,size_t>> IVecT;
|
2020-08-26 23:24:10 +02:00
|
|
|
typedef std::map<std::string,std::shared_ptr<IndexW>> IMapT;
|
|
|
|
|
|
|
|
static IMapT sIMap;
|
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
IVecT mIVec;
|
2019-03-19 20:58:59 +01:00
|
|
|
bool mIvecInit = false;
|
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
public:
|
2020-07-08 17:55:51 +02:00
|
|
|
typedef IndexInterface<DynamicIndex,vector<char>> IB;
|
2019-03-14 19:10:06 +01:00
|
|
|
typedef vector<char> MetaType;
|
2020-07-08 17:55:51 +02:00
|
|
|
typedef DynamicRange RangeType;
|
2018-10-22 14:27:55 +02:00
|
|
|
typedef DynamicIndex IType;
|
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
DynamicIndex(const std::shared_ptr<RangeType>& range);
|
2018-10-22 14:27:55 +02:00
|
|
|
|
2020-08-26 23:24:10 +02:00
|
|
|
static void clearIMap() { sIMap.clear(); }
|
2018-10-22 14:27:55 +02:00
|
|
|
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
|
|
|
static constexpr size_t totalDim() { return 1; }
|
|
|
|
static constexpr size_t sDim() { return 1; }
|
|
|
|
|
|
|
|
static constexpr SpaceType STYPE = SpaceType::DYN;
|
|
|
|
|
|
|
|
IndexType type() const;
|
|
|
|
|
|
|
|
DynamicIndex& operator=(size_t pos);
|
|
|
|
DynamicIndex& operator++();
|
|
|
|
DynamicIndex& operator--();
|
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
DynamicIndex& operator()(const IVecT& ivec);
|
2020-07-08 17:55:51 +02:00
|
|
|
DynamicIndex& operator()(const vector<std::shared_ptr<IndexW>>& ivec);
|
2020-08-26 23:24:10 +02:00
|
|
|
DynamicIndex& operator()(const vector<std::string>& inames);
|
2018-12-02 22:08:51 +01:00
|
|
|
|
2018-11-01 22:11:08 +01:00
|
|
|
template <class... Indices>
|
|
|
|
DynamicIndex& operator()(const std::shared_ptr<Indices>&... is);
|
2018-12-02 22:08:51 +01:00
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
DynamicIndex& sync();
|
2018-12-02 22:08:51 +01:00
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
int pp(std::intptr_t idxPtrNum);
|
|
|
|
int mm(std::intptr_t idxPtrNum);
|
|
|
|
|
|
|
|
std::string stringMeta() const;
|
|
|
|
MetaType meta() const;
|
|
|
|
const MetaType* metaPtr() const;
|
|
|
|
DynamicIndex& at(const MetaType& metaPos);
|
|
|
|
size_t posAt(const MetaType& metaPos) const;
|
|
|
|
|
|
|
|
//bool isMeta(const MetaType& metaPos) const;
|
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
size_t dim() const;
|
|
|
|
bool last() const;
|
|
|
|
bool first() const;
|
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
const IndexW& get(size_t n) const;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
std::shared_ptr<RangeType> range();
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
void getPtr();
|
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
size_t getStepSize(size_t n) const;
|
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
std::string id() const;
|
|
|
|
void print(size_t offset);
|
|
|
|
|
|
|
|
template <class Expr>
|
2020-07-09 17:37:28 +02:00
|
|
|
DynamicExpression ifor(size_t step, Expr ex) const;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
template <class Expr>
|
2020-07-09 17:37:28 +02:00
|
|
|
DynamicExpression iforh(size_t step, Expr ex) const;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
2019-01-15 17:41:43 +01:00
|
|
|
template <class Expr>
|
2020-07-09 17:37:28 +02:00
|
|
|
DynamicExpression pifor(size_t step, Expr ex) const;
|
2019-01-15 17:41:43 +01:00
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
};
|
|
|
|
|
2018-10-27 14:58:34 +02:00
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
// NOT THREAD SAVE!!
|
|
|
|
class DynamicRangeFactory : public RangeFactoryBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
typedef DynamicRange oType;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
DynamicRangeFactory();
|
|
|
|
|
|
|
|
template <class... RangeTypes>
|
|
|
|
DynamicRangeFactory(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
|
|
|
|
|
|
|
|
template <class... RangeTypes>
|
|
|
|
DynamicRangeFactory(std::shared_ptr<RangeTypes>... origs);
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
DynamicRangeFactory(const vector<std::shared_ptr<RangeBase>>& origs);
|
2018-11-02 18:58:58 +01:00
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
template <class Range>
|
|
|
|
void append(std::shared_ptr<Range> r);
|
2020-08-27 03:23:03 +02:00
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
void appendx(std::shared_ptr<Range> r);
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
std::shared_ptr<RangeBase> create();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
std::shared_ptr<RangeBase> checkIfCreated(const vector<std::shared_ptr<RangeBase> >& pvec);
|
2018-10-22 14:27:55 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
static std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > mAleadyCreated;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
bool mProductCreated = false;
|
|
|
|
};
|
2018-10-27 14:58:34 +02:00
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
class DynamicRange : public RangeInterface<DynamicIndex>
|
2018-10-22 14:27:55 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr bool defaultable = true;
|
|
|
|
static constexpr size_t ISSTATIC = 0;
|
|
|
|
static constexpr size_t SIZE = -1;
|
|
|
|
static constexpr bool HASMETACONT = false;
|
|
|
|
|
2020-08-27 03:23:03 +02:00
|
|
|
typedef vector<std::shared_ptr<IndexW>> IVecT;
|
2018-10-22 14:27:55 +02:00
|
|
|
typedef RangeBase RB;
|
2020-07-08 17:55:51 +02:00
|
|
|
typedef DynamicIndex IndexType;
|
2018-10-22 14:27:55 +02:00
|
|
|
typedef DynamicRange RangeType;
|
2019-03-14 19:10:06 +01:00
|
|
|
typedef vector<char> MetaType;
|
2020-07-08 17:55:51 +02:00
|
|
|
typedef DynamicRangeFactory FType;
|
2019-03-14 19:10:06 +01:00
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
private:
|
2018-10-30 15:06:29 +01:00
|
|
|
DynamicRange() = default;
|
|
|
|
DynamicRange(const DynamicRange& in) = default;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
template <class... RangeTypes>
|
2018-10-30 15:06:29 +01:00
|
|
|
DynamicRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
template <class... RangeTypes>
|
2018-10-30 15:06:29 +01:00
|
|
|
DynamicRange(std::shared_ptr<RangeTypes>... origs);
|
2018-10-22 14:27:55 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
DynamicRange(const vector<std::shared_ptr<RangeBase>>& origs);
|
2018-11-02 18:58:58 +01:00
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
size_t mSize = 1;
|
|
|
|
bool mEmpty = true;
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<std::shared_ptr<RangeBase> > mOrig;
|
2020-08-27 03:23:03 +02:00
|
|
|
IVecT mProtoI;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual size_t size() const final;
|
|
|
|
virtual size_t dim() const final;
|
|
|
|
|
|
|
|
MetaType get(size_t pos) const;
|
|
|
|
size_t getMeta(const MetaType& metaPos) const;
|
|
|
|
|
|
|
|
virtual IndexType begin() const final;
|
|
|
|
virtual IndexType end() const final;
|
|
|
|
|
|
|
|
virtual SpaceType spaceType() const final;
|
2018-11-07 10:58:07 +01:00
|
|
|
virtual DataHeader dataHeader() const final;
|
|
|
|
|
2019-03-19 20:58:59 +01:00
|
|
|
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;
|
2019-03-19 20:58:59 +01:00
|
|
|
virtual size_t cmetaSize() const final;
|
2018-10-22 14:27:55 +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-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
std::shared_ptr<RangeBase> sub(size_t num) const;
|
2020-08-27 03:23:03 +02:00
|
|
|
std::shared_ptr<IndexW> subI(size_t num) const;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
template <class Range>
|
|
|
|
std::shared_ptr<Range> fullsub(size_t num) const;
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<std::shared_ptr<RangeBase> >& orig() const;
|
2018-11-02 18:58:58 +01:00
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
void sreplace(const std::shared_ptr<RangeBase> in, size_t num);
|
|
|
|
|
|
|
|
bool isEmpty() const;
|
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
friend DynamicRangeFactory;
|
2018-10-22 14:27:55 +02:00
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
static DynamicRangeFactory factory()
|
|
|
|
{ return DynamicRangeFactory(); }
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace MultiArrayTools
|
|
|
|
|
|
|
|
|
|
|
|
namespace MultiArrayHelper
|
|
|
|
{
|
|
|
|
using namespace MultiArrayTools;
|
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
inline void resolveSetRange(std::shared_ptr<DynamicRange>& rp,
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<std::shared_ptr<RangeBase> >& orig,
|
2018-10-30 15:06:29 +01:00
|
|
|
size_t origpos, size_t size)
|
2018-10-22 14:27:55 +02:00
|
|
|
{
|
2020-07-08 17:55:51 +02:00
|
|
|
DynamicRangeFactory arf;
|
2018-10-22 14:27:55 +02:00
|
|
|
for(size_t op = origpos; op != origpos + size; ++op){
|
|
|
|
//VCHECK(op);
|
2020-08-27 03:23:03 +02:00
|
|
|
arf.appendx(orig[op]);
|
2018-10-22 14:27:55 +02:00
|
|
|
}
|
2020-07-08 17:55:51 +02:00
|
|
|
rp = std::dynamic_pointer_cast<DynamicRange>( arf.create() );
|
2018-10-22 14:27:55 +02:00
|
|
|
}
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
|
2020-07-08 17:55:51 +02:00
|
|
|
std::shared_ptr<DynamicRange> r)
|
2018-10-22 14:27:55 +02:00
|
|
|
{
|
|
|
|
if(not r->isEmpty()){
|
2018-10-27 14:58:34 +02:00
|
|
|
for(size_t i = r->dim(); i != 0; --i){
|
2018-10-22 14:27:55 +02:00
|
|
|
v.insert(v.begin(), r->sub(i-1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 17:55:51 +02:00
|
|
|
inline size_t getStepSize(const DynamicIndex& ii, std::intptr_t j)
|
2018-10-29 14:19:42 +01:00
|
|
|
{
|
|
|
|
size_t ss = 0;
|
|
|
|
size_t sx = 1;
|
2018-11-01 22:11:08 +01:00
|
|
|
for(size_t k = ii.dim(); k != 0; --k){
|
|
|
|
const size_t i = k-1;
|
2018-10-29 14:19:42 +01:00
|
|
|
const auto& ni = ii.get(i);
|
|
|
|
const size_t max = ni.max();
|
|
|
|
const size_t tmp = ni.getStepSizeComp(j);
|
|
|
|
ss += tmp * ii.getStepSize(i);
|
|
|
|
sx *= max;
|
|
|
|
}
|
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:27:55 +02:00
|
|
|
}
|
|
|
|
|
2018-11-01 22:11:08 +01:00
|
|
|
//#include "dynamic_range.cc.h"
|
2018-10-22 14:27:55 +02:00
|
|
|
|
|
|
|
#endif
|