2017-02-16 11:20:40 +01:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
|
|
|
#ifndef __multi_range_h__
|
|
|
|
#define __multi_range_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <tuple>
|
2017-05-22 13:39:37 +02:00
|
|
|
#include <memory>
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
//#include "base_def.h"
|
|
|
|
#include "ranges/range_base.h"
|
|
|
|
#include "ranges/index_base.h"
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
#include "rpack_num.h"
|
2017-11-20 21:35:25 +01:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2017-12-11 18:49:43 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace MultiArrayHelper;
|
|
|
|
}
|
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...>,
|
|
|
|
std::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...>,
|
|
|
|
std::tuple<typename Indices::MetaType...> > IB;
|
2017-07-25 17:46:59 +02:00
|
|
|
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
2017-08-11 15:26:10 +02:00
|
|
|
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
|
|
|
typedef MultiRange<typename Indices::RangeType...> RangeType;
|
2018-01-05 13:56:16 +01:00
|
|
|
|
|
|
|
static IndexType sType() { return IndexType::MULTI; }
|
|
|
|
static size_t sDim() { return sizeof...(Indices); }
|
2018-01-09 22:38:46 +01:00
|
|
|
static size_t totalDim() { return mkTotalDim<Indices...>(); }
|
2017-08-11 15:26:10 +02:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
private:
|
|
|
|
|
2017-08-04 11:27:47 +02:00
|
|
|
IndexPack mIPack;
|
2017-08-29 17:52:08 +02:00
|
|
|
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
|
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-08-11 15:26:10 +02:00
|
|
|
MultiIndex() = delete;
|
2017-12-11 18:49:43 +01:00
|
|
|
|
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-08-11 16:45:03 +02:00
|
|
|
//MultiIndex(const MultiIndex& in);
|
|
|
|
//MultiIndex& operator=(const MultiIndex& in);
|
2017-08-11 15:26:10 +02:00
|
|
|
MultiIndex& operator=(ContainerIndex<Indices...>& ci);
|
2017-05-24 19:01:02 +02:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
template <class MRange>
|
|
|
|
MultiIndex(const std::shared_ptr<MRange>& range);
|
2017-08-28 18:28:43 +02:00
|
|
|
|
2017-07-26 16:45:09 +02:00
|
|
|
template <size_t DIR>
|
|
|
|
MultiIndex& up();
|
|
|
|
|
|
|
|
template <size_t DIR>
|
|
|
|
MultiIndex& down();
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
template <size_t 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
|
|
|
|
2017-12-12 11:15:39 +01:00
|
|
|
template <size_t N>
|
|
|
|
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
|
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
// 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 MultiIndex instances
|
|
|
|
MultiIndex& operator()(std::shared_ptr<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
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
MultiIndex& operator=(size_t 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
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
int pp(std::intptr_t idxPtrNum);
|
|
|
|
int mm(std::intptr_t idxPtrNum);
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
MetaType meta();
|
|
|
|
MultiIndex& at(const MetaType& metaPos);
|
2017-02-20 17:18:53 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
size_t dim();
|
|
|
|
bool first();
|
|
|
|
bool last();
|
|
|
|
std::shared_ptr<RangeType> range();
|
2017-12-12 11:15:39 +01:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
template <size_t N>
|
2017-12-17 14:23:23 +01:00
|
|
|
auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
|
2017-08-29 17:52:08 +02:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
std::shared_ptr<VIWB> getVPtr(size_t n);
|
|
|
|
size_t getStepSize(size_t n);
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-12-24 18:14:07 +01:00
|
|
|
std::vector<IndexInfo> infoVec() const;
|
|
|
|
|
2018-01-14 22:41:35 +01:00
|
|
|
std::string id() const;
|
2017-12-17 14:23:23 +01:00
|
|
|
void print(size_t offset);
|
2018-01-07 22:33:34 +01:00
|
|
|
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Exprs>
|
2018-02-12 00:11:24 +01:00
|
|
|
auto ifor(Exprs exs) const
|
2018-01-13 18:07:52 +01:00
|
|
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs));
|
2018-01-15 14:56:22 +01:00
|
|
|
|
|
|
|
template <class Exprs>
|
2018-02-12 00:11:24 +01:00
|
|
|
auto iforh(Exprs exs) const
|
2018-01-15 14:56:22 +01:00
|
|
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
/*************************
|
|
|
|
* MultiRangeFactory *
|
|
|
|
*************************/
|
|
|
|
|
|
|
|
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;
|
|
|
|
MultiRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
2017-08-04 11:27:47 +02:00
|
|
|
MultiRangeFactory(const typename MultiRange<Ranges...>::SpaceType& space);
|
2017-08-11 15:26:10 +02:00
|
|
|
MultiRangeFactory(const std::shared_ptr<ContainerRange<Ranges...> >& cr);
|
2017-07-26 18:38:11 +02:00
|
|
|
|
|
|
|
virtual std::shared_ptr<RangeBase> create() override;
|
|
|
|
};
|
2017-02-21 17:41:48 +01:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
/******************
|
|
|
|
* MultiRange *
|
|
|
|
******************/
|
|
|
|
|
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;
|
2017-05-22 13:39:37 +02:00
|
|
|
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
|
2017-12-12 11:15:39 +01:00
|
|
|
typedef MultiIndex<typename Ranges::IndexType...> IndexType;
|
|
|
|
//typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
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;
|
|
|
|
|
|
|
|
MultiRange(const std::shared_ptr<Ranges>&... rs);
|
|
|
|
MultiRange(const SpaceType& space);
|
|
|
|
|
|
|
|
SpaceType mSpace;
|
2017-12-15 14:47:02 +01:00
|
|
|
|
2017-08-04 11:27:47 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
static const size_t sdim = sizeof...(Ranges);
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-08-04 11:27:47 +02:00
|
|
|
template <size_t N>
|
|
|
|
auto get() const -> decltype( *std::get<N>( mSpace ) )&;
|
2017-08-04 14:57:19 +02:00
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
2017-07-25 17:46:59 +02:00
|
|
|
|
2017-07-27 14:48:41 +02:00
|
|
|
virtual size_t dim() const override;
|
|
|
|
virtual size_t size() const override;
|
2017-02-28 19:29:52 +01:00
|
|
|
|
2017-07-25 17:46:59 +02:00
|
|
|
const SpaceType& space() const;
|
2017-02-17 18:10:03 +01:00
|
|
|
|
2017-08-04 11:27:47 +02:00
|
|
|
virtual IndexType begin() const override;
|
|
|
|
virtual IndexType end() const override;
|
2017-05-24 19:01:02 +02:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
virtual std::shared_ptr<VIWB> index() const override;
|
2017-07-26 18:38:11 +02:00
|
|
|
|
|
|
|
friend MultiRangeFactory<Ranges...>;
|
2017-12-15 14:47:02 +01:00
|
|
|
|
2018-02-13 16:54:13 +01:00
|
|
|
static constexpr bool defaultable = false;
|
|
|
|
static constexpr size_t ISSTATIC = SubProp<Ranges...>::ISSTATIC;
|
|
|
|
static constexpr size_t SIZE = SubProp<Ranges...>::SIZE;
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace MultiArrayHelper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************
|
|
|
|
* MultiIndex *
|
|
|
|
******************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>::MultiIndex(const MultiIndex<Indices...>& in) :
|
|
|
|
IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(const MultiIndex<Indices...>& in)
|
|
|
|
{
|
|
|
|
IndexI::operator=(in);
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
2017-11-20 21:35:25 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(ContainerIndex<Indices...>& ci)
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::copyInst(mIPack, ci);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
2017-11-20 21:35:25 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
template <class MRange>
|
|
|
|
MultiIndex<Indices...>::MultiIndex(const std::shared_ptr<MRange>& range) :
|
2017-12-11 18:49:43 +01:00
|
|
|
IndexInterface<MultiIndex<Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
2017-11-20 21:35:25 +01:00
|
|
|
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack); // has one more element!
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
template <size_t DIR>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
|
|
|
{
|
|
|
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
2017-12-17 17:40:55 +01:00
|
|
|
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
|
|
|
RPackNum<DIR>::pp( mIPack );
|
2017-11-20 21:35:25 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
template <size_t DIR>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::down()
|
|
|
|
{
|
|
|
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
2017-12-17 17:40:55 +01:00
|
|
|
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
|
|
|
RPackNum<DIR>::mm( mIPack );
|
2017-11-20 21:35:25 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
template <size_t N>
|
|
|
|
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>
|
|
|
|
template <size_t N>
|
|
|
|
auto MultiIndex<Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
|
|
|
|
{
|
|
|
|
return std::get<N>(mIPack);
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
|
|
|
|
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
2017-11-20 21:35:25 +01: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>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
|
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
2017-12-17 14:23:23 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
2017-12-17 14:23:23 +01:00
|
|
|
++IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
2017-12-17 14:23:23 +01:00
|
|
|
--IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
int MultiIndex<Indices...>::pp(std::intptr_t idxPtrNum)
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
2017-12-17 14:23:23 +01:00
|
|
|
IB::mPos += tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
int MultiIndex<Indices...>::mm(std::intptr_t idxPtrNum)
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
2017-12-17 14:23:23 +01:00
|
|
|
IB::mPos -= tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta()
|
|
|
|
{
|
|
|
|
MetaType metaTuple;
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
|
2017-12-17 14:23:23 +01:00
|
|
|
return metaTuple;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos)
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
|
|
|
|
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
2017-12-17 14:23:23 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
size_t MultiIndex<Indices...>::dim()
|
|
|
|
{
|
|
|
|
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>
|
|
|
|
std::shared_ptr<typename MultiIndex<Indices...>::RangeType>
|
|
|
|
MultiIndex<Indices...>::range()
|
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
template <size_t N>
|
|
|
|
auto MultiIndex<Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
|
|
|
|
{
|
|
|
|
return std::get<N>(mIPack);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
std::shared_ptr<VIWB> MultiIndex<Indices...>::getVPtr(size_t n)
|
|
|
|
{
|
|
|
|
if(n >= sizeof...(Indices)){
|
|
|
|
assert(0);
|
|
|
|
// throw !!
|
|
|
|
}
|
|
|
|
MultiIndex<Indices...> const* t = this;
|
2017-12-17 17:40:55 +01:00
|
|
|
return RPackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
|
2017-12-17 14:23:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
size_t MultiIndex<Indices...>::getStepSize(size_t n)
|
|
|
|
{
|
|
|
|
if(n >= sizeof...(Indices)){
|
|
|
|
assert(0);
|
|
|
|
// throw !!
|
|
|
|
}
|
|
|
|
return mBlockSizes[n+1];
|
|
|
|
}
|
|
|
|
|
2017-12-24 18:14:07 +01:00
|
|
|
template <class... Indices>
|
|
|
|
std::vector<IndexInfo> MultiIndex<Indices...>::infoVec() const
|
|
|
|
{
|
2017-12-25 13:44:55 +01:00
|
|
|
std::vector<IndexInfo> out;
|
|
|
|
out.reserve(sizeof...(Indices));
|
|
|
|
RPackNum<sizeof...(Indices)-1>::buildInfoVec(out, mIPack, mBlockSizes);
|
2017-12-24 18:14:07 +01:00
|
|
|
return std::move( out );
|
|
|
|
}
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <class... Indices>
|
2018-01-14 22:41:35 +01:00
|
|
|
std::string MultiIndex<Indices...>::id() const
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return std::string("mul") + std::to_string(IB::mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
void MultiIndex<Indices...>::print(size_t offset)
|
|
|
|
{
|
|
|
|
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;
|
2017-12-17 17:40:55 +01:00
|
|
|
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
|
2017-12-17 14:23:23 +01:00
|
|
|
}
|
|
|
|
|
2018-01-07 22:33:34 +01:00
|
|
|
template <class... Indices>
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Exprs>
|
2018-02-12 00:11:24 +01:00
|
|
|
auto MultiIndex<Indices...>::ifor(Exprs exs) const
|
2018-01-13 18:07:52 +01:00
|
|
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs))
|
2018-01-07 22:33:34 +01:00
|
|
|
{
|
2018-01-13 18:07:52 +01:00
|
|
|
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs);
|
2018-01-07 22:33:34 +01:00
|
|
|
}
|
2018-01-15 14:56:22 +01:00
|
|
|
|
|
|
|
template <class... Indices>
|
|
|
|
template <class Exprs>
|
2018-02-12 00:11:24 +01:00
|
|
|
auto MultiIndex<Indices...>::iforh(Exprs exs) const
|
2018-01-15 14:56:22 +01:00
|
|
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
|
|
|
{
|
|
|
|
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/*************************
|
|
|
|
* MultiRangeFactory *
|
|
|
|
*************************/
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
MultiRangeFactory<Ranges...>::MultiRangeFactory(const std::shared_ptr<Ranges>&... rs)
|
|
|
|
{
|
|
|
|
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( rs... ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
MultiRangeFactory<Ranges...>::MultiRangeFactory(const typename MultiRange<Ranges...>::SpaceType& st)
|
|
|
|
{
|
|
|
|
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
MultiRangeFactory<Ranges...>::MultiRangeFactory(const std::shared_ptr<ContainerRange<Ranges...> >& cr)
|
|
|
|
{
|
|
|
|
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( cr->space() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
|
|
|
{
|
|
|
|
setSelf();
|
|
|
|
return mProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************
|
|
|
|
* MultiRange *
|
|
|
|
******************/
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
MultiRange<Ranges...>::MultiRange(const std::shared_ptr<Ranges>&... rs) : mSpace(std::make_tuple(rs...)) {}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
MultiRange<Ranges...>::MultiRange(const SpaceType& space) : mSpace( space ) {}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
template <size_t N>
|
|
|
|
auto MultiRange<Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
|
|
|
|
{
|
|
|
|
return *std::get<N>(mSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
template <size_t N>
|
|
|
|
auto MultiRange<Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
|
|
|
|
{
|
|
|
|
return std::get<N>(mSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
size_t MultiRange<Ranges...>::dim() const
|
|
|
|
{
|
|
|
|
return sdim;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
size_t MultiRange<Ranges...>::size() const
|
|
|
|
{
|
2017-12-17 17:40:55 +01:00
|
|
|
return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
const typename MultiRange<Ranges...>::SpaceType& MultiRange<Ranges...>::space() const
|
|
|
|
{
|
|
|
|
return mSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
|
|
|
typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::begin() const
|
|
|
|
{
|
|
|
|
MultiIndex<typename Ranges::IndexType...>
|
|
|
|
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
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...> >
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis )) );
|
|
|
|
i = size();
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Ranges>
|
2017-12-11 18:49:43 +01:00
|
|
|
std::shared_ptr<VIWB> MultiRange<Ranges...>::index() const
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2017-12-12 11:15:39 +01:00
|
|
|
typedef IndexWrapper<IndexType> IW;
|
|
|
|
return std::make_shared<IW>
|
|
|
|
( std::make_shared<IndexType>
|
2017-12-11 18:49:43 +01:00
|
|
|
( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
#endif
|