split rpack_num -> .h , .cc.h
This commit is contained in:
parent
52e1efc974
commit
991a9bc5b4
20 changed files with 1128 additions and 621 deletions
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
#include "multi_array_operation.cc.h"
|
#include "multi_array_operation.cc.h"
|
||||||
#include "functional_multi_array.cc.h"
|
#include "functional_multi_array.cc.h"
|
||||||
#include "helper_tools.cc.h"
|
#include "helper_tools.cc.h"
|
||||||
|
@ -9,4 +11,3 @@
|
||||||
#include "dynamic_operation.cc.h"
|
#include "dynamic_operation.cc.h"
|
||||||
//#include "expressions.cc.h"
|
//#include "expressions.cc.h"
|
||||||
|
|
||||||
#include "ranges/dynamic_range.cc.h"
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
//#include "ranges/dynamic_range.h"
|
#include "ranges/dynamic_range.h"
|
||||||
//#include "ranges/dynamic_meta.h"
|
//#include "ranges/dynamic_meta.h"
|
||||||
|
|
||||||
#include "rpack_num.h"
|
#include "rpack_num.h"
|
||||||
|
@ -11,11 +11,6 @@ namespace MultiArrayTools
|
||||||
using namespace MultiArrayHelper;
|
using namespace MultiArrayHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
size_t IndexWrapper<Index>::getStepSizeComp(std::intptr_t j) const
|
|
||||||
{
|
|
||||||
return MultiArrayHelper::getStepSize(*mI, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
* DynamicRangeFactory *
|
* DynamicRangeFactory *
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#define __dynamic_range_h__
|
#define __dynamic_range_h__
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "ranges/rbase_def.h"
|
#include "ranges/rbase_def.h"
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
|
@ -10,13 +11,13 @@
|
||||||
|
|
||||||
#include "xfor/xfor.h"
|
#include "xfor/xfor.h"
|
||||||
|
|
||||||
#include <map>
|
|
||||||
//#include "ranges/rpheader.h"
|
//#include "ranges/rpheader.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/type_map.h"
|
#include "ranges/type_map.h"
|
||||||
|
|
||||||
#include "ranges/dynamic_meta.h"
|
#include "ranges/dynamic_meta.h"
|
||||||
|
|
||||||
|
#include "index_wrapper.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
|
@ -38,139 +39,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
class IndexWrapperBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
IndexWrapperBase() = default;
|
|
||||||
IndexWrapperBase(const IndexWrapperBase& in) = default;
|
|
||||||
IndexWrapperBase(IndexWrapperBase&& in) = default;
|
|
||||||
IndexWrapperBase& operator=(const IndexWrapperBase& in) = default;
|
|
||||||
IndexWrapperBase& operator=(IndexWrapperBase&& in) = default;
|
|
||||||
|
|
||||||
virtual IndexType type() const = 0;
|
|
||||||
|
|
||||||
virtual IndexWrapperBase& operator=(size_t pos) = 0;
|
|
||||||
virtual IndexWrapperBase& operator++() = 0;
|
|
||||||
virtual IndexWrapperBase& operator--() = 0;
|
|
||||||
|
|
||||||
virtual int pp(std::intptr_t idxPtrNum) = 0;
|
|
||||||
virtual int mm(std::intptr_t idxPtrNum) = 0;
|
|
||||||
|
|
||||||
virtual std::string stringMeta() const = 0;
|
|
||||||
|
|
||||||
virtual size_t pos() const = 0;
|
|
||||||
virtual size_t max() const = 0;
|
|
||||||
virtual size_t dim() const = 0;
|
|
||||||
virtual bool last() const = 0;
|
|
||||||
virtual bool first() const = 0;
|
|
||||||
|
|
||||||
virtual std::shared_ptr<RangeBase> range() const = 0;
|
|
||||||
|
|
||||||
virtual size_t getStepSize(size_t n) const = 0;
|
|
||||||
virtual size_t getStepSizeComp(std::intptr_t j) const = 0;
|
|
||||||
|
|
||||||
virtual std::intptr_t get() const = 0;
|
|
||||||
virtual std::intptr_t ptrNum() const = 0;
|
|
||||||
|
|
||||||
virtual std::shared_ptr<IndexWrapperBase> duplicate() const = 0;
|
|
||||||
|
|
||||||
//virtual DynamicMetaT meta() const = 0;
|
|
||||||
//virtual const DynamicMetaT* metaPtr() const = 0;
|
|
||||||
//virtual AbstractIW& at(const U& metaPos) = 0;
|
|
||||||
//virtual size_t posAt(const U& metaPos) const = 0;
|
|
||||||
|
|
||||||
//virtual bool isMeta(const U& metaPos) const = 0;
|
|
||||||
inline IndexWrapperBase& at(const std::string smeta)
|
|
||||||
{
|
|
||||||
for((*this) = 0; this->pos() != this->max(); ++(*this)){
|
|
||||||
if(this->stringMeta() == smeta){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const = 0;
|
|
||||||
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const = 0;
|
|
||||||
/*
|
|
||||||
std::shared_ptr<IndexWrapperBase> duplicateI() const
|
|
||||||
{ return std::dynamic_pointer_cast<IndexWrapperBase>( this->duplicate() ); }
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef IndexWrapperBase IndexW;
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
class IndexWrapper : public IndexWrapperBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef IndexWrapperBase IWB;
|
|
||||||
typedef typename Index::MetaType MetaType;
|
|
||||||
|
|
||||||
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
IndexWrapper() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::shared_ptr<Index> mI;
|
|
||||||
public:
|
|
||||||
|
|
||||||
IndexWrapper(const IndexWrapper& in) = default;
|
|
||||||
IndexWrapper(IndexWrapper&& in) = default;
|
|
||||||
IndexWrapper& operator=(const IndexWrapper& in) = default;
|
|
||||||
IndexWrapper& operator=(IndexWrapper&& in) = default;
|
|
||||||
|
|
||||||
IndexWrapper(const std::shared_ptr<Index>& i) : mI(i) {}
|
|
||||||
|
|
||||||
virtual IndexType type() const final { return mI->type(); }
|
|
||||||
|
|
||||||
virtual IndexWrapper& operator=(size_t pos) override final { (*mI) = pos; return *this; }
|
|
||||||
virtual IndexWrapper& operator++() override final { ++(*mI); return *this; }
|
|
||||||
virtual IndexWrapper& operator--() override final { --(*mI); return *this; }
|
|
||||||
|
|
||||||
virtual size_t pos() const override final { return mI->pos(); }
|
|
||||||
virtual size_t max() const override final { return mI->max(); }
|
|
||||||
|
|
||||||
virtual int pp(std::intptr_t idxPtrNum) override final { return mI->pp(idxPtrNum); }
|
|
||||||
virtual int mm(std::intptr_t idxPtrNum) override final { return mI->mm(idxPtrNum); }
|
|
||||||
|
|
||||||
virtual std::string stringMeta() const override final { return mI->stringMeta(); }
|
|
||||||
//virtual DynamicMetaT meta() const final { return DynamicMetaT(mI->meta()); }
|
|
||||||
//virtual const DynamicMetaT* metaPtr() const final { return nullptr; }
|
|
||||||
IndexWrapper& at(const typename Index::MetaType& metaPos) { mI->at(metaPos); return *this; }
|
|
||||||
size_t posAt(const typename Index::MetaType& metaPos) const { return mI->posAt(metaPos); }
|
|
||||||
|
|
||||||
//virtual bool isMeta(const U& metaPos) const final { return mI->isMeta(); }
|
|
||||||
|
|
||||||
virtual size_t dim() const override final { return mI->dim(); }
|
|
||||||
virtual bool last() const override final { return mI->last(); }
|
|
||||||
virtual bool first() const override final { return mI->first(); }
|
|
||||||
|
|
||||||
virtual std::shared_ptr<RangeBase> range() const override final { return mI->range(); }
|
|
||||||
|
|
||||||
virtual size_t getStepSize(size_t n) const override final { return mI->getStepSize(n); }
|
|
||||||
virtual size_t getStepSizeComp(std::intptr_t j) const override final;
|
|
||||||
|
|
||||||
virtual std::intptr_t get() const override final { return reinterpret_cast<std::intptr_t>(mI.get()); }
|
|
||||||
virtual std::intptr_t ptrNum() const override final { return mI->ptrNum(); }
|
|
||||||
|
|
||||||
virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const override final
|
|
||||||
{ return mI->ifor(step, ex); }
|
|
||||||
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const override final
|
|
||||||
{ return mI->iforh(step, ex); }
|
|
||||||
|
|
||||||
virtual std::shared_ptr<IndexWrapperBase> duplicate() const override final
|
|
||||||
{ return std::make_shared<IndexWrapper>( std::make_shared<Index>( *mI ) ); }
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
std::shared_ptr<IndexWrapperBase> mkIndexWrapper(const Index& i)
|
|
||||||
{
|
|
||||||
return std::make_shared<IndexWrapper<Index>>(std::make_shared<Index>(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
//typedef SingleRange<size_t,SpaceType::DYN> DynamicRange;
|
//typedef SingleRange<size_t,SpaceType::DYN> DynamicRange;
|
||||||
|
|
||||||
|
|
152
src/include/ranges/index_wrapper.cc.h
Normal file
152
src/include/ranges/index_wrapper.cc.h
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
|
||||||
|
#include "index_wrapper.h"
|
||||||
|
#include "rpack_num.h"
|
||||||
|
|
||||||
|
namespace MultiArrayTools
|
||||||
|
{
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
IndexWrapper<Index>::IndexWrapper(const std::shared_ptr<Index>& i) : mI(i) {}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
IndexType IndexWrapper<Index>::type() const
|
||||||
|
{
|
||||||
|
return mI->type();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
IndexWrapper<Index>& IndexWrapper<Index>::operator=(size_t pos)
|
||||||
|
{
|
||||||
|
(*mI) = pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
IndexWrapper<Index>& IndexWrapper<Index>::operator++()
|
||||||
|
{
|
||||||
|
++(*mI);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
IndexWrapper<Index>& IndexWrapper<Index>::operator--()
|
||||||
|
{
|
||||||
|
--(*mI);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
size_t IndexWrapper<Index>::pos() const
|
||||||
|
{
|
||||||
|
return mI->pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
size_t IndexWrapper<Index>::max() const
|
||||||
|
{
|
||||||
|
return mI->max();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
int IndexWrapper<Index>::pp(std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
return mI->pp(idxPtrNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
int IndexWrapper<Index>::mm(std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
return mI->mm(idxPtrNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
std::string IndexWrapper<Index>::stringMeta() const
|
||||||
|
{
|
||||||
|
return mI->stringMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
IndexWrapper<Index>& IndexWrapper<Index>::at(const typename Index::MetaType& metaPos)
|
||||||
|
{
|
||||||
|
mI->at(metaPos);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
size_t IndexWrapper<Index>::posAt(const typename Index::MetaType& metaPos)
|
||||||
|
{
|
||||||
|
return mI->posAt(metaPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
size_t IndexWrapper<Index>::dim() const
|
||||||
|
{
|
||||||
|
return mI->dim();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
bool IndexWrapper<Index>::last() const
|
||||||
|
{
|
||||||
|
return mI->last();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
bool IndexWrapper<Index>::first() const
|
||||||
|
{
|
||||||
|
return mI->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
std::shared_ptr<RangeBase> IndexWrapper<Index>::range() const
|
||||||
|
{
|
||||||
|
return mI->range();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
size_t IndexWrapper<Index>::getStepSize(size_t n) const
|
||||||
|
{
|
||||||
|
return mI->getStepSize(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
size_t IndexWrapper<Index>::getStepSizeComp(std::intptr_t j) const
|
||||||
|
{
|
||||||
|
return MultiArrayHelper::getStepSize(*mI, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
std::intptr_t IndexWrapper<Index>::get() const
|
||||||
|
{
|
||||||
|
return reinterpret_cast<std::intptr_t>(mI.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
std::intptr_t IndexWrapper<Index>::ptrNum() const
|
||||||
|
{
|
||||||
|
return mI->ptrNum();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
DynamicExpression IndexWrapper<Index>::ifor(size_t step, DynamicExpression ex) const
|
||||||
|
{
|
||||||
|
return mI->ifor(step, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
DynamicExpression IndexWrapper<Index>::iforh(size_t step, DynamicExpression ex) const
|
||||||
|
{
|
||||||
|
return mI->iforh(step, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
std::shared_ptr<IndexWrapperBase> IndexWrapper<Index>::duplicate() const
|
||||||
|
{
|
||||||
|
return std::make_shared<IndexWrapper>( std::make_shared<Index>( *mI ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
std::shared_ptr<IndexWrapperBase> mkIndexWrapper(const Index& i)
|
||||||
|
{
|
||||||
|
return std::make_shared<IndexWrapper<Index>>(std::make_shared<Index>(i));
|
||||||
|
}
|
||||||
|
}
|
145
src/include/ranges/index_wrapper.h
Normal file
145
src/include/ranges/index_wrapper.h
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
|
||||||
|
#ifndef __index_wrapper_h__
|
||||||
|
#define __index_wrapper_h__
|
||||||
|
|
||||||
|
#include "ranges/rbase_def.h"
|
||||||
|
#include "xfor/xfor.h"
|
||||||
|
|
||||||
|
namespace MultiArrayTools
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
using namespace MultiArrayHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
class IndexWrapperBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
IndexWrapperBase() = default;
|
||||||
|
IndexWrapperBase(const IndexWrapperBase& in) = default;
|
||||||
|
IndexWrapperBase(IndexWrapperBase&& in) = default;
|
||||||
|
IndexWrapperBase& operator=(const IndexWrapperBase& in) = default;
|
||||||
|
IndexWrapperBase& operator=(IndexWrapperBase&& in) = default;
|
||||||
|
|
||||||
|
virtual IndexType type() const = 0;
|
||||||
|
|
||||||
|
virtual IndexWrapperBase& operator=(size_t pos) = 0;
|
||||||
|
virtual IndexWrapperBase& operator++() = 0;
|
||||||
|
virtual IndexWrapperBase& operator--() = 0;
|
||||||
|
|
||||||
|
virtual int pp(std::intptr_t idxPtrNum) = 0;
|
||||||
|
virtual int mm(std::intptr_t idxPtrNum) = 0;
|
||||||
|
|
||||||
|
virtual std::string stringMeta() const = 0;
|
||||||
|
|
||||||
|
virtual size_t pos() const = 0;
|
||||||
|
virtual size_t max() const = 0;
|
||||||
|
virtual size_t dim() const = 0;
|
||||||
|
virtual bool last() const = 0;
|
||||||
|
virtual bool first() const = 0;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<RangeBase> range() const = 0;
|
||||||
|
|
||||||
|
virtual size_t getStepSize(size_t n) const = 0;
|
||||||
|
virtual size_t getStepSizeComp(std::intptr_t j) const = 0;
|
||||||
|
|
||||||
|
virtual std::intptr_t get() const = 0;
|
||||||
|
virtual std::intptr_t ptrNum() const = 0;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<IndexWrapperBase> duplicate() const = 0;
|
||||||
|
|
||||||
|
//virtual DynamicMetaT meta() const = 0;
|
||||||
|
//virtual const DynamicMetaT* metaPtr() const = 0;
|
||||||
|
//virtual AbstractIW& at(const U& metaPos) = 0;
|
||||||
|
//virtual size_t posAt(const U& metaPos) const = 0;
|
||||||
|
|
||||||
|
//virtual bool isMeta(const U& metaPos) const = 0;
|
||||||
|
inline IndexWrapperBase& at(const std::string smeta)
|
||||||
|
{
|
||||||
|
for((*this) = 0; this->pos() != this->max(); ++(*this)){
|
||||||
|
if(this->stringMeta() == smeta){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const = 0;
|
||||||
|
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const = 0;
|
||||||
|
/*
|
||||||
|
std::shared_ptr<IndexWrapperBase> duplicateI() const
|
||||||
|
{ return std::dynamic_pointer_cast<IndexWrapperBase>( this->duplicate() ); }
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef IndexWrapperBase IndexW;
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
class IndexWrapper : public IndexWrapperBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef IndexWrapperBase IWB;
|
||||||
|
typedef typename Index::MetaType MetaType;
|
||||||
|
|
||||||
|
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
IndexWrapper() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Index> mI;
|
||||||
|
public:
|
||||||
|
|
||||||
|
IndexWrapper(const IndexWrapper& in) = default;
|
||||||
|
IndexWrapper(IndexWrapper&& in) = default;
|
||||||
|
IndexWrapper& operator=(const IndexWrapper& in) = default;
|
||||||
|
IndexWrapper& operator=(IndexWrapper&& in) = default;
|
||||||
|
|
||||||
|
IndexWrapper(const std::shared_ptr<Index>& i);
|
||||||
|
|
||||||
|
virtual IndexType type() const final;
|
||||||
|
|
||||||
|
virtual IndexWrapper& operator=(size_t pos) override final;
|
||||||
|
virtual IndexWrapper& operator++() override final;
|
||||||
|
virtual IndexWrapper& operator--() override final;
|
||||||
|
|
||||||
|
virtual size_t pos() const override final;
|
||||||
|
virtual size_t max() const override final;
|
||||||
|
|
||||||
|
virtual int pp(std::intptr_t idxPtrNum) override final;
|
||||||
|
virtual int mm(std::intptr_t idxPtrNum) override final;
|
||||||
|
|
||||||
|
virtual std::string stringMeta() const override final;
|
||||||
|
//virtual DynamicMetaT meta() const final { return DynamicMetaT(mI->meta()); }
|
||||||
|
//virtual const DynamicMetaT* metaPtr() const final { return nullptr; }
|
||||||
|
IndexWrapper& at(const typename Index::MetaType& metaPos);
|
||||||
|
size_t posAt(const typename Index::MetaType& metaPos);
|
||||||
|
|
||||||
|
//virtual bool isMeta(const U& metaPos) const final { return mI->isMeta(); }
|
||||||
|
|
||||||
|
virtual size_t dim() const override final;
|
||||||
|
virtual bool last() const override final;
|
||||||
|
virtual bool first() const override final;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<RangeBase> range() const override final;
|
||||||
|
|
||||||
|
virtual size_t getStepSize(size_t n) const override final;
|
||||||
|
virtual size_t getStepSizeComp(std::intptr_t j) const override final;
|
||||||
|
|
||||||
|
virtual std::intptr_t get() const override final;
|
||||||
|
virtual std::intptr_t ptrNum() const override final;
|
||||||
|
|
||||||
|
virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const override final;
|
||||||
|
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const override final;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<IndexWrapperBase> duplicate() const override final;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
std::shared_ptr<IndexWrapperBase> mkIndexWrapper(const Index& i);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
4
src/include/ranges/ranges_header.cc.h
Normal file
4
src/include/ranges/ranges_header.cc.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
#include "rpack_num.cc.h"
|
||||||
|
#include "ranges/dynamic_range.cc.h"
|
||||||
|
#include "ranges/index_wrapper.cc.h"
|
729
src/include/ranges/rpack_num.cc.h
Normal file
729
src/include/ranges/rpack_num.cc.h
Normal file
|
@ -0,0 +1,729 @@
|
||||||
|
|
||||||
|
#include "rpack_num.h"
|
||||||
|
namespace MultiArrayHelper
|
||||||
|
{
|
||||||
|
using namespace MultiArrayTools;
|
||||||
|
|
||||||
|
template <class Index1>
|
||||||
|
size_t mkTotalDim()
|
||||||
|
{
|
||||||
|
return Index1::totalDim();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index1, class Index2, class... Indices>
|
||||||
|
size_t mkTotalDim()
|
||||||
|
{
|
||||||
|
return Index1::totalDim() * mkTotalDim<Index2,Indices...>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <class Range>
|
||||||
|
inline void resolveSetRange(std::shared_ptr<Range>& rp, const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
|
size_t origpos, size_t size)
|
||||||
|
{
|
||||||
|
assert(size == 1);
|
||||||
|
rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!!
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Range>
|
||||||
|
inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
|
||||||
|
std::shared_ptr<Range> r)
|
||||||
|
{
|
||||||
|
v.insert(v.begin(), r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
void RPackNum<N>::initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
|
std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||||
|
{
|
||||||
|
std::get<N>(bs) = RPackNum<sizeof...(Indices)-N>::blockSize(ip);
|
||||||
|
RPackNum<N-1>::initBlockSizes(bs, ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
inline void RPackNum<N>::pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||||
|
{
|
||||||
|
auto& si = *std::get<N>(ip);
|
||||||
|
if(si.last()){
|
||||||
|
si = 0;
|
||||||
|
RPackNum<N-1>::pp(ip);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++si;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
inline int RPackNum<N>::pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
|
std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
auto& siPtr = std::get<N>(ip);
|
||||||
|
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
|
return RPackNum<N-1>::pp(ip, bs, idxPtrNum);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int tmp = siPtr->pp(idxPtrNum);
|
||||||
|
if(siPtr->pos() == siPtr->max()){
|
||||||
|
(*siPtr) = 0;
|
||||||
|
return RPackNum<N-1>::pp(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return tmp * std::get<N+1>(bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
inline void RPackNum<N>::mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||||
|
{
|
||||||
|
auto& si = *std::get<N>(ip);
|
||||||
|
if(si.first()){
|
||||||
|
si = si.max() - 1;
|
||||||
|
RPackNum<N-1>::mm(ip);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
--si;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// !!!!
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
inline int RPackNum<N>::mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
|
std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
auto& siPtr = std::get<N>(ip);
|
||||||
|
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
|
return std::get<N>(bs) + RPackNum<N-1>::mm(ip, bs, idxPtrNum);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(siPtr->first()){
|
||||||
|
(*siPtr) = siPtr->max() - 1;
|
||||||
|
return RPackNum<N-1>::mm(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return siPtr->mm(idxPtrNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class RangeTuple>
|
||||||
|
size_t RPackNum<N>::getSize(const RangeTuple& rt)
|
||||||
|
{
|
||||||
|
return std::get<N>(rt)->size() * RPackNum<N-1>::getSize(rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class IndexPack, class MetaType>
|
||||||
|
void RPackNum<N>::getMetaPos(MetaType& target,
|
||||||
|
const IndexPack& source)
|
||||||
|
{
|
||||||
|
std::get<N>(target) = std::get<N>(source)->meta();
|
||||||
|
RPackNum<N-1>::getMetaPos(target, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class IndexPack, typename MetaType>
|
||||||
|
void RPackNum<N>::setMeta(IndexPack& target, const MetaType& source)
|
||||||
|
{
|
||||||
|
std::get<N>(target)->at( std::get<N>(source) );
|
||||||
|
RPackNum<N-1>::setMeta(target, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class SpaceClass>
|
||||||
|
inline std::shared_ptr<RangeBase> RPackNum<N>::getSub(const SpaceClass& space, size_t num)
|
||||||
|
{
|
||||||
|
if(num == N){
|
||||||
|
return std::get<N>(space);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return RPackNum<N-1>::getSub(space, num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class IndexPack>
|
||||||
|
void RPackNum<N>::setIndexPack(IndexPack& iPack, size_t pos)
|
||||||
|
{
|
||||||
|
auto& i = *std::get<N>(iPack).get();
|
||||||
|
const size_t ownPos = pos % i.max();
|
||||||
|
i = ownPos;
|
||||||
|
RPackNum<N-1>::setIndexPack(iPack, (pos - ownPos) / i.max() );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class MRange, class... Indices>
|
||||||
|
void RPackNum<N>::construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
const MRange& range)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(range.template get<N>())>::type SubRangeType;
|
||||||
|
typedef typename SubRangeType::IndexType SubIndexType;
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<N>(ip).get())>::type TypeFromIndexPack;
|
||||||
|
|
||||||
|
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
|
||||||
|
"inconsistent types");
|
||||||
|
|
||||||
|
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<N>() ) );
|
||||||
|
*std::get<N>(ip) = 0;
|
||||||
|
RPackNum<N-1>::construct(ip, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class IndexType, class... Indices>
|
||||||
|
void RPackNum<N>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
const IndexType& ind)
|
||||||
|
{
|
||||||
|
std::get<N>(ip) = ind.template getPtr<N>() ;
|
||||||
|
RPackNum<N-1>::copyInst(ip, ind);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class IndexType, class... Indices>
|
||||||
|
void RPackNum<N>::copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
const IndexType& ind)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<N>(ip))>::type SubType;
|
||||||
|
std::get<N>(ip) = std::make_shared<SubType>( ind.template get<N>() ) ;
|
||||||
|
RPackNum<N-1>::copyIndex(ip, ind);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
inline size_t RPackNum<N>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
||||||
|
{
|
||||||
|
//const auto& idx = *std::get<N>(iPtrTup);
|
||||||
|
return std::get<N>(iPtrTup)->pos() + RPackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
inline size_t RPackNum<N>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
||||||
|
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
|
||||||
|
{
|
||||||
|
return RPackNum<N-1>::makePos(iPtrTup, blockSize) + std::get<N>(iPtrTup)->pos() * std::get<N+1>(blockSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class Pack, class IndexType, class... Indices>
|
||||||
|
void RPackNum<N>::swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind,
|
||||||
|
const std::shared_ptr<Indices>&... ninds)
|
||||||
|
{
|
||||||
|
std::get<std::tuple_size<Pack>::value-N-1>(ipack) = nind;
|
||||||
|
RPackNum<N-1>::swapIndices(ipack, ninds...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class Pack, class... Indices>
|
||||||
|
void RPackNum<N>::swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds)
|
||||||
|
{
|
||||||
|
std::get<N>(ipack) = std::get<N>(ninds);
|
||||||
|
RPackNum<N-1>::swapIndices(ipack, ninds);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
size_t RPackNum<N>::blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
||||||
|
{
|
||||||
|
return std::get<sizeof...(Indices)-N>(pack)->max() * RPackNum<N-1>::blockSize(pack);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<N>::RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
|
vector<std::shared_ptr<RangeBase> >& v)
|
||||||
|
{
|
||||||
|
setRangeToVec(v, std::get<N>(rst));
|
||||||
|
RPackNum<N-1>::RangesToVec(rst, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<N>::RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
|
vector<std::intptr_t>& v)
|
||||||
|
{
|
||||||
|
v[N] = reinterpret_cast<std::intptr_t>( std::get<N>(rst).get() );
|
||||||
|
RPackNum<N-1>::RangesToVec(rst, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Indices>
|
||||||
|
void RPackNum<N>::printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset)
|
||||||
|
{
|
||||||
|
std::get<N>(ip)->print(offset);
|
||||||
|
RPackNum<N-1>::printIndex(ip, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class Range, class... Ranges>
|
||||||
|
void RPackNum<N>::checkDefaultable()
|
||||||
|
{
|
||||||
|
static_assert( Range::defaultable, "not defaultable" );
|
||||||
|
RPackNum<N-1>::template checkDefaultable<Ranges...>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto RPackNum<N>::mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||||
|
->ifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) )
|
||||||
|
{
|
||||||
|
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
||||||
|
return std::get<NN>(ipack)
|
||||||
|
->ifor( step*std::get<NN+1>(ba), RPackNum<N-1>::mkFor(step, ipack, ba, exs) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto RPackNum<N>::mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||||
|
->iforh( 0, RPackNum<N-1>::mkForh(step, ipack, ba, exs) ) )
|
||||||
|
{
|
||||||
|
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
||||||
|
return std::get<NN>(ipack)
|
||||||
|
->iforh( step*std::get<NN+1>(ba), RPackNum<N-1>::mkForh(step, ipack, ba, exs) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto RPackNum<N>::mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||||
|
->pifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) )
|
||||||
|
{
|
||||||
|
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
||||||
|
return std::get<NN>(ipack)
|
||||||
|
->pifor( step*std::get<NN+1>(ba), RPackNum<N-1>::mkFor(step, ipack, ba, exs) );
|
||||||
|
// mkFor is correct here, because we want to multithread only the FIRST index!!
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class Index>
|
||||||
|
inline void RPackNum<N>::getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
||||||
|
{
|
||||||
|
//constexpr size_t DIM = Index::sDim();
|
||||||
|
const auto& ni = ii.template get<N>();
|
||||||
|
const size_t max = ni.max();
|
||||||
|
const size_t tmp = getStepSize(ni, j);
|
||||||
|
//ss += tmp * sx;
|
||||||
|
ss += tmp * ii.template getBlockSize<N+1>();
|
||||||
|
sx *= max;
|
||||||
|
RPackNum<N-1>::getStepSizeX(ii, j, ss, sx);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class RangeTuple, typename... SIZET>
|
||||||
|
inline void RPackNum<N>::resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
|
RangeTuple& rtp, size_t off, size_t size, SIZET... sizes)
|
||||||
|
{
|
||||||
|
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
||||||
|
resolveSetRange(std::get<tps-N-1>(rtp), orig, off, size);
|
||||||
|
RPackNum<N-1>::resolveRangeType(orig, rtp, off+size, sizes...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Ranges>
|
||||||
|
inline bool RPackNum<N>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
||||||
|
const vector<std::intptr_t>& a)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<std::intptr_t>( std::get<N>(p).get() ) == a[N] and
|
||||||
|
RPackNum<N-1>::checkIfCreated(p,a);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class MIndex>
|
||||||
|
inline std::string RPackNum<N>::getStringMeta(const MIndex& mi)
|
||||||
|
{
|
||||||
|
return RPackNum<N-1>::getStringMeta(mi) + "," + mi.template getPtr<N>()->stringMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<N>::fillRangeDataVec(vector<char>& out,
|
||||||
|
const std::tuple<std::shared_ptr<Ranges>...>& tp)
|
||||||
|
{
|
||||||
|
vector<char> part = std::get<sizeof...(Ranges)-N-1>(tp)->data();
|
||||||
|
out.insert(out.end(), part.begin(), part.end());
|
||||||
|
RPackNum<N-1>::fillRangeDataVec(out, tp);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <size_t SIZE, class Range, class... Ranges>
|
||||||
|
inline bool RPackNum<N>::compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
|
||||||
|
{
|
||||||
|
return rbvec[SIZE-N-1]->spaceType() == Range::STYPE and RPackNum<N-1>::template compareSpaceTypes<SIZE,Ranges...>(rbvec);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<N>::setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
||||||
|
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<N>( stp ))>::type RType;
|
||||||
|
std::get<N>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[N] );
|
||||||
|
RPackNum<N-1>::setSpace(rbvec, stp);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class MetaType, class... Ranges>
|
||||||
|
inline size_t RPackNum<N>::getCMeta(MetaType* xtarget, size_t pos,
|
||||||
|
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
||||||
|
{
|
||||||
|
//constexpr size_t NN = sizeof...(Ranges);
|
||||||
|
auto& r = *std::get<N>(stp);
|
||||||
|
const size_t ownPos = pos % r.size();
|
||||||
|
const size_t s = r.cmetaSize();
|
||||||
|
off -= s;
|
||||||
|
r.cmeta(reinterpret_cast<char*>(&std::get<N>(*xtarget)), ownPos);
|
||||||
|
return s + RPackNum<N-1>::getCMeta(xtarget, (pos - ownPos) / r.size(), stp, off);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Ranges>
|
||||||
|
inline size_t RPackNum<N>::getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
constexpr size_t NN = sizeof...(Ranges);
|
||||||
|
auto& r = *std::get<NN-N-1>(stp);
|
||||||
|
return r.cmetaSize() + RPackNum<N-1>::getCMetaSize(stp);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<N>::getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
auto& r = *std::get<N>(stp);
|
||||||
|
auto tn = r.typeNum();
|
||||||
|
res.insert(res.begin(), tn.begin(), tn.end());
|
||||||
|
RPackNum<N-1>::getTypeNum(res, stp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
void RPackNum<0>::initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
|
std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||||
|
{
|
||||||
|
std::get<0>(bs) = RPackNum<sizeof...(Indices)>::blockSize(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
inline void RPackNum<0>::pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||||
|
{
|
||||||
|
auto& si = *std::get<0>(ip);
|
||||||
|
++si;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
inline int RPackNum<0>::pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
|
std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
auto& siPtr = std::get<0>(ip);
|
||||||
|
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
|
return std::get<0>(bs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int tmp = siPtr->pp(idxPtrNum);
|
||||||
|
return tmp * std::get<1>(bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
inline void RPackNum<0>::mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||||
|
{
|
||||||
|
auto& si = *std::get<0>(ip);
|
||||||
|
--si;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
inline int RPackNum<0>::mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
|
std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
auto& siPtr = std::get<0>(ip);
|
||||||
|
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
|
return std::get<0>(bs);
|
||||||
|
//return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return siPtr->mm(idxPtrNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class RangeTuple>
|
||||||
|
size_t RPackNum<0>::getSize(const RangeTuple& rt)
|
||||||
|
{
|
||||||
|
return std::get<0>(rt)->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexPack, class MetaType>
|
||||||
|
void RPackNum<0>::getMetaPos(MetaType& target,
|
||||||
|
const IndexPack& source)
|
||||||
|
{
|
||||||
|
std::get<0>(target) = std::get<0>(source)->meta();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexPack, typename MetaType>
|
||||||
|
void RPackNum<0>::setMeta(IndexPack& target, const MetaType& source)
|
||||||
|
{
|
||||||
|
std::get<0>(target)->at( std::get<0>( source ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class SpaceClass>
|
||||||
|
inline std::shared_ptr<RangeBase> RPackNum<0>::getSub(const SpaceClass& space, size_t num)
|
||||||
|
{
|
||||||
|
if(num == 0){
|
||||||
|
return std::get<0>(space);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert(0);
|
||||||
|
return std::shared_ptr<RangeBase>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexPack>
|
||||||
|
void RPackNum<0>::setIndexPack(IndexPack& iPack, size_t pos)
|
||||||
|
{
|
||||||
|
auto& i = *std::get<0>(iPack);
|
||||||
|
const size_t ownPos = pos % i.max();
|
||||||
|
i = ownPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class MRange, class... Indices>
|
||||||
|
void RPackNum<0>::construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
const MRange& range)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(range.template get<0>())>::type SubRangeType;
|
||||||
|
typedef typename SubRangeType::IndexType SubIndexType;
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<0>(ip).get())>::type TypeFromIndexPack;
|
||||||
|
|
||||||
|
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
|
||||||
|
"inconsistent types");
|
||||||
|
|
||||||
|
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<0>() ) );
|
||||||
|
*std::get<0>(ip) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexType, class... Indices>
|
||||||
|
void RPackNum<0>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
const IndexType& ind)
|
||||||
|
{
|
||||||
|
std::get<0>(ip) = ind.template getPtr<0>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexType, class... Indices>
|
||||||
|
void RPackNum<0>::copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
const IndexType& ind)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<0>(ip))>::type SubType;
|
||||||
|
std::get<0>(ip) = std::make_shared<SubType>( ind.template get<0>() ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
inline size_t RPackNum<0>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
||||||
|
{
|
||||||
|
return std::get<0>(iPtrTup)->pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
inline size_t RPackNum<0>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
||||||
|
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
|
||||||
|
{
|
||||||
|
return std::get<0>(iPtrTup)->pos() * std::get<1>(blockSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Pack, class IndexType>
|
||||||
|
void RPackNum<0>::swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind)
|
||||||
|
{
|
||||||
|
std::get<std::tuple_size<Pack>::value-1>(ipack) = nind;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Pack, class... Indices>
|
||||||
|
void RPackNum<0>::swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds)
|
||||||
|
{
|
||||||
|
std::get<0>(ipack) = std::get<0>(ninds);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
size_t RPackNum<0>::blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<0>::RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
|
vector<std::intptr_t>& v)
|
||||||
|
{
|
||||||
|
v[0] = reinterpret_cast<std::intptr_t>( std::get<0>(rst).get() );;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<0>::RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
|
vector<std::shared_ptr<RangeBase> >& v)
|
||||||
|
{
|
||||||
|
setRangeToVec(v, std::get<0>(rst));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
void RPackNum<0>::printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset)
|
||||||
|
{
|
||||||
|
std::get<0>(ip)->print(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Range>
|
||||||
|
void RPackNum<0>::checkDefaultable()
|
||||||
|
{
|
||||||
|
static_assert( Range::defaultable, "not defaultable" );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto RPackNum<0>::mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||||
|
->ifor(0,exs) )
|
||||||
|
{
|
||||||
|
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
||||||
|
return std::get<NN>(ipack)
|
||||||
|
->ifor( step*std::get<NN+1>(ba), exs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto RPackNum<0>::mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||||
|
->iforh(0,exs) )
|
||||||
|
{
|
||||||
|
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
||||||
|
return std::get<NN>(ipack)
|
||||||
|
->iforh( step*std::get<NN+1>(ba), exs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto RPackNum<0>::mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||||
|
->pifor(0,exs) )
|
||||||
|
{
|
||||||
|
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
||||||
|
return std::get<NN>(ipack)
|
||||||
|
->pifor( step*std::get<NN+1>(ba), exs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline void RPackNum<0>::getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
||||||
|
{
|
||||||
|
//constexpr size_t DIM = Index::sDim();
|
||||||
|
const auto& ni = ii.template get<0>();
|
||||||
|
const size_t max = ni.max();
|
||||||
|
const size_t tmp = getStepSize(ni, j);
|
||||||
|
//ss += tmp * sx;
|
||||||
|
ss += tmp * ii.template getBlockSize<1>();
|
||||||
|
sx *= max;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class RangeTuple, typename... SIZET>
|
||||||
|
inline void RPackNum<0>::resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
|
RangeTuple& rtp, size_t off, size_t size)
|
||||||
|
{
|
||||||
|
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
||||||
|
resolveSetRange(std::get<tps-1>(rtp), orig, off, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
inline bool RPackNum<0>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
||||||
|
const vector<std::intptr_t>& a)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<std::intptr_t>( std::get<0>(p).get() ) == a[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class MIndex>
|
||||||
|
inline std::string RPackNum<0>::getStringMeta(const MIndex& mi)
|
||||||
|
{
|
||||||
|
return mi.template getPtr<0>()->stringMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<0>::fillRangeDataVec(vector<char>& out,
|
||||||
|
const std::tuple<std::shared_ptr<Ranges>...>& tp)
|
||||||
|
{
|
||||||
|
vector<char> part = std::get<sizeof...(Ranges)-1>(tp)->data();
|
||||||
|
out.insert(out.end(), part.begin(), part.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t SIZE, class Range>
|
||||||
|
inline bool RPackNum<0>::compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
|
||||||
|
{
|
||||||
|
return rbvec[SIZE-1]->spaceType() == Range::STYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<0>::setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
||||||
|
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<0>( stp ))>::type RType;
|
||||||
|
std::get<0>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[0] );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class MetaType, class... Ranges>
|
||||||
|
inline size_t RPackNum<0>::getCMeta(MetaType* xtarget, size_t pos,
|
||||||
|
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
||||||
|
{
|
||||||
|
//constexpr size_t NN = sizeof...(Ranges);
|
||||||
|
auto& r = *std::get<0>(stp);
|
||||||
|
const size_t ownPos = pos % r.size();
|
||||||
|
const size_t s = r.cmetaSize();
|
||||||
|
off -= s;
|
||||||
|
assert(off == 0);
|
||||||
|
r.cmeta(reinterpret_cast<char*>(&std::get<0>(*xtarget)), ownPos);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
inline size_t RPackNum<0>::getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
constexpr size_t NN = sizeof...(Ranges);
|
||||||
|
auto& r = *std::get<NN-1>(stp);
|
||||||
|
return r.cmetaSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
inline void RPackNum<0>::getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
auto& r = *std::get<0>(stp);
|
||||||
|
auto tn = r.typeNum();
|
||||||
|
res.insert(res.begin(), tn.begin(), tn.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <IndexType IT>
|
||||||
|
template <class Index>
|
||||||
|
inline size_t SSG<IT>::getStepSize(const Index& ii, std::intptr_t j)
|
||||||
|
{
|
||||||
|
size_t ss = 0;
|
||||||
|
size_t sx = 1;
|
||||||
|
constexpr size_t DIM = Index::sDim();
|
||||||
|
RPackNum<DIM-1>::getStepSizeX(ii, j, ss, sx);
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline size_t SSG<IndexType::SINGLE>::getStepSize(const Index& ii, std::intptr_t j)
|
||||||
|
{
|
||||||
|
const std::intptr_t ip = reinterpret_cast<std::intptr_t>(&ii);
|
||||||
|
return ip == j ? 1 : 0;
|
||||||
|
//return ii.ptrNum() == j ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
||||||
|
{
|
||||||
|
constexpr IndexType IT = Index::sType();
|
||||||
|
return SSG<IT>::getStepSize(ii, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace MultiArrayHelper
|
|
@ -15,16 +15,10 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
|
|
||||||
template <class Index1>
|
template <class Index1>
|
||||||
size_t mkTotalDim()
|
size_t mkTotalDim();
|
||||||
{
|
|
||||||
return Index1::totalDim();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index1, class Index2, class... Indices>
|
template <class Index1, class Index2, class... Indices>
|
||||||
size_t mkTotalDim()
|
size_t mkTotalDim();
|
||||||
{
|
|
||||||
return Index1::totalDim() * mkTotalDim<Index2,Indices...>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class RangeType, class... Ranges>
|
template <class RangeType, class... Ranges>
|
||||||
|
@ -47,358 +41,145 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
template <class Range>
|
template <class Range>
|
||||||
inline void resolveSetRange(std::shared_ptr<Range>& rp, const vector<std::shared_ptr<RangeBase> >& orig,
|
inline void resolveSetRange(std::shared_ptr<Range>& rp, const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
size_t origpos, size_t size)
|
size_t origpos, size_t size);
|
||||||
{
|
|
||||||
assert(size == 1);
|
|
||||||
rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!!
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Range>
|
template <class Range>
|
||||||
inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
|
inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
|
||||||
std::shared_ptr<Range> r)
|
std::shared_ptr<Range> r);
|
||||||
{
|
|
||||||
v.insert(v.begin(), r);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
struct RPackNum
|
struct RPackNum
|
||||||
{
|
{
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::tuple<std::shared_ptr<Indices>...>& ip)
|
std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||||
{
|
|
||||||
std::get<N>(bs) = RPackNum<sizeof...(Indices)-N>::blockSize(ip);
|
|
||||||
RPackNum<N-1>::initBlockSizes(bs, ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||||
{
|
|
||||||
auto& si = *std::get<N>(ip);
|
|
||||||
if(si.last()){
|
|
||||||
si = 0;
|
|
||||||
RPackNum<N-1>::pp(ip);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
++si;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::intptr_t idxPtrNum)
|
std::intptr_t idxPtrNum);
|
||||||
{
|
|
||||||
auto& siPtr = std::get<N>(ip);
|
|
||||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
|
||||||
return RPackNum<N-1>::pp(ip, bs, idxPtrNum);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int tmp = siPtr->pp(idxPtrNum);
|
|
||||||
if(siPtr->pos() == siPtr->max()){
|
|
||||||
(*siPtr) = 0;
|
|
||||||
return RPackNum<N-1>::pp(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return tmp * std::get<N+1>(bs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||||
{
|
|
||||||
auto& si = *std::get<N>(ip);
|
|
||||||
if(si.first()){
|
|
||||||
si = si.max() - 1;
|
|
||||||
RPackNum<N-1>::mm(ip);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
--si;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// !!!!
|
// !!!!
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::intptr_t idxPtrNum)
|
std::intptr_t idxPtrNum);
|
||||||
{
|
|
||||||
auto& siPtr = std::get<N>(ip);
|
|
||||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
|
||||||
return std::get<N>(bs) + RPackNum<N-1>::mm(ip, bs, idxPtrNum);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(siPtr->first()){
|
|
||||||
(*siPtr) = siPtr->max() - 1;
|
|
||||||
return RPackNum<N-1>::mm(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return siPtr->mm(idxPtrNum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class RangeTuple>
|
template <class RangeTuple>
|
||||||
static size_t getSize(const RangeTuple& rt)
|
static size_t getSize(const RangeTuple& rt);
|
||||||
{
|
|
||||||
return std::get<N>(rt)->size() * RPackNum<N-1>::getSize(rt);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class MetaType>
|
template <class IndexPack, class MetaType>
|
||||||
static void getMetaPos(MetaType& target,
|
static void getMetaPos(MetaType& target,
|
||||||
const IndexPack& source)
|
const IndexPack& source);
|
||||||
{
|
|
||||||
std::get<N>(target) = std::get<N>(source)->meta();
|
|
||||||
RPackNum<N-1>::getMetaPos(target, source);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, typename MetaType>
|
template <class IndexPack, typename MetaType>
|
||||||
static void setMeta(IndexPack& target, const MetaType& source)
|
static void setMeta(IndexPack& target, const MetaType& source);
|
||||||
{
|
|
||||||
std::get<N>(target)->at( std::get<N>(source) );
|
|
||||||
RPackNum<N-1>::setMeta(target, source);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class SpaceClass>
|
template <class SpaceClass>
|
||||||
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num)
|
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num);
|
||||||
{
|
|
||||||
if(num == N){
|
|
||||||
return std::get<N>(space);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return RPackNum<N-1>::getSub(space, num);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack>
|
template <class IndexPack>
|
||||||
static void setIndexPack(IndexPack& iPack, size_t pos)
|
static void setIndexPack(IndexPack& iPack, size_t pos);
|
||||||
{
|
|
||||||
auto& i = *std::get<N>(iPack).get();
|
|
||||||
const size_t ownPos = pos % i.max();
|
|
||||||
i = ownPos;
|
|
||||||
RPackNum<N-1>::setIndexPack(iPack, (pos - ownPos) / i.max() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MRange, class... Indices>
|
template <class MRange, class... Indices>
|
||||||
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
const MRange& range)
|
const MRange& range);
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(range.template get<N>())>::type SubRangeType;
|
|
||||||
typedef typename SubRangeType::IndexType SubIndexType;
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<N>(ip).get())>::type TypeFromIndexPack;
|
|
||||||
|
|
||||||
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
|
|
||||||
"inconsistent types");
|
|
||||||
|
|
||||||
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<N>() ) );
|
|
||||||
*std::get<N>(ip) = 0;
|
|
||||||
RPackNum<N-1>::construct(ip, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
template <class IndexType, class... Indices>
|
||||||
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
const IndexType& ind)
|
const IndexType& ind);
|
||||||
{
|
|
||||||
std::get<N>(ip) = ind.template getPtr<N>() ;
|
|
||||||
RPackNum<N-1>::copyInst(ip, ind);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
template <class IndexType, class... Indices>
|
||||||
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
const IndexType& ind)
|
const IndexType& ind);
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<N>(ip))>::type SubType;
|
|
||||||
std::get<N>(ip) = std::make_shared<SubType>( ind.template get<N>() ) ;
|
|
||||||
RPackNum<N-1>::copyIndex(ip, ind);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup);
|
||||||
{
|
|
||||||
//const auto& idx = *std::get<N>(iPtrTup);
|
|
||||||
return std::get<N>(iPtrTup)->pos() + RPackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
||||||
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
|
const std::array<size_t,sizeof...(Indices)+1>& blockSize);
|
||||||
{
|
|
||||||
return RPackNum<N-1>::makePos(iPtrTup, blockSize) + std::get<N>(iPtrTup)->pos() * std::get<N+1>(blockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Pack, class IndexType, class... Indices>
|
template <class Pack, class IndexType, class... Indices>
|
||||||
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind,
|
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind,
|
||||||
const std::shared_ptr<Indices>&... ninds)
|
const std::shared_ptr<Indices>&... ninds);
|
||||||
{
|
|
||||||
std::get<std::tuple_size<Pack>::value-N-1>(ipack) = nind;
|
|
||||||
RPackNum<N-1>::swapIndices(ipack, ninds...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Pack, class... Indices>
|
template <class Pack, class... Indices>
|
||||||
static void swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds)
|
static void swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds);
|
||||||
{
|
|
||||||
std::get<N>(ipack) = std::get<N>(ninds);
|
|
||||||
RPackNum<N-1>::swapIndices(ipack, ninds);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack);
|
||||||
{
|
|
||||||
return std::get<sizeof...(Indices)-N>(pack)->max() * RPackNum<N-1>::blockSize(pack);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
vector<std::shared_ptr<RangeBase> >& v)
|
vector<std::shared_ptr<RangeBase> >& v);
|
||||||
{
|
|
||||||
setRangeToVec(v, std::get<N>(rst));
|
|
||||||
RPackNum<N-1>::RangesToVec(rst, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
vector<std::intptr_t>& v)
|
vector<std::intptr_t>& v);
|
||||||
{
|
|
||||||
v[N] = reinterpret_cast<std::intptr_t>( std::get<N>(rst).get() );
|
|
||||||
RPackNum<N-1>::RangesToVec(rst, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static void printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset)
|
static void printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset);
|
||||||
{
|
|
||||||
std::get<N>(ip)->print(offset);
|
|
||||||
RPackNum<N-1>::printIndex(ip, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Range, class... Ranges>
|
template <class Range, class... Ranges>
|
||||||
static void checkDefaultable()
|
static void checkDefaultable();
|
||||||
{
|
|
||||||
static_assert( Range::defaultable, "not defaultable" );
|
|
||||||
RPackNum<N-1>::template checkDefaultable<Ranges...>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||||
->ifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) )
|
->ifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) );
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->ifor( step*std::get<NN+1>(ba), RPackNum<N-1>::mkFor(step, ipack, ba, exs) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||||
->iforh( 0, RPackNum<N-1>::mkForh(step, ipack, ba, exs) ) )
|
->iforh( 0, RPackNum<N-1>::mkForh(step, ipack, ba, exs) ) );
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->iforh( step*std::get<NN+1>(ba), RPackNum<N-1>::mkForh(step, ipack, ba, exs) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
static auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
static auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||||
->pifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) )
|
->pifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) );
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->pifor( step*std::get<NN+1>(ba), RPackNum<N-1>::mkFor(step, ipack, ba, exs) );
|
|
||||||
// mkFor is correct here, because we want to multithread only the FIRST index!!
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index>
|
template <class Index>
|
||||||
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx);
|
||||||
{
|
|
||||||
//constexpr size_t DIM = Index::sDim();
|
|
||||||
const auto& ni = ii.template get<N>();
|
|
||||||
const size_t max = ni.max();
|
|
||||||
const size_t tmp = getStepSize(ni, j);
|
|
||||||
//ss += tmp * sx;
|
|
||||||
ss += tmp * ii.template getBlockSize<N+1>();
|
|
||||||
sx *= max;
|
|
||||||
RPackNum<N-1>::getStepSizeX(ii, j, ss, sx);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class RangeTuple, typename... SIZET>
|
template <class RangeTuple, typename... SIZET>
|
||||||
static inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
static inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
RangeTuple& rtp, size_t off, size_t size, SIZET... sizes)
|
RangeTuple& rtp, size_t off, size_t size, SIZET... sizes);
|
||||||
{
|
|
||||||
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
|
||||||
resolveSetRange(std::get<tps-N-1>(rtp), orig, off, size);
|
|
||||||
RPackNum<N-1>::resolveRangeType(orig, rtp, off+size, sizes...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
||||||
const vector<std::intptr_t>& a)
|
const vector<std::intptr_t>& a);
|
||||||
{
|
|
||||||
return reinterpret_cast<std::intptr_t>( std::get<N>(p).get() ) == a[N] and
|
|
||||||
RPackNum<N-1>::checkIfCreated(p,a);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MIndex>
|
template <class MIndex>
|
||||||
static inline std::string getStringMeta(const MIndex& mi)
|
static inline std::string getStringMeta(const MIndex& mi);
|
||||||
{
|
|
||||||
return RPackNum<N-1>::getStringMeta(mi) + "," + mi.template getPtr<N>()->stringMeta();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void fillRangeDataVec(vector<char>& out,
|
static inline void fillRangeDataVec(vector<char>& out,
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& tp)
|
const std::tuple<std::shared_ptr<Ranges>...>& tp);
|
||||||
{
|
|
||||||
vector<char> part = std::get<sizeof...(Ranges)-N-1>(tp)->data();
|
|
||||||
out.insert(out.end(), part.begin(), part.end());
|
|
||||||
RPackNum<N-1>::fillRangeDataVec(out, tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t SIZE, class Range, class... Ranges>
|
template <size_t SIZE, class Range, class... Ranges>
|
||||||
static inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
|
static inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec);
|
||||||
{
|
|
||||||
return rbvec[SIZE-N-1]->spaceType() == Range::STYPE and RPackNum<N-1>::template compareSpaceTypes<SIZE,Ranges...>(rbvec);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
static inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
||||||
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
std::tuple<std::shared_ptr<Ranges>...>& stp);
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<N>( stp ))>::type RType;
|
|
||||||
std::get<N>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[N] );
|
|
||||||
RPackNum<N-1>::setSpace(rbvec, stp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MetaType, class... Ranges>
|
template <class MetaType, class... Ranges>
|
||||||
static inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
static inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off);
|
||||||
{
|
|
||||||
//constexpr size_t NN = sizeof...(Ranges);
|
|
||||||
auto& r = *std::get<N>(stp);
|
|
||||||
const size_t ownPos = pos % r.size();
|
|
||||||
const size_t s = r.cmetaSize();
|
|
||||||
off -= s;
|
|
||||||
r.cmeta(reinterpret_cast<char*>(&std::get<N>(*xtarget)), ownPos);
|
|
||||||
return s + RPackNum<N-1>::getCMeta(xtarget, (pos - ownPos) / r.size(), stp, off);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline size_t getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
static inline size_t getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp);
|
||||||
{
|
|
||||||
constexpr size_t NN = sizeof...(Ranges);
|
|
||||||
auto& r = *std::get<NN-N-1>(stp);
|
|
||||||
return r.cmetaSize() + RPackNum<N-1>::getCMetaSize(stp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
static inline void getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp);
|
||||||
{
|
|
||||||
auto& r = *std::get<N>(stp);
|
|
||||||
auto tn = r.typeNum();
|
|
||||||
res.insert(res.begin(), tn.begin(), tn.end());
|
|
||||||
RPackNum<N-1>::getTypeNum(res, stp);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -408,295 +189,131 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::tuple<std::shared_ptr<Indices>...>& ip)
|
std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||||
{
|
|
||||||
std::get<0>(bs) = RPackNum<sizeof...(Indices)>::blockSize(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||||
{
|
|
||||||
auto& si = *std::get<0>(ip);
|
|
||||||
++si;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::intptr_t idxPtrNum)
|
std::intptr_t idxPtrNum);
|
||||||
{
|
|
||||||
auto& siPtr = std::get<0>(ip);
|
|
||||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
|
||||||
return std::get<0>(bs);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int tmp = siPtr->pp(idxPtrNum);
|
|
||||||
return tmp * std::get<1>(bs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip);
|
||||||
{
|
|
||||||
auto& si = *std::get<0>(ip);
|
|
||||||
--si;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::intptr_t idxPtrNum)
|
std::intptr_t idxPtrNum);
|
||||||
{
|
|
||||||
auto& siPtr = std::get<0>(ip);
|
|
||||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
|
||||||
return std::get<0>(bs);
|
|
||||||
//return 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return siPtr->mm(idxPtrNum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class RangeTuple>
|
template <class RangeTuple>
|
||||||
static size_t getSize(const RangeTuple& rt)
|
static size_t getSize(const RangeTuple& rt);
|
||||||
{
|
|
||||||
return std::get<0>(rt)->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class MetaType>
|
template <class IndexPack, class MetaType>
|
||||||
static void getMetaPos(MetaType& target,
|
static void getMetaPos(MetaType& target,
|
||||||
const IndexPack& source)
|
const IndexPack& source);
|
||||||
{
|
|
||||||
std::get<0>(target) = std::get<0>(source)->meta();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, typename MetaType>
|
template <class IndexPack, typename MetaType>
|
||||||
static void setMeta(IndexPack& target, const MetaType& source)
|
static void setMeta(IndexPack& target, const MetaType& source);
|
||||||
{
|
|
||||||
std::get<0>(target)->at( std::get<0>( source ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class SpaceClass>
|
template <class SpaceClass>
|
||||||
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num)
|
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num);
|
||||||
{
|
|
||||||
if(num == 0){
|
|
||||||
return std::get<0>(space);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assert(0);
|
|
||||||
return std::shared_ptr<RangeBase>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack>
|
template <class IndexPack>
|
||||||
static void setIndexPack(IndexPack& iPack, size_t pos)
|
static void setIndexPack(IndexPack& iPack, size_t pos);
|
||||||
{
|
|
||||||
auto& i = *std::get<0>(iPack);
|
|
||||||
const size_t ownPos = pos % i.max();
|
|
||||||
i = ownPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MRange, class... Indices>
|
template <class MRange, class... Indices>
|
||||||
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
const MRange& range)
|
const MRange& range);
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(range.template get<0>())>::type SubRangeType;
|
|
||||||
typedef typename SubRangeType::IndexType SubIndexType;
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<0>(ip).get())>::type TypeFromIndexPack;
|
|
||||||
|
|
||||||
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
|
|
||||||
"inconsistent types");
|
|
||||||
|
|
||||||
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<0>() ) );
|
|
||||||
*std::get<0>(ip) = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
template <class IndexType, class... Indices>
|
||||||
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
const IndexType& ind)
|
const IndexType& ind);
|
||||||
{
|
|
||||||
std::get<0>(ip) = ind.template getPtr<0>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
template <class IndexType, class... Indices>
|
||||||
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
const IndexType& ind)
|
const IndexType& ind);
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<0>(ip))>::type SubType;
|
|
||||||
std::get<0>(ip) = std::make_shared<SubType>( ind.template get<0>() ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup);
|
||||||
{
|
|
||||||
return std::get<0>(iPtrTup)->pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
||||||
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
|
const std::array<size_t,sizeof...(Indices)+1>& blockSize);
|
||||||
{
|
|
||||||
return std::get<0>(iPtrTup)->pos() * std::get<1>(blockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Pack, class IndexType>
|
template <class Pack, class IndexType>
|
||||||
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind)
|
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind);
|
||||||
{
|
|
||||||
std::get<std::tuple_size<Pack>::value-1>(ipack) = nind;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Pack, class... Indices>
|
template <class Pack, class... Indices>
|
||||||
static void swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds)
|
static void swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds);
|
||||||
{
|
|
||||||
std::get<0>(ipack) = std::get<0>(ninds);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack);
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
vector<std::intptr_t>& v)
|
vector<std::intptr_t>& v);
|
||||||
{
|
|
||||||
v[0] = reinterpret_cast<std::intptr_t>( std::get<0>(rst).get() );;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
||||||
vector<std::shared_ptr<RangeBase> >& v)
|
vector<std::shared_ptr<RangeBase> >& v);
|
||||||
{
|
|
||||||
setRangeToVec(v, std::get<0>(rst));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static void printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset)
|
static void printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset);
|
||||||
{
|
|
||||||
std::get<0>(ip)->print(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Range>
|
template <class Range>
|
||||||
static void checkDefaultable()
|
static void checkDefaultable();
|
||||||
{
|
|
||||||
static_assert( Range::defaultable, "not defaultable" );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||||
->ifor(0,exs) )
|
->ifor(0,exs) );
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->ifor( step*std::get<NN+1>(ba), exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||||
->iforh(0,exs) )
|
->iforh(0,exs) );
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->iforh( step*std::get<NN+1>(ba), exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
template <class IndexPack, class BlockArray, class Exprs>
|
||||||
static auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
static auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||||
->pifor(0,exs) )
|
->pifor(0,exs) );
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->pifor( step*std::get<NN+1>(ba), exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index>
|
template <class Index>
|
||||||
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx);
|
||||||
{
|
|
||||||
//constexpr size_t DIM = Index::sDim();
|
|
||||||
const auto& ni = ii.template get<0>();
|
|
||||||
const size_t max = ni.max();
|
|
||||||
const size_t tmp = getStepSize(ni, j);
|
|
||||||
//ss += tmp * sx;
|
|
||||||
ss += tmp * ii.template getBlockSize<1>();
|
|
||||||
sx *= max;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class RangeTuple, typename... SIZET>
|
template <class RangeTuple, typename... SIZET>
|
||||||
static inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
static inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
RangeTuple& rtp, size_t off, size_t size)
|
RangeTuple& rtp, size_t off, size_t size);
|
||||||
{
|
|
||||||
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
|
||||||
resolveSetRange(std::get<tps-1>(rtp), orig, off, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
||||||
const vector<std::intptr_t>& a)
|
const vector<std::intptr_t>& a);
|
||||||
{
|
|
||||||
return reinterpret_cast<std::intptr_t>( std::get<0>(p).get() ) == a[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MIndex>
|
template <class MIndex>
|
||||||
static inline std::string getStringMeta(const MIndex& mi)
|
static inline std::string getStringMeta(const MIndex& mi);
|
||||||
{
|
|
||||||
return mi.template getPtr<0>()->stringMeta();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void fillRangeDataVec(vector<char>& out,
|
static inline void fillRangeDataVec(vector<char>& out,
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& tp)
|
const std::tuple<std::shared_ptr<Ranges>...>& tp);
|
||||||
{
|
|
||||||
vector<char> part = std::get<sizeof...(Ranges)-1>(tp)->data();
|
|
||||||
out.insert(out.end(), part.begin(), part.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t SIZE, class Range>
|
template <size_t SIZE, class Range>
|
||||||
static inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
|
static inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec);
|
||||||
{
|
|
||||||
return rbvec[SIZE-1]->spaceType() == Range::STYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
static inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
||||||
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
std::tuple<std::shared_ptr<Ranges>...>& stp);
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<0>( stp ))>::type RType;
|
|
||||||
std::get<0>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[0] );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MetaType, class... Ranges>
|
template <class MetaType, class... Ranges>
|
||||||
static inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
static inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off);
|
||||||
{
|
|
||||||
//constexpr size_t NN = sizeof...(Ranges);
|
|
||||||
auto& r = *std::get<0>(stp);
|
|
||||||
const size_t ownPos = pos % r.size();
|
|
||||||
const size_t s = r.cmetaSize();
|
|
||||||
off -= s;
|
|
||||||
assert(off == 0);
|
|
||||||
r.cmeta(reinterpret_cast<char*>(&std::get<0>(*xtarget)), ownPos);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline size_t getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
static inline size_t getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp);
|
||||||
{
|
|
||||||
constexpr size_t NN = sizeof...(Ranges);
|
|
||||||
auto& r = *std::get<NN-1>(stp);
|
|
||||||
return r.cmetaSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
static inline void getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
static inline void getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp);
|
||||||
{
|
|
||||||
auto& r = *std::get<0>(stp);
|
|
||||||
auto tn = r.typeNum();
|
|
||||||
res.insert(res.begin(), tn.begin(), tn.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -704,35 +321,19 @@ namespace MultiArrayHelper
|
||||||
struct SSG
|
struct SSG
|
||||||
{
|
{
|
||||||
template <class Index>
|
template <class Index>
|
||||||
static inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
static inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
||||||
{
|
|
||||||
size_t ss = 0;
|
|
||||||
size_t sx = 1;
|
|
||||||
constexpr size_t DIM = Index::sDim();
|
|
||||||
RPackNum<DIM-1>::getStepSizeX(ii, j, ss, sx);
|
|
||||||
return ss;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct SSG<IndexType::SINGLE>
|
struct SSG<IndexType::SINGLE>
|
||||||
{
|
{
|
||||||
template <class Index>
|
template <class Index>
|
||||||
static inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
static inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
||||||
{
|
|
||||||
const std::intptr_t ip = reinterpret_cast<std::intptr_t>(&ii);
|
|
||||||
return ip == j ? 1 : 0;
|
|
||||||
//return ii.ptrNum() == j ? 1 : 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
|
||||||
{
|
|
||||||
constexpr IndexType IT = Index::sType();
|
|
||||||
return SSG<IT>::getStepSize(ii, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
} // end namespace MultiArrayHelper
|
||||||
|
|
||||||
|
//#include "rpack_num.cc.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "ranges/anonymous_range.h"
|
#include "ranges/anonymous_range.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ranges/dynamic_meta.h"
|
#include "ranges/dynamic_meta.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "ranges/dynamic_range.h"
|
#include "ranges/dynamic_range.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "ranges/multi_range_factory_product_map.h"
|
#include "ranges/multi_range_factory_product_map.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "ranges/range_types/header.h"
|
#include "ranges/range_types/header.h"
|
||||||
|
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
#include "ranges/rheader.h"
|
#include "ranges/rheader.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
#include "ranges/rheader.h"
|
#include "ranges/rheader.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
#include "ranges/rheader.h"
|
#include "ranges/rheader.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
#include "ranges/rheader.h"
|
#include "ranges/rheader.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "ranges/type_map.h"
|
#include "ranges/type_map.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "ranges/rheader.h"
|
#include "ranges/rheader.h"
|
||||||
#include "multi_array_header.h"
|
#include "multi_array_header.h"
|
||||||
|
//#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MAT = MultiArrayTools;
|
namespace MAT = MultiArrayTools;
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
|
|
||||||
#include "ranges/rheader.h"
|
#include "ranges/rheader.h"
|
||||||
//#include "expressions.h"
|
//#include "expressions.h"
|
||||||
#include "ranges/dynamic_range.cc.h"
|
//#include "ranges/dynamic_range.cc.h"
|
||||||
//#include "multi_array_header.h"
|
//#include "multi_array_header.h"
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MAT = MultiArrayTools;
|
namespace MAT = MultiArrayTools;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue