start removing virtualities in Index*; intr VIWB for flexible use instead; Missing reg this: Multi/ContainerIndex, PackNum, OpClasses (NOT COMPILABLE)
This commit is contained in:
parent
1b251e5867
commit
defa568c5b
5 changed files with 207 additions and 162 deletions
177
src/index_base.h
177
src/index_base.h
|
@ -10,7 +10,6 @@
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
#include "range_base.h"
|
#include "range_base.h"
|
||||||
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
size_t indexId()
|
size_t indexId()
|
||||||
|
@ -26,66 +25,112 @@ namespace MultiArrayTools
|
||||||
CONT = 2
|
CONT = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
class IndexBase
|
class VirtualIndexWrapperBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//DEFAULT_MEMBERS(IndexBase);
|
DEFAULT_MEMBERS(VirtualIndexWrapperBase);
|
||||||
|
|
||||||
IndexBase() { mId = indexId(); }
|
|
||||||
IndexBase(IndexBase&& in) = default;
|
|
||||||
IndexBase& operator=(IndexBase&& in) = default;
|
|
||||||
|
|
||||||
IndexBase(const std::shared_ptr<RangeBase>& range, size_t pos);
|
|
||||||
virtual ~IndexBase() = default;
|
|
||||||
|
|
||||||
virtual IndexType type() const = 0;
|
virtual IndexType type() const = 0;
|
||||||
|
|
||||||
virtual IndexBase& operator=(size_t pos) = 0;
|
|
||||||
virtual IndexBase& operator++() = 0;
|
|
||||||
virtual IndexBase& operator--() = 0;
|
|
||||||
|
|
||||||
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) = 0;
|
|
||||||
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) = 0;
|
|
||||||
|
|
||||||
bool operator==(const IndexBase& in) const;
|
|
||||||
bool operator!=(const IndexBase& in) const;
|
|
||||||
|
|
||||||
virtual size_t dim() const = 0;
|
virtual size_t dim() const = 0;
|
||||||
virtual size_t pos() const;
|
virtual size_t pos() const = 0;
|
||||||
virtual size_t max() const;
|
virtual size_t max() const = 0;
|
||||||
|
virtual std::shared_ptr<RangeBase> rangePtr() const = 0;
|
||||||
|
virtual VirtualIndexWrapperBase getPtr(size_t n) const = 0;
|
||||||
|
virtual intptr_t getPtrNum() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
virtual bool last() const = 0;
|
typedef VirtualIndexWrapperBase VIWB;
|
||||||
virtual bool first() const = 0;
|
|
||||||
|
|
||||||
//virtual bool locked() const;
|
template <class I>
|
||||||
//virtual IndexBase& lock(std::shared_ptr<IndexBase>& idx);
|
std::shared_ptr<IndexWrapper<I> > make_viwb(std::shared_ptr<I> idxPtr)
|
||||||
|
{
|
||||||
|
return std::make_shared<IndexWrapper<I> >(idxPtr);
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::shared_ptr<RangeBase> rangePtr() const;
|
template <class I>
|
||||||
virtual std::shared_ptr<IndexBase> getPtr(size_t n) const = 0;
|
std::shared_ptr<IndexWrapper<I> > make_viwb(const I& idxPtr)
|
||||||
|
{
|
||||||
|
return make_viwb( std::make_shared<I>(idxPtr) );
|
||||||
|
}
|
||||||
|
|
||||||
virtual size_t getStepSize(size_t n) const = 0;
|
template <class I>
|
||||||
|
class IndexWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
virtual operator size_t() const;
|
DEFAULT_MEMBERS(IndexWrapper);
|
||||||
|
|
||||||
|
IndexWrapper(std::shared_ptr<I>& idxPtr);
|
||||||
|
|
||||||
|
virtual IndexType type() const override { return mIdxPtr->type(); }
|
||||||
|
virtual size_t dim() const override { return mIdxPtr->dim(); }
|
||||||
|
virtual size_t pos() const override { return mIdxPtr->pos(); }
|
||||||
|
virtual size_t max() const override { return mIdxPtr->max(); }
|
||||||
|
virtual std::shared_ptr<RangeBase> rangePtr() const override { return mIdxPtr->rangePtr(); }
|
||||||
|
virtual std::shared_ptr<VirtualIndexWrapperBase> getPtr(size_t n) const override { return mIdxPtr->getv(n); }
|
||||||
|
virtual intptr_t getPtrNum() const override { return static_cast<intptr_t>( mIdxPtr.get() ); };
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<I> mIdxPtr;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class I, typename MetaType>
|
||||||
|
class IndexInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//DEFAULT_MEMBERS(IndexInterface);
|
||||||
|
|
||||||
|
I* THIS() { return static_cast<I*>(this); }
|
||||||
|
|
||||||
|
~IndexInterface() = default;
|
||||||
|
|
||||||
|
IndexType type() const { return I::S_type(THIS()); }
|
||||||
|
|
||||||
|
IndexInterface& operator=(size_t pos) { return I::S_ass_op(THIS(), pos); }
|
||||||
|
IndexInterface& operator++() { return I::S_pp_op(THIS()); }
|
||||||
|
IndexInterface& operator--() { return I::S_mm_op(THIS()); }
|
||||||
|
|
||||||
|
int pp(std::shared_ptr<IndexInterface>& idxPtr) { return I::S_pp(THIS()); }
|
||||||
|
int mm(std::shared_ptr<IndexInterface>& idxPtr) { return I::S_mm(THIS()); }
|
||||||
|
|
||||||
|
bool operator==(const IndexInterface& in) const;
|
||||||
|
bool operator!=(const IndexInterface& in) const;
|
||||||
|
|
||||||
|
size_t dim() const { return I::S_dim(THIS()); }
|
||||||
|
size_t pos() const;
|
||||||
|
size_t max() const;
|
||||||
|
|
||||||
|
bool last() const { return I::S_last(THIS()); }
|
||||||
|
bool first() const { return I::S_first(THIS()); }
|
||||||
|
|
||||||
|
std::shared_ptr<RangeBase> rangePtr() const;
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
auto getPtr() const -> decltype(I::S_get<N>(THIS())) { return I::S_get<N>(THIS()); }
|
||||||
|
|
||||||
|
std::shared_ptr<VIWB> getVPtr(size_t n) const { return I::S_getVPtr(THIS(),n); }
|
||||||
|
|
||||||
|
size_t getStepSize(size_t n) const { return I::S_getStepSize(THIS(),n); }
|
||||||
|
|
||||||
|
operator size_t() const;
|
||||||
|
|
||||||
|
std::string id() const { return I::S_id(THIS()); }
|
||||||
|
|
||||||
|
MetaType meta() const { return I::S_meta(THIS()); }
|
||||||
|
IndexInterface& at(const MetaType& meta) { return I::S_at(THIS(), meta); }
|
||||||
|
|
||||||
virtual std::string id() const { return std::to_string( mId ); }
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
IndexInterface() { mId = indexId(); }
|
||||||
|
IndexInterface(IndexInterface&& in) = default;
|
||||||
|
IndexInterface& operator=(IndexInterface&& in) = default;
|
||||||
|
|
||||||
|
IndexInterface(const std::shared_ptr<RangeBase>& range, size_t pos);
|
||||||
|
|
||||||
std::shared_ptr<RangeBase> mRangePtr;
|
std::shared_ptr<RangeBase> mRangePtr;
|
||||||
size_t mPos;
|
size_t mPos;
|
||||||
size_t mId;
|
size_t mId;
|
||||||
//bool mLocked = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename MetaType>
|
|
||||||
class IndexInterface : public IndexBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
DEFAULT_MEMBERS(IndexInterface);
|
|
||||||
|
|
||||||
IndexInterface(const std::shared_ptr<RangeBase>& rangePtr, size_t pos);
|
|
||||||
virtual MetaType meta() const = 0;
|
|
||||||
virtual IndexInterface& at(const MetaType& meta) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -97,66 +142,52 @@ namespace MultiArrayTools
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
/*****************
|
/*****************
|
||||||
* IndexBase *
|
* IndexInterface *
|
||||||
*****************/
|
*****************/
|
||||||
|
|
||||||
IndexBase::IndexBase(const std::shared_ptr<RangeBase>& range,
|
template <class I, typename MetaType>
|
||||||
|
IndexInterface<I,MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& range,
|
||||||
size_t pos) : mRangePtr(range),
|
size_t pos) : mRangePtr(range),
|
||||||
mPos(pos)
|
mPos(pos)
|
||||||
{
|
{
|
||||||
mId = indexId();
|
mId = indexId();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IndexBase::operator==(const IndexBase& in) const
|
template <class I, typename MetaType>
|
||||||
|
bool IndexInterface<I,MetaType>::operator==(const IndexInterface& in) const
|
||||||
{
|
{
|
||||||
return in.mPos == mPos and in.mRangePtr.get() == mRangePtr.get();
|
return in.mPos == mPos and in.mRangePtr.get() == mRangePtr.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IndexBase::operator!=(const IndexBase& in) const
|
template <class I, typename MetaType>
|
||||||
|
bool IndexInterface<I,MetaType>::operator!=(const IndexInterface& in) const
|
||||||
{
|
{
|
||||||
return in.mPos != mPos or in.mRangePtr.get() != mRangePtr.get();
|
return in.mPos != mPos or in.mRangePtr.get() != mRangePtr.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IndexBase::pos() const
|
template <class I, typename MetaType>
|
||||||
|
size_t IndexInterface<I,MetaType>::pos() const
|
||||||
{
|
{
|
||||||
return mPos;
|
return mPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IndexBase::max() const
|
template <class I, typename MetaType>
|
||||||
|
size_t IndexInterface<I,MetaType>::max() const
|
||||||
{
|
{
|
||||||
return mRangePtr->size();
|
return mRangePtr->size();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
bool IndexBase::locked() const
|
|
||||||
{
|
|
||||||
return mLocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
IndexBase& IndexBase::lock(std::shared_ptr<IndexBase>& idx)
|
template <class I, typename MetaType>
|
||||||
{
|
std::shared_ptr<RangeBase> IndexInterface<I,MetaType>::rangePtr() const
|
||||||
mLocked = (idx.get() == this);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
std::shared_ptr<RangeBase> IndexBase::rangePtr() const
|
|
||||||
{
|
{
|
||||||
return mRangePtr;
|
return mRangePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexBase::operator size_t() const
|
template <class I, typename MetaType>
|
||||||
|
IndexInterface<I,MetaType>::operator size_t() const
|
||||||
{
|
{
|
||||||
return pos();
|
return pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
|
||||||
* IndexInterface *
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
template <typename MetaType>
|
|
||||||
IndexInterface<MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& rangePtr, size_t pos) :
|
|
||||||
IndexBase(rangePtr, pos) {}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,14 +32,14 @@ namespace MultiArrayTools
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void seekIndexInst(std::shared_ptr<IndexBase> i, std::vector<std::shared_ptr<IndexBase> >& ivec);
|
void seekIndexInst(std::shared_ptr<VIWB> i, std::vector<std::shared_ptr<VIWB> >& ivec);
|
||||||
|
|
||||||
|
|
||||||
// <block type, step size within actual instance>
|
// <block type, step size within actual instance>
|
||||||
typedef std::pair<BlockType,size_t> BTSS;
|
typedef std::pair<BlockType,size_t> BTSS;
|
||||||
|
|
||||||
BTSS getBlockType(std::shared_ptr<IndexBase> i,
|
BTSS getBlockType(std::shared_ptr<VIWB> i,
|
||||||
std::shared_ptr<IndexBase> j,
|
std::shared_ptr<VIWB> j,
|
||||||
bool first, size_t higherStepSize = 1);
|
bool first, size_t higherStepSize = 1);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -50,11 +50,11 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt);
|
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt);
|
||||||
|
|
||||||
void minimizeAppearanceOfType(std::map<std::shared_ptr<IndexBase>, std::vector<BTSS> >& mp,
|
void minimizeAppearanceOfType(std::map<std::shared_ptr<VIWB>, std::vector<BTSS> >& mp,
|
||||||
BlockType bt);
|
BlockType bt);
|
||||||
|
|
||||||
template <class OpClass>
|
template <class OpClass>
|
||||||
std::shared_ptr<IndexBase> seekBlockIndex(std::shared_ptr<IndexBase> ownIdx,
|
std::shared_ptr<VIWB> seekBlockIndex(std::shared_ptr<VIWB> ownIdx,
|
||||||
const OpClass& second);
|
const OpClass& second);
|
||||||
/*
|
/*
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -133,7 +133,7 @@ namespace MultiArrayTools
|
||||||
MBlock<T>& get();
|
MBlock<T>& get();
|
||||||
const Block<T>& get() const;
|
const Block<T>& get() const;
|
||||||
|
|
||||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex) const;
|
||||||
const OperationMaster& block() const;
|
const OperationMaster& block() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -163,7 +163,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
const Block<T>& get() const;
|
const Block<T>& get() const;
|
||||||
|
|
||||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex) const;
|
||||||
const ConstOperationRoot& block() const;
|
const ConstOperationRoot& block() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -194,7 +194,7 @@ namespace MultiArrayTools
|
||||||
const MBlock<T>& get() const;
|
const MBlock<T>& get() const;
|
||||||
MBlock<T>& get();
|
MBlock<T>& get();
|
||||||
|
|
||||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex) const;
|
||||||
const OperationRoot& block() const;
|
const OperationRoot& block() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -219,7 +219,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
const BlockResult<T>& get() const;
|
const BlockResult<T>& get() const;
|
||||||
|
|
||||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex) const;
|
||||||
const Operation& block() const;
|
const Operation& block() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -239,7 +239,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
const BlockResult<T>& get() const;
|
const BlockResult<T>& get() const;
|
||||||
|
|
||||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex) const;
|
||||||
const Contraction& block() const;
|
const Contraction& block() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -262,7 +262,7 @@ namespace MultiArrayTools
|
||||||
using namespace MultiArrayHelper;
|
using namespace MultiArrayHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
void seekIndexInst(std::shared_ptr<IndexBase> i, std::vector<std::shared_ptr<IndexBase> >& ivec)
|
void seekIndexInst(std::shared_ptr<VIWB> i, std::vector<std::shared_ptr<VIWB> >& ivec)
|
||||||
{
|
{
|
||||||
for(size_t inum = 0; inum != i->rangePtr()->dim(); ++inum){
|
for(size_t inum = 0; inum != i->rangePtr()->dim(); ++inum){
|
||||||
auto ii = i->getPtr(inum);
|
auto ii = i->getPtr(inum);
|
||||||
|
@ -274,8 +274,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BTSS getBlockType(std::shared_ptr<IndexBase> i,
|
BTSS getBlockType(std::shared_ptr<VIWB> i,
|
||||||
std::shared_ptr<IndexBase> j,
|
std::shared_ptr<VIWB> j,
|
||||||
bool first, size_t higherStepSize)
|
bool first, size_t higherStepSize)
|
||||||
{
|
{
|
||||||
// returning BlockType and step size is redundant (change in the future)
|
// returning BlockType and step size is redundant (change in the future)
|
||||||
|
@ -440,11 +440,12 @@ namespace MultiArrayTools
|
||||||
(*mIndex) = *index;
|
(*mIndex) = *index;
|
||||||
|
|
||||||
auto blockIndex = seekBlockIndex( mIndex, second);
|
auto blockIndex = seekBlockIndex( mIndex, second);
|
||||||
|
intptr_t blockIndexNum = blockIndex->getPtrNum();
|
||||||
|
|
||||||
block(blockIndex);
|
block(blockIndex);
|
||||||
second.block(blockIndex);
|
second.block(blockIndex);
|
||||||
|
|
||||||
for(*mIndex = 0; mIndex->pos() != mIndex->max(); mIndex->pp(blockIndex) ){
|
for(*mIndex = 0; mIndex->pos() != mIndex->max(); mIndex->pp(blockIndexNum) ){
|
||||||
get() = mSecond.get();
|
get() = mSecond.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,16 +21,16 @@ namespace MultiArrayHelper
|
||||||
struct PackNum
|
struct PackNum
|
||||||
{
|
{
|
||||||
template <class IndexType>
|
template <class IndexType>
|
||||||
static IndexBase& getIndex(IndexType& in, size_t n)
|
static std::shared_ptr<VIWB> getIndex(const IndexType& in, size_t n)
|
||||||
{
|
{
|
||||||
if(n == N){
|
if(n == N){
|
||||||
return in.template get<N>();
|
return make_viwb( in.template get<N>() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return PackNum<N-1>::getIndex(in, n);
|
return PackNum<N-1>::getIndex(in, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
template <class IndexType>
|
template <class IndexType>
|
||||||
static const IndexBase& getIndex(const IndexType& in, size_t n)
|
static const IndexBase& getIndex(const IndexType& in, size_t n)
|
||||||
{
|
{
|
||||||
|
@ -40,19 +40,19 @@ namespace MultiArrayHelper
|
||||||
else {
|
else {
|
||||||
return PackNum<N-1>::getIndex(in, n);
|
return PackNum<N-1>::getIndex(in, n);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
template <class IndexType>
|
template <class IndexType>
|
||||||
static std::shared_ptr<IndexBase> getIndexPtr(const IndexType& in, size_t n)
|
static std::shared_ptr<VIWB> getIndexPtr(const IndexType& in, size_t n)
|
||||||
{
|
{
|
||||||
if(n == N){
|
if(n == N){
|
||||||
return in.template getPtr<N>();
|
return make_viwb( in.template getPtr<N>() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return PackNum<N-1>::getIndexPtr(in, n);
|
return PackNum<N-1>::getIndexPtr(in, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static void lock(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static void lock(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::shared_ptr<IndexBase> toLock)
|
std::shared_ptr<IndexBase> toLock)
|
||||||
|
@ -60,7 +60,7 @@ namespace MultiArrayHelper
|
||||||
std::get<N>(ip)->lock(toLock);
|
std::get<N>(ip)->lock(toLock);
|
||||||
PackNum<N-1>::lock(ip, toLock);
|
PackNum<N-1>::lock(ip, toLock);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
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)
|
||||||
|
@ -85,18 +85,18 @@ namespace MultiArrayHelper
|
||||||
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::shared_ptr<IndexBase> idxPtr)
|
intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
auto& siPtr = std::get<N>(ip);
|
auto& siPtr = std::get<N>(ip);
|
||||||
//VCHECK(siPtr.id());
|
//VCHECK(siPtr.id());
|
||||||
if(siPtr.get() == idxPtr.get()){
|
if(static_cast<intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
return PackNum<N-1>::pp(ip, bs, idxPtr);
|
return PackNum<N-1>::pp(ip, bs, idxPtrNum;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int tmp = siPtr->pp(idxPtr);
|
int tmp = siPtr->pp(idxPtr);
|
||||||
if(siPtr->pos() == siPtr->max()){
|
if(siPtr->pos() == siPtr->max()){
|
||||||
(*siPtr) = 0;
|
(*siPtr) = 0;
|
||||||
return PackNum<N-1>::pp(ip, bs, idxPtr) - siPtr->max() + 1;
|
return PackNum<N-1>::pp(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return tmp * std::get<N+1>(bs);
|
return tmp * std::get<N+1>(bs);
|
||||||
|
@ -117,22 +117,23 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !!!!
|
||||||
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::shared_ptr<IndexBase> idxPtr)
|
intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
auto& siPtr = std::get<N>(ip);
|
auto& siPtr = std::get<N>(ip);
|
||||||
if(siPtr.get() == idxPtr.get()){
|
if(static_cast<intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
return std::get<N>(bs) + PackNum<N-1>::mm(ip, bs, idxPtr);
|
return std::get<N>(bs) + PackNum<N-1>::mm(ip, bs, idxPtrNum);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(siPtr->first()){
|
if(siPtr->first()){
|
||||||
(*siPtr) = siPtr->max() - 1;
|
(*siPtr) = siPtr->max() - 1;
|
||||||
return PackNum<N-1>::mm(ip, bs, idxPtr) - siPtr->max() + 1;
|
return PackNum<N-1>::mm(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return siPtr->mm(idxPtr);
|
return siPtr->mm(idxPtrNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,31 +258,31 @@ namespace MultiArrayHelper
|
||||||
template<>
|
template<>
|
||||||
struct PackNum<0>
|
struct PackNum<0>
|
||||||
{
|
{
|
||||||
template <class MultiIndex>
|
template <class IndexType>
|
||||||
static IndexBase& getIndex(MultiIndex& in, size_t n)
|
static std::shared_ptr<VIWB> getIndex(const IndexType& in, size_t n)
|
||||||
{
|
{
|
||||||
return in.template get<0>();
|
return make_viwb( in.template get<0>() );
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
template <class MultiIndex>
|
template <class MultiIndex>
|
||||||
static const IndexBase& getIndex(const MultiIndex& in, size_t n)
|
static const IndexBase& getIndex(const MultiIndex& in, size_t n)
|
||||||
{
|
{
|
||||||
return in.template get<0>();
|
return in.template get<0>();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
template <class IndexType>
|
template <class IndexType>
|
||||||
static std::shared_ptr<IndexBase> getIndexPtr(const IndexType& in, size_t n)
|
static std::shared_ptr<IndexBase> getIndexPtr(const IndexType& in, size_t n)
|
||||||
{
|
{
|
||||||
return in.template getPtr<0>();
|
return make_viwb( in.template get<0>() );
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static void lock(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static void lock(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::shared_ptr<IndexBase> toLock)
|
std::shared_ptr<IndexBase> toLock)
|
||||||
{
|
{
|
||||||
std::get<0>(ip)->lock(toLock);
|
std::get<0>(ip)->lock(toLock);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
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)
|
||||||
|
@ -299,14 +300,14 @@ namespace MultiArrayHelper
|
||||||
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::shared_ptr<IndexBase> idxPtr)
|
intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
auto& siPtr = std::get<0>(ip);
|
auto& siPtr = std::get<0>(ip);
|
||||||
if(siPtr.get() == idxPtr.get()){
|
if(static_cast<intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
return std::get<0>(bs);
|
return std::get<0>(bs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int tmp = siPtr->pp(idxPtr);
|
int tmp = siPtr->pp(idxPtrNum);
|
||||||
return tmp * std::get<1>(bs);
|
return tmp * std::get<1>(bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,15 +322,15 @@ namespace MultiArrayHelper
|
||||||
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::shared_ptr<IndexBase> idxPtr)
|
intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
auto& siPtr = std::get<0>(ip);
|
auto& siPtr = std::get<0>(ip);
|
||||||
if(siPtr.get() == idxPtr.get()){
|
if(static_cast<intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
return std::get<0>(bs);
|
return std::get<0>(bs);
|
||||||
//return 1;
|
//return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return siPtr->mm(idxPtr);
|
return siPtr->mm(idxPtrNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace MultiArrayTools
|
||||||
virtual size_t size() const = 0;
|
virtual size_t size() const = 0;
|
||||||
virtual size_t dim() const = 0;
|
virtual size_t dim() const = 0;
|
||||||
|
|
||||||
virtual std::shared_ptr<IndexBase> index() const = 0;
|
virtual std::shared_ptr<VIWB> index() const = 0;
|
||||||
|
|
||||||
bool operator==(const RangeBase& in) const;
|
bool operator==(const RangeBase& in) const;
|
||||||
bool operator!=(const RangeBase& in) const;
|
bool operator!=(const RangeBase& in) const;
|
||||||
|
|
|
@ -15,11 +15,11 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
class SingleIndex : public IndexInterface<U>
|
class SingleIndex : public IndexInterface<SingleIndex<U,TYPE>,U>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef IndexBase IB;
|
typedef IndexBase<SingleIndex<U,TYPE>,U> IB;
|
||||||
typedef U MetaType;
|
typedef U MetaType;
|
||||||
typedef SingleRange<U,TYPE> RangeType;
|
typedef SingleRange<U,TYPE> RangeType;
|
||||||
|
|
||||||
|
@ -27,26 +27,30 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
|
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
|
||||||
|
|
||||||
virtual IndexType type() const override;
|
static IndexType S_type(SingleIndex* i) const;
|
||||||
|
|
||||||
virtual SingleIndex& operator=(size_t pos) override;
|
static SingleIndex& S_ass_op(SingleIndex* i, size_t pos);
|
||||||
virtual SingleIndex& operator++() override;
|
static SingleIndex& S_pp_op(SingleIndex* i);
|
||||||
virtual SingleIndex& operator--() override;
|
static SingleIndex& S_mm_op(SingleIndex* i);
|
||||||
|
|
||||||
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) override;
|
static int S_pp(SingleIndex* i, std::shared_ptr<VIWB>& idxPtr);
|
||||||
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) override;
|
static int S_mm(SingleIndex* i, std::shared_ptr<VIWB>& idxPtr);
|
||||||
|
|
||||||
virtual U meta() const override;
|
static U S_meta(SingleIndex* i) const;
|
||||||
virtual SingleIndex& at(const U& metaPos) override;
|
static SingleIndex& S_at(SingleIndex* i, const U& metaPos);
|
||||||
|
|
||||||
virtual size_t dim() const override; // = 1
|
static size_t S_dim(SingleIndex* i) const; // = 1
|
||||||
virtual bool last() const override;
|
static bool S_last(SingleIndex* i) const;
|
||||||
virtual bool first() const override;
|
static bool S_first(SingleIndex* i) const;
|
||||||
|
|
||||||
virtual std::shared_ptr<IndexBase> getPtr(size_t n) const override;
|
template <size_t N>
|
||||||
virtual size_t getStepSize(size_t n) const override;
|
static void S_getPtr(SingleIndex* i) const;
|
||||||
|
|
||||||
virtual std::string id() const override { return std::string("sin") + std::to_string(IB::mId); }
|
std::shared_ptr<VIWB> getVPtr(size_t n) const;
|
||||||
|
|
||||||
|
static size_t S_getStepSize(SingleIndex* i, size_t n) const;
|
||||||
|
|
||||||
|
static std::string S_id(SingleIndex* i) const { return std::string("sin") + std::to_string(IB::mId); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
|
@ -77,7 +81,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
virtual IndexType begin() const override;
|
virtual IndexType begin() const override;
|
||||||
virtual IndexType end() const override;
|
virtual IndexType end() const override;
|
||||||
virtual std::shared_ptr<IndexBase> index() const override;
|
virtual std::shared_ptr<VIWB> index() const override;
|
||||||
|
|
||||||
friend SingleRangeFactory<U,TYPE>;
|
friend SingleRangeFactory<U,TYPE>;
|
||||||
|
|
||||||
|
@ -108,85 +112,92 @@ namespace MultiArrayTools
|
||||||
IndexInterface<U>(range, 0) {}
|
IndexInterface<U>(range, 0) {}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
IndexType SingleIndex<U,TYPE>::type() const
|
IndexType SingleIndex<U,TYPE>::S_type() const
|
||||||
{
|
{
|
||||||
return IndexType::SINGLE;
|
return IndexType::SINGLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
|
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::S_ass_op(size_t pos)
|
||||||
{
|
{
|
||||||
IB::mPos = pos;
|
IB::mPos = pos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator++()
|
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::S_pp_op()
|
||||||
{
|
{
|
||||||
++IB::mPos;
|
++IB::mPos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator--()
|
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::S_mm_op()
|
||||||
{
|
{
|
||||||
--IB::mPos;
|
--IB::mPos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
int SingleIndex<U,TYPE>::pp(std::shared_ptr<IndexBase>& idxPtr)
|
int SingleIndex<U,TYPE>::S_pp(std::shared_ptr<VIWB>& idxPtr)
|
||||||
{
|
{
|
||||||
++(*this);
|
++(*this);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
int SingleIndex<U,TYPE>::mm(std::shared_ptr<IndexBase>& idxPtr)
|
int SingleIndex<U,TYPE>::S_mm(std::shared_ptr<VIWB>& idxPtr)
|
||||||
{
|
{
|
||||||
--(*this);
|
--(*this);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
U SingleIndex<U,TYPE>::meta() const
|
U SingleIndex<U,TYPE>::S_meta() const
|
||||||
{
|
{
|
||||||
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->get( IB::pos() );
|
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->get( IB::pos() );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::at(const U& metaPos)
|
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::S_at(const U& metaPos)
|
||||||
{
|
{
|
||||||
operator=( std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos ) );
|
operator=( std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos ) );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
size_t SingleIndex<U,TYPE>::dim() const
|
size_t SingleIndex<U,TYPE>::S_dim() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
bool SingleIndex<U,TYPE>::last() const
|
bool SingleIndex<U,TYPE>::S_last() const
|
||||||
{
|
{
|
||||||
return IB::mPos == IB::mRangePtr->size() - 1;
|
return IB::mPos == IB::mRangePtr->size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
bool SingleIndex<U,TYPE>::first() const
|
bool SingleIndex<U,TYPE>::S_first() const
|
||||||
{
|
{
|
||||||
return IB::mPos == 0;
|
return IB::mPos == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
std::shared_ptr<IndexBase> SingleIndex<U,TYPE>::getPtr(size_t n) const
|
template <size_t N>
|
||||||
|
void SingleIndex<U,TYPE>::S_getPtr() const
|
||||||
{
|
{
|
||||||
return std::shared_ptr<IndexBase>();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
size_t SingleIndex<U,TYPE>::getStepSize(size_t n) const
|
std::shared_ptr<VIWB> SingleIndex<U,TYPE>::getVPtr(size_t n) const
|
||||||
|
{
|
||||||
|
return std::shared_ptr<VIWB>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U, RangeType TYPE>
|
||||||
|
size_t SingleIndex<U,TYPE>::S_getStepSize(size_t n) const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -267,11 +278,12 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
// put this in the interface class !!!
|
// put this in the interface class !!!
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
std::shared_ptr<IndexBase> SingleRange<U,TYPE>::index() const
|
std::shared_ptr<VIWB> SingleRange<U,TYPE>::index() const
|
||||||
{
|
{
|
||||||
return std::make_shared<SingleIndex<U,TYPE> >
|
return std::make_shared<VIWB>
|
||||||
|
( std::make_shared<SingleIndex<U,TYPE> >
|
||||||
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
||||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue