2017-02-16 11:20:40 +01:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
|
|
|
#ifndef __single_range_h__
|
|
|
|
#define __single_range_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <vector>
|
2017-06-01 13:19:27 +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/index_base.h"
|
|
|
|
#include "ranges/range_base.h"
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2018-01-07 22:33:34 +01:00
|
|
|
#include "xfor/xfor.h"
|
|
|
|
|
|
|
|
using MultiArrayHelper::For;
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-12-10 18:41:53 +01:00
|
|
|
class SingleIndex : public IndexInterface<SingleIndex<U,TYPE>,U>
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
typedef IndexInterface<SingleIndex<U,TYPE>,U> IB;
|
2017-08-04 14:57:19 +02:00
|
|
|
typedef U MetaType;
|
2017-08-11 15:26:10 +02:00
|
|
|
typedef SingleRange<U,TYPE> RangeType;
|
2017-08-04 11:27:47 +02:00
|
|
|
|
2017-08-11 16:45:03 +02:00
|
|
|
//DEFAULT_MEMBERS_X(SingleIndex);
|
2017-08-04 11:27:47 +02:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
|
2017-08-28 18:28:43 +02:00
|
|
|
|
2018-01-05 13:56:16 +01:00
|
|
|
static IndexType sType() { return IndexType::SINGLE; }
|
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
|
|
|
|
2017-12-26 15:13:50 +01:00
|
|
|
IndexType type() const;
|
2017-08-11 16:45:03 +02:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
SingleIndex& operator=(size_t pos);
|
|
|
|
SingleIndex& operator++();
|
|
|
|
SingleIndex& 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-08-30 17:56:38 +02:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
U meta();
|
|
|
|
SingleIndex& at(const U& metaPos);
|
2017-03-03 17:51:42 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
size_t dim(); // = 1
|
|
|
|
bool last();
|
|
|
|
bool first();
|
2017-08-25 22:03:20 +02:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
std::shared_ptr<RangeType> range();
|
2017-12-12 11:15:39 +01:00
|
|
|
|
2017-12-10 18:41:53 +01:00
|
|
|
template <size_t N>
|
2017-12-17 14:23:23 +01:00
|
|
|
void getPtr();
|
2017-12-10 18:41:53 +01: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-24 18:14:07 +01:00
|
|
|
|
|
|
|
std::vector<IndexInfo> infoVec() const;
|
2017-12-10 18:41:53 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
std::string id();
|
|
|
|
void print(size_t offset);
|
2018-01-07 22:33:34 +01:00
|
|
|
|
2018-01-09 17:24:10 +01:00
|
|
|
template <class Expr, size_t DIM, class... Ops>
|
|
|
|
auto ifor(const std::array<std::tuple<to_size_t<Ops>...>,DIM>& ee, Expr&& ex) const
|
2018-01-09 11:37:26 +01:00
|
|
|
-> For<SingleIndex<U,TYPE>,Expr,Ops...>;
|
2017-02-16 11:20:40 +01:00
|
|
|
};
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-07-28 11:33:31 +02:00
|
|
|
class SingleRangeFactory : public RangeFactoryBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef SingleRange<U,TYPE> oType;
|
|
|
|
|
|
|
|
SingleRangeFactory() = delete;
|
|
|
|
SingleRangeFactory(const std::vector<U>& space);
|
|
|
|
std::shared_ptr<RangeBase> create();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-08-04 11:27:47 +02:00
|
|
|
class SingleRange : public RangeInterface<SingleIndex<U,TYPE> >
|
2017-02-16 11:20:40 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-08-04 11:27:47 +02:00
|
|
|
typedef RangeBase RB;
|
2017-12-12 11:15:39 +01:00
|
|
|
typedef SingleIndex<U,TYPE> IndexType;
|
|
|
|
//typedef typename RangeInterface<SingleIndex<U,TYPE> >::IndexType IndexType;
|
2017-02-17 18:10:03 +01:00
|
|
|
|
2017-02-16 16:06:23 +01:00
|
|
|
virtual size_t size() const override;
|
2017-08-04 11:27:47 +02:00
|
|
|
virtual size_t dim() const override;
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
const U& get(size_t pos) const;
|
2017-03-03 17:51:42 +01:00
|
|
|
size_t getMeta(const U& metaPos) const;
|
2017-02-20 17:18:53 +01:00
|
|
|
|
2017-08-04 14:57:19 +02:00
|
|
|
virtual IndexType begin() const override;
|
|
|
|
virtual IndexType end() const override;
|
2017-12-10 18:41:53 +01:00
|
|
|
virtual std::shared_ptr<VIWB> index() const override;
|
2017-07-28 14:02:44 +02:00
|
|
|
|
2017-07-26 18:38:11 +02:00
|
|
|
friend SingleRangeFactory<U,TYPE>;
|
2017-12-15 14:47:02 +01:00
|
|
|
|
|
|
|
static const bool defaultable = false;
|
2017-02-16 11:20:40 +01:00
|
|
|
|
|
|
|
protected:
|
2017-07-26 18:38:11 +02:00
|
|
|
|
|
|
|
SingleRange() = delete;
|
|
|
|
SingleRange(const SingleRange& in) = delete;
|
2017-06-01 13:19:27 +02:00
|
|
|
|
|
|
|
SingleRange(const std::vector<U>& space);
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
std::vector<U> mSpace;
|
|
|
|
};
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-03-30 14:41:57 +02:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
/******************
|
|
|
|
* SingleIndex *
|
|
|
|
******************/
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
|
2017-12-11 18:49:43 +01:00
|
|
|
IndexInterface<SingleIndex<U,TYPE>,U>(range, 0) {}
|
2017-12-17 14:23:23 +01:00
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
2017-12-26 15:13:50 +01:00
|
|
|
IndexType SingleIndex<U,TYPE>::type() const
|
2017-12-17 14:23:23 +01:00
|
|
|
{
|
|
|
|
return IndexType::SINGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
|
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator++()
|
|
|
|
{
|
|
|
|
++IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator--()
|
|
|
|
{
|
|
|
|
--IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
int SingleIndex<U,TYPE>::pp(std::intptr_t idxPtrNum)
|
|
|
|
{
|
|
|
|
++(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
int SingleIndex<U,TYPE>::mm(std::intptr_t idxPtrNum)
|
|
|
|
{
|
|
|
|
--(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
U SingleIndex<U,TYPE>::meta()
|
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->get( IB::pos() );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::at(const U& metaPos)
|
|
|
|
{
|
|
|
|
(*this) = std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
size_t SingleIndex<U,TYPE>::dim() // = 1
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
bool SingleIndex<U,TYPE>::last()
|
|
|
|
{
|
|
|
|
return IB::mPos == IB::mMax - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
bool SingleIndex<U,TYPE>::first()
|
|
|
|
{
|
|
|
|
return IB::mPos == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
std::shared_ptr<typename SingleIndex<U,TYPE>::RangeType> SingleIndex<U,TYPE>::range()
|
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
template <size_t N>
|
|
|
|
void SingleIndex<U,TYPE>::getPtr() {}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
std::shared_ptr<VIWB> SingleIndex<U,TYPE>::getVPtr(size_t n)
|
|
|
|
{
|
|
|
|
return std::shared_ptr<VIWB>();
|
|
|
|
}
|
|
|
|
|
2017-12-24 18:14:07 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
std::vector<IndexInfo> SingleIndex<U,TYPE>::infoVec() const
|
|
|
|
{
|
|
|
|
return std::move( std::vector<IndexInfo>() );
|
|
|
|
}
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
size_t SingleIndex<U,TYPE>::getStepSize(size_t n)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
std::string SingleIndex<U,TYPE>::id()
|
|
|
|
{
|
|
|
|
return std::string("sin") + std::to_string(IB::mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, SpaceType TYPE>
|
|
|
|
void SingleIndex<U,TYPE>::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;
|
|
|
|
}
|
|
|
|
|
2018-01-07 22:33:34 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2018-01-09 17:24:10 +01:00
|
|
|
template <class Expr, size_t DIM, class... Ops>
|
|
|
|
auto SingleIndex<U,TYPE>::ifor(const std::array<std::tuple<to_size_t<Ops>...>,DIM>& ee, Expr&& ex) const
|
2018-01-09 11:37:26 +01:00
|
|
|
-> For<SingleIndex<U,TYPE>,Expr,Ops...>
|
2018-01-07 22:33:34 +01:00
|
|
|
{
|
2018-01-09 17:24:10 +01:00
|
|
|
static const size_t layer = typename Expr::layer();
|
|
|
|
return For<SingleIndex<U,TYPE>,Expr,Ops...>( this, ex, std::get<layer>( ee ) );
|
2018-01-07 22:33:34 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
|
|
|
|
/********************
|
|
|
|
* SingleRange *
|
|
|
|
********************/
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
SingleRangeFactory<U,TYPE>::SingleRangeFactory(const std::vector<U>& space)
|
2017-03-14 23:00:41 +01:00
|
|
|
{
|
2017-11-20 21:35:25 +01:00
|
|
|
mProd = std::shared_ptr<oType>( new SingleRange<U,TYPE>( space ) );
|
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
std::shared_ptr<RangeBase> SingleRangeFactory<U,TYPE>::create()
|
|
|
|
{
|
|
|
|
setSelf();
|
|
|
|
return mProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************
|
|
|
|
* SingleRange *
|
|
|
|
********************/
|
2017-03-15 22:54:48 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
SingleRange<U,TYPE>::SingleRange(const std::vector<U>& space) : RangeInterface<SingleIndex<U,TYPE> >(),
|
|
|
|
mSpace(space) {}
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
const U& SingleRange<U,TYPE>::get(size_t pos) const
|
2017-03-14 23:00:41 +01:00
|
|
|
{
|
2017-11-20 21:35:25 +01:00
|
|
|
return mSpace[pos];
|
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
size_t SingleRange<U,TYPE>::getMeta(const U& metaPos) const
|
|
|
|
{
|
|
|
|
size_t cnt = 0;
|
|
|
|
for(auto& x: mSpace){
|
|
|
|
if(x == metaPos){
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
size_t SingleRange<U,TYPE>::size() const
|
|
|
|
{
|
|
|
|
return mSpace.size();
|
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
size_t SingleRange<U,TYPE>::dim() const
|
2017-03-14 23:00:41 +01:00
|
|
|
{
|
2017-11-20 21:35:25 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::begin() const
|
|
|
|
{
|
|
|
|
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = 0;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-11-20 21:35:25 +01:00
|
|
|
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::end() const
|
|
|
|
{
|
|
|
|
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
|
|
i = size();
|
|
|
|
return i;
|
|
|
|
}
|
2017-03-14 23:00:41 +01:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
// put this in the interface class !!!
|
2017-12-17 14:23:23 +01:00
|
|
|
template <typename U, SpaceType TYPE>
|
2017-12-10 18:41:53 +01:00
|
|
|
std::shared_ptr<VIWB> SingleRange<U,TYPE>::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<SingleRange<U,TYPE> >
|
|
|
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
2017-02-16 11:20:40 +01:00
|
|
|
|
2017-12-04 18:29:18 +01:00
|
|
|
#include "range_types/header.h"
|
|
|
|
|
2017-02-16 11:20:40 +01:00
|
|
|
#endif
|