im com (finished block draft)
This commit is contained in:
parent
b985b9c35c
commit
7763bf4f77
14 changed files with 512 additions and 65 deletions
|
@ -105,7 +105,7 @@ namespace MultiArrayTools
|
|||
// container_range.h
|
||||
template <class... Indices>
|
||||
class ContainerIndex;
|
||||
|
||||
|
||||
// multi_array.h
|
||||
template <typename T, class... SRanges>
|
||||
class MultiArrayBase;
|
||||
|
@ -118,6 +118,42 @@ namespace MultiArrayTools
|
|||
template <typename T, class... SRanges>
|
||||
class MultiArray;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class BlockBase;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class MutableBlockBase;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class Block;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class MBlock;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class BlockValue;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class MBlockValue;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class SplitBlock;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class MSplitBlock;
|
||||
|
||||
// block.h
|
||||
template <typename T>
|
||||
class BlockResult;
|
||||
|
||||
// multi_array_operation.h
|
||||
template <typename T>
|
||||
class OperationBase;
|
||||
|
|
112
src/block.cc
112
src/block.cc
|
@ -54,6 +54,13 @@ namespace MultiArrayHelper
|
|||
{
|
||||
return operate<std::divides<T> >(in);
|
||||
}
|
||||
|
||||
/************************
|
||||
* MutableBlockBase *
|
||||
************************/
|
||||
|
||||
template <typename T>
|
||||
MutableBlockBase<T>::MutableBlockBase(size_t size) : BlockBase<T>(size) {}
|
||||
|
||||
/*************
|
||||
* Block *
|
||||
|
@ -83,6 +90,41 @@ namespace MultiArrayHelper
|
|||
mBegPtr = nbeg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**************
|
||||
* MBlock *
|
||||
**************/
|
||||
|
||||
template <typename T>
|
||||
MBlock<T>::MBlock(const std::vector<T>& data,
|
||||
size_t begPos, size_t size) :
|
||||
MutableBlockBase<T>(size),
|
||||
mBegPtr(data.data() + begPos) {}
|
||||
|
||||
template <typename T>
|
||||
BlockType MBlock<T>::type() const
|
||||
{
|
||||
return BlockType::BLOCK;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& MBlock<T>::operator[](size_t i) const
|
||||
{
|
||||
return *(mBegPtr + i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& MBlock<T>::operator[](size_t i)
|
||||
{
|
||||
return *(mBegPtr + i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
MBlock<T>& MBlock<T>::set(const T* nbeg)
|
||||
{
|
||||
mBegPtr = nbeg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/******************
|
||||
* BlockValue *
|
||||
|
@ -112,6 +154,40 @@ namespace MultiArrayHelper
|
|||
return *this;
|
||||
}
|
||||
|
||||
/*******************
|
||||
* MBlockValue *
|
||||
*******************/
|
||||
|
||||
template <typename T>
|
||||
MBlockValue<T>::MBlockValue(const T& val, size_t size) :
|
||||
BlockBase<T>(size),
|
||||
mVal(val) {}
|
||||
|
||||
template <typename T>
|
||||
BlockType MBlockValue<T>::type() const
|
||||
{
|
||||
return BlockType::VALUE;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& MBlockValue<T>::operator[](size_t i) const
|
||||
{
|
||||
return mVal;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& MBlockValue<T>::operator[](size_t i)
|
||||
{
|
||||
return mVal;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
MBlockValue<T>& MBlockValue<T>::set(const T* nbeg)
|
||||
{
|
||||
mVal = *nbeg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/******************
|
||||
* SplitBlock *
|
||||
******************/
|
||||
|
@ -141,6 +217,42 @@ namespace MultiArrayHelper
|
|||
mBegPtr = nbeg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*******************
|
||||
* MSplitBlock *
|
||||
*******************/
|
||||
|
||||
template <typename T>
|
||||
MSplitBlock<T>::MSplitBlock(const std::vector<T>& data, size_t begPos,
|
||||
size_t stepSize, size_t size) :
|
||||
BlockBase<T>(size),
|
||||
mStepSize(stepSize),
|
||||
mBegPtr(data.data() + begPos) {}
|
||||
|
||||
template <typename T>
|
||||
BlockType MSplitBlock<T>::type() const
|
||||
{
|
||||
return BlockType::SPLIT;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& MSplitBlock<T>::operator[](size_t pos) const
|
||||
{
|
||||
return *(mBegPtr + pos*mStepSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& MSplitBlock<T>::operator[](size_t pos)
|
||||
{
|
||||
return *(mBegPtr + pos*mStepSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
MSplitBlock<T>& MSplitBlock<T>::set(const T* nbeg)
|
||||
{
|
||||
mBegPtr = nbeg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*******************
|
||||
* BlockResult *
|
||||
|
|
69
src/block.h
69
src/block.h
|
@ -47,6 +47,18 @@ namespace MultiArrayHelper
|
|||
size_t mSize;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MutableBlockBase : public BlockBase<T>
|
||||
{
|
||||
public:
|
||||
|
||||
MutableBlockBase() = default;
|
||||
MutableBlockBase(size_t size);
|
||||
|
||||
virtual T& operator[](size_t pos) override;
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Block : public BlockBase<T>
|
||||
{
|
||||
|
@ -62,6 +74,22 @@ namespace MultiArrayHelper
|
|||
const T* mBegPtr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MBlock : public MutableBlockBase<T>
|
||||
{
|
||||
public:
|
||||
MBlock() = default;
|
||||
MBlock(std::vector<T>& data, size_t begPos, size_t size);
|
||||
|
||||
virtual BlockType type() const override;
|
||||
virtual const T& operator[](size_t pos) const override;
|
||||
virtual T& operator[](size_t pos) override;
|
||||
virtual Block& set(const T* nbeg) override;
|
||||
|
||||
protected:
|
||||
T* mBegPtr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class BlockValue : public BlockBase<T>
|
||||
{
|
||||
|
@ -77,7 +105,22 @@ namespace MultiArrayHelper
|
|||
T mVal;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class MBlockValue : public MutableBlockBase<T>
|
||||
{
|
||||
public:
|
||||
MBlockValue() = default;
|
||||
MBlockValue(T& val, size_t size);
|
||||
|
||||
virtual BlockType type() const override;
|
||||
virtual const T& operator[](size_t pos) const override;
|
||||
virtual T& operator[](size_t pos) override;
|
||||
virtual BlockValue& set(const T* nbeg) override;
|
||||
|
||||
protected:
|
||||
T& mVal;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class SplitBlock : public BlockBase<T>
|
||||
{
|
||||
|
@ -97,7 +140,27 @@ namespace MultiArrayHelper
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
class BlockResult : public BlockBase<T>
|
||||
class MSplitBlock : public MutableBlockBase<T>
|
||||
{
|
||||
public:
|
||||
|
||||
MSplitBlock() = default;
|
||||
MSplitBlock(std::vector<T>& data, size_t begPos,
|
||||
size_t stepSize, size_t size);
|
||||
|
||||
virtual BlockType type() const override;
|
||||
virtual const T& operator[](size_t pos) const override;
|
||||
virtual T& operator[](size_t pos) override;
|
||||
virtual SplitBlock& set(const T* nbeg) override;
|
||||
|
||||
protected:
|
||||
size_t mStepSize;
|
||||
T* mBegPtr;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class BlockResult : public MutableBlockBase<T>
|
||||
{
|
||||
public:
|
||||
BlockResult() = default;
|
||||
|
@ -105,7 +168,7 @@ namespace MultiArrayHelper
|
|||
|
||||
virtual BlockType type() const override;
|
||||
virtual const T& operator[](size_t pos) const override;
|
||||
virtual T& operator[](size_t i);
|
||||
virtual T& operator[](size_t i) override;
|
||||
virtual BlockResult& set(const T* nbeg) override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -78,6 +78,22 @@ namespace MultiArrayTools
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
size_t ContainerIndex<Indices...>::pp(std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
size_t tmp = pp(mIPack, mBlockSizes, idxPtr);
|
||||
IB::mPos += tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
size_t ContainerIndex<Indices...>::mm(std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
size_t tmp = mm(mIPack, mBlockSizes, idxPtr);
|
||||
IB::mPos -= tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
typename ContainerIndex<Indices...>::MetaType ContainerIndex<Indices...>::meta() const
|
||||
{
|
||||
|
|
|
@ -44,6 +44,9 @@ namespace MultiArrayTools
|
|||
virtual ContainerIndex& operator--() override;
|
||||
virtual ContainerIndex& operator=(size_t pos) override;
|
||||
|
||||
virtual size_t pp(std::shared_ptr<const IndexBase>& idxPtr) override;
|
||||
virtual size_t mm(std::shared_ptr<const IndexBase>& idxPtr) override;
|
||||
|
||||
virtual MetaType meta() const override;
|
||||
virtual ContainerIndex& at(const MetaType& metaPos) override;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
return mRangePtr->size();
|
||||
}
|
||||
|
||||
/*
|
||||
bool IndexBase::locked() const
|
||||
{
|
||||
return mLocked;
|
||||
|
@ -44,7 +44,7 @@ namespace MultiArrayTools
|
|||
mLocked = (idx.get() == this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
IndexBase::operator size_t() const
|
||||
{
|
||||
|
|
|
@ -43,6 +43,9 @@ namespace MultiArrayTools
|
|||
virtual IndexBase& operator=(size_t pos) = 0;
|
||||
virtual IndexBase& operator++() = 0;
|
||||
virtual IndexBase& operator--() = 0;
|
||||
|
||||
virtual size_t pp(std::shared_ptr<const IndexBase>& idxPtr) = 0;
|
||||
virtual size_t mm(std::shared_ptr<const IndexBase>& idxPtr) = 0;
|
||||
|
||||
bool operator==(const IndexBase& in) const;
|
||||
bool operator!=(const IndexBase& in) const;
|
||||
|
@ -53,9 +56,9 @@ namespace MultiArrayTools
|
|||
|
||||
virtual bool last() const = 0;
|
||||
virtual bool first() const = 0;
|
||||
|
||||
virtual bool locked() const;
|
||||
virtual IndexBase& lock(std::shared_ptr<const IndexBase>& idx);
|
||||
|
||||
//virtual bool locked() const;
|
||||
//virtual IndexBase& lock(std::shared_ptr<const IndexBase>& idx);
|
||||
|
||||
virtual std::shared_ptr<const IndexBase> getPtr(size_t n) const = 0;
|
||||
|
||||
|
@ -67,7 +70,7 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<RangeBase> mRangePtr;
|
||||
size_t mPos;
|
||||
size_t mId;
|
||||
bool mLocked = false;
|
||||
//bool mLocked = false;
|
||||
};
|
||||
|
||||
template <typename MetaType>
|
||||
|
|
|
@ -19,31 +19,66 @@ namespace MultiArrayTools
|
|||
ivec.push_back(ii);
|
||||
}
|
||||
}
|
||||
|
||||
BlockType getBlockType(std::shared_ptr<const IndexBase> i,
|
||||
std::shared_ptr<const IndexBase> j, bool first)
|
||||
|
||||
// !!!
|
||||
BTSS getBlockType(std::shared_ptr<const IndexBase> i,
|
||||
std::shared_ptr<const IndexBase> j, bool first)
|
||||
{
|
||||
BlockType out = BlockType::VALUE;
|
||||
// returning BlockType and step size is redundant (change in the future)
|
||||
// stepSize == 0 => VALUE
|
||||
// stepSize == 1 => BLOCK
|
||||
// stepSize > 1 => SPLIT :)
|
||||
BTSS out(BlockType::VALUE, 0);
|
||||
for(size_t inum = 0; inum != i->range()->dim(); ++inum){
|
||||
auto ii = i->getPtr(inum);
|
||||
if(ii == j){
|
||||
if(inum == 0){
|
||||
out = BlockType::BLOCK;
|
||||
if(inum == 0 and first){
|
||||
out = BTSS(BlockType::BLOCK, 1);
|
||||
}
|
||||
else {
|
||||
out = BlockType::SPLIT;
|
||||
out = BTSS(BlockType::SPLIT, i->getStepSize(inum));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ii->type() == IndexType::MULTI){
|
||||
BlockType tmp = getBlockType(ii, j, ivec);
|
||||
if(tmp != BlockType::VALUE){
|
||||
if(ii->type() == IndexType::MULTI or
|
||||
ii->type() == IndexType::CONT){
|
||||
BTSS tmp = getBlockType(ii, j, inum == 0);
|
||||
if(tmp.first != BlockType::VALUE){
|
||||
out = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<BlockBase<T> > makeBlock(const std::vector<T>& vec, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
if(stepSize == 0){
|
||||
return std::make_shared<BlockValue<T> >(vec[0], blockSize);
|
||||
}
|
||||
else if(stepSize == 1){
|
||||
return std::make_shared<Block<T> >(vec, 0, blockSize);
|
||||
}
|
||||
else {
|
||||
return std::make_shared<SplitBlock<T> >(vec, 0, stepSize, blockSize);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<MutableBlockBase<T> > makeBlock(std::vector<T>& vec, size_t stepSize, size_t blockSize)
|
||||
{
|
||||
if(stepSize == 0){
|
||||
return std::make_shared<MBlockValue<T> >(vec[0], blockSize);
|
||||
}
|
||||
else if(stepSize == 1){
|
||||
return std::make_shared<MBlock<T> >(vec, 0, blockSize);
|
||||
}
|
||||
else {
|
||||
return std::make_shared<MSplitBlock<T> >(vec, 0, stepSize, blockSize);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************
|
||||
* MultiArrayOperationBase *
|
||||
|
@ -106,9 +141,11 @@ namespace MultiArrayTools
|
|||
std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
||||
mIndex = std::make_shared<IndexType>( mr->begin() );
|
||||
(*mIndex) = *index;
|
||||
// -> find optimal block index !!!
|
||||
// -> lock this index !!!
|
||||
for(*mIndex = 0; mIndex->pos() != mIndex->max(); ++(*mIndex)){
|
||||
|
||||
auto blockIndex = seekBlockIndex(mIndex, second);
|
||||
block(blockIndex);
|
||||
second.block(blockIndex);
|
||||
for(*mIndex = 0; mIndex->pos() != mIndex->max(); mIndex->pp(blockIndex) )){
|
||||
get() = mSecond.get();
|
||||
}
|
||||
}
|
||||
|
@ -128,10 +165,11 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
std::vector<BlockType> OperationMaster<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
|
||||
std::vector<BTSS> OperationMaster<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
|
||||
{
|
||||
// seek index with smallest number of SPLITs !!!
|
||||
|
||||
std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) );
|
||||
mBlockPtr = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
|
||||
return btv;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
|
@ -163,9 +201,11 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
std::vector<BlockType> ConstOperationRoot<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
|
||||
std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
|
||||
{
|
||||
// !!!
|
||||
std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) );
|
||||
mBlockPtr = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
|
||||
return btv;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
|
@ -206,13 +246,15 @@ namespace MultiArrayTools
|
|||
BlockBase<T>& OperationRoot<T,Ranges...>::get()
|
||||
{
|
||||
block();
|
||||
return *mBlockPtr; // issue: const !!!
|
||||
return *mBlockPtr;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
std::vector<BlockType> OperationRoot<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
|
||||
std::vector<BTSS> OperationRoot<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
|
||||
{
|
||||
// !!!
|
||||
std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) );
|
||||
mBlockPtr = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
|
||||
return btv;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
|
@ -239,9 +281,11 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
std::vector<BlockType> Operation<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
|
||||
std::vector<BTSS> Operation<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
|
||||
{
|
||||
// !!!
|
||||
std::vector<BTSS> btv;
|
||||
PackNum<sizeof...(Ranges)-1>::makeBlockTypeVec(btv, mOps, blockIndex);
|
||||
return btv;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
#include "base_def.h"
|
||||
|
||||
|
@ -32,9 +34,73 @@ namespace MultiArrayTools
|
|||
|
||||
void seekIndexInst(std::shared_ptr<const IndexBase> i, std::vector<std::shared_ptr<const IndexBase> >& ivec);
|
||||
|
||||
BlockType getBlockType(std::shared_ptr<const IndexBase> i,
|
||||
std::shared_ptr<const IndexBase> j, bool first);
|
||||
|
||||
// <block type, step size within actual instance>
|
||||
typedef std::pair<BlockType,size_t> BTSS;
|
||||
|
||||
BTSS getBlockType(std::shared_ptr<const IndexBase> i,
|
||||
std::shared_ptr<const IndexBase> j, bool first);
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<BlockBase<T> > makeBlock(const std::vector<T>& vec, size_t stepSize, size_t blockSize);
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<MutableBlockBase<T> > makeBlock(std::vector<T>& vec, size_t stepSize, size_t blockSize);
|
||||
|
||||
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt)
|
||||
{
|
||||
size_t out = 0;
|
||||
for(auto& xx: mp){
|
||||
if(xx.first == bt){
|
||||
++out;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void minimizeAppearanceOfType(std::map<std::shared_ptr<const IndexBase>, std::vector<BTSS> > mp,
|
||||
BlockType bt)
|
||||
{
|
||||
size_t minNum = getBTNum( *mp.begin(), bt );
|
||||
for(auto& mm: mp){
|
||||
size_t tmp = getBTNum( mm.second, bt );
|
||||
if(tmp < minNum){
|
||||
minNum = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
for(auto mit = mp.begin(); mit != mp.end(); ){
|
||||
size_t tmp = getBTNum( mit->second, bt );
|
||||
if(tmp > minNum){
|
||||
mit = mp.erase(mit);
|
||||
}
|
||||
else {
|
||||
++mit;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<const IndexBase> seekBlockIndex(std::shared_ptr<const IndexBase>& ownIdx,
|
||||
const OperationBase<T>& second)
|
||||
{
|
||||
std::vector<std::shared_ptr<const IndexBase> > ivec;
|
||||
seekIndexInst(ownIdx, ivec);
|
||||
std::map<std::shared_ptr<const IndexBase>, std::vector<BTSS> > mp;
|
||||
|
||||
for(auto& xx: ivec){
|
||||
mp[xx] = second.block(xx);
|
||||
}
|
||||
|
||||
// seek minimal number of VALUEs => guarantees absence of conflicting blocks
|
||||
minimizeAppearanceOfType(mp, BlockType::VALUE);
|
||||
|
||||
// seek mininmal number of SPLITs => maximal vectorization possible
|
||||
minimizeAppearanceOfType(mp, BlockType::SPLIT);
|
||||
|
||||
return *mp.begin();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class OperationBase
|
||||
|
@ -52,9 +118,6 @@ namespace MultiArrayTools
|
|||
|
||||
//virtual size_t argNum() const = 0;
|
||||
virtual const BlockBase<T>& get() const = 0;
|
||||
|
||||
protected:
|
||||
mutable std::shared_ptr<BlockBase> mBlockPtr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -109,7 +172,7 @@ namespace MultiArrayTools
|
|||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OperationBase<T>& second,
|
||||
std::shared_ptr<typename CRange::IndexType>& index);
|
||||
|
||||
virtual BlockBase<T>& get() override;
|
||||
virtual MutableBlockBase<T>& get() override;
|
||||
virtual const BlockBase<T>& get() const override;
|
||||
|
||||
virtual std::vector<BlockType> block(const std::shared_ptr<IndexBase>& blockIndex) const override;
|
||||
|
@ -121,7 +184,7 @@ namespace MultiArrayTools
|
|||
OperationBase<T> const& mSecond;
|
||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
|
||||
mutable std::shared_ptr<MutableBlockBase> mBlockPtr;
|
||||
};
|
||||
|
||||
|
||||
|
@ -149,6 +212,7 @@ namespace MultiArrayTools
|
|||
|
||||
MultiArrayBase<T,Ranges...> const& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
mutable std::shared_ptr<BlockBase> mBlockPtr;
|
||||
};
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
|
@ -169,7 +233,7 @@ namespace MultiArrayTools
|
|||
OperationMaster<T,Ranges...> operator=(const OperationBase<T>& in);
|
||||
|
||||
virtual const BlockBase<T>& get() const override;
|
||||
virtual BlockBase<T>& get() override;
|
||||
virtual MutableBlockBase<T>& get() override;
|
||||
|
||||
virtual std::vector<BlockType> block(const std::shared_ptr<IndexBase>& blockIndex) const override;
|
||||
virtual OperationRoot& block() const override;
|
||||
|
@ -178,6 +242,7 @@ namespace MultiArrayTools
|
|||
|
||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
mutable std::shared_ptr<MutableBlockBase> mBlockPtr;
|
||||
};
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
|
|
|
@ -59,15 +59,16 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
|
||||
{
|
||||
// return step size -> add to IB::mPos
|
||||
IB::mPos += PackNum<sizeof...(Indices)-1>::pp( mIPack, mBlockSizes );
|
||||
PackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
|
||||
{
|
||||
IB::mPos -= PackNum<sizeof...(Indices)-1>::mm( mIPack, mBlockSizes );
|
||||
PackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -79,13 +80,29 @@ namespace MultiArrayTools
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
size_t MultiIndex<Indices...>::pp(std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
size_t tmp = pp(mIPack, mBlockSizes, idxPtr);
|
||||
IB::mPos += tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
size_t MultiIndex<Indices...>::mm(std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
size_t tmp = mm(mIPack, mBlockSizes, idxPtr);
|
||||
IB::mPos -= tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <size_t DIR>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos += PackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
PackNum<DIR>::pp( mIPack );
|
||||
PackNum<DIR+1>::pp( mIPack );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -95,7 +112,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos -= PackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
PackNum<DIR>::mm( mIPack );
|
||||
PackNum<DIR+1>::mm( mIPack );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -141,6 +158,15 @@ namespace MultiArrayTools
|
|||
return PackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
|
||||
}
|
||||
|
||||
size_t getStepSize(size_t n) const
|
||||
{
|
||||
if(n >= sizeof...(Indices)){
|
||||
assert(0);
|
||||
// throw !!
|
||||
}
|
||||
return mBlockSizes[n+1];
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const
|
||||
{
|
||||
|
@ -174,14 +200,14 @@ namespace MultiArrayTools
|
|||
{
|
||||
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
||||
}
|
||||
|
||||
/*
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::lock(std::shared_ptr<const IndexBase>& idx)
|
||||
{
|
||||
IB::mLocked = (idx.get() == this);
|
||||
PackNum<sizeof...(Indices)-1>::lock(mIPack, idx);
|
||||
return *this;
|
||||
}
|
||||
}*/
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
|
||||
|
|
|
@ -46,6 +46,9 @@ namespace MultiArrayTools
|
|||
virtual MultiIndex& operator--() override;
|
||||
virtual MultiIndex& operator=(size_t pos) override;
|
||||
|
||||
virtual size_t pp(std::shared_ptr<const IndexBase>& idxPtr) override;
|
||||
virtual size_t mm(std::shared_ptr<const IndexBase>& idxPtr) override;
|
||||
|
||||
template <size_t DIR>
|
||||
MultiIndex& up();
|
||||
|
||||
|
@ -60,6 +63,7 @@ namespace MultiArrayTools
|
|||
|
||||
const IndexBase& get(size_t n) const;
|
||||
virtual std::shared_ptr<const IndexBase> getPtr(size_t n) const override;
|
||||
virtual size_t getStepSize(size_t n) const override;
|
||||
|
||||
virtual MetaType meta() const override;
|
||||
virtual MultiIndex& at(const MetaType& metaPos) override;
|
||||
|
@ -71,7 +75,7 @@ namespace MultiArrayTools
|
|||
|
||||
std::shared_ptr<RangeType> range() const;
|
||||
|
||||
virtual MultiIndex& lock(std::shared_ptr<const IndexBase>& idx) override;
|
||||
//virtual MultiIndex& lock(std::shared_ptr<const IndexBase>& idx) override;
|
||||
|
||||
// raplace instances (in contrast to its analogon in ContainerIndex
|
||||
// MultiIndices CANNOT be influences be its subindices, so there is
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace MultiArrayHelper
|
|||
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||
std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
if(N == sizeof...(Indices)){
|
||||
if(N == sizeof...(Indices)+1){
|
||||
std::get<N>(bs) = 1;
|
||||
}
|
||||
else {
|
||||
|
@ -72,42 +72,67 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
static inline size_t pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)>& bs)
|
||||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<N>(ip);
|
||||
if(si.last() or si.locked()){
|
||||
if(si.last()){
|
||||
si = 0;
|
||||
PackNum<N-1>::pp(ip);
|
||||
}
|
||||
else {
|
||||
++si;
|
||||
}
|
||||
if(si.locked()){
|
||||
return std::get<N-1>(bs) - std::get<N>(bs) + 1;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static inline size_t mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)>& bs)
|
||||
static inline size_t pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)>& bs,
|
||||
std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
auto siPtr = std::get<N>(ip);
|
||||
if(siPtr.get() == idxPtr.get()){
|
||||
return std::get<N>(bs) + PackNum<N-1>::pp(ip);
|
||||
}
|
||||
else {
|
||||
if(siPtr->last()){
|
||||
(*siPtr) = 0;
|
||||
return PackNum<N-1>::pp(ip, bs) - siPtr->max() + 1;
|
||||
}
|
||||
else {
|
||||
return siPtr->pp(idxPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<N>(ip);
|
||||
if(si.first() or si.locked()){
|
||||
if(si.first()){
|
||||
si = si.max();
|
||||
PackNum<N-1>::mm(ip);
|
||||
}
|
||||
else {
|
||||
--si;
|
||||
}
|
||||
if(si.locked()){
|
||||
return std::get<N-1>(bs) - std::get<N>(bs) + 1;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static inline size_t mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
std::array<size_t,sizeof...(Indices)>& bs,
|
||||
std::shared_ptr<const IndexBase>& idx)
|
||||
{
|
||||
auto siPtr = std::get<N>(ip);
|
||||
if(siPtr.get() == idxPtr.get()){
|
||||
return std::get<N>(bs) + PackNum<N-1>::mm(ip);
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
if(siPtr->first()){
|
||||
return PackNum<N-1>::mm(ip, bs) - siPtr->max() + 1;
|
||||
}
|
||||
else {
|
||||
return siPtr->pp(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,6 +225,16 @@ namespace MultiArrayHelper
|
|||
{
|
||||
return PackNum<N-1>::template unpackArgs<T,Func>(tp, std::get<N>(tp).get(), args...);
|
||||
}
|
||||
|
||||
template <class... Ops>
|
||||
static void makeBlockTypeVec(std::vector<std::pair<BlockType,size_t> >& btv,
|
||||
const std::tuple<Ops...>& ops,
|
||||
std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
auto& subvec = std::get<N>(ops).block(idxPtr);
|
||||
btv.insert(btv.end(), subvec.begin(), subvec.end() );
|
||||
PackNum<N-1>::makeBlockTypeVec(btv, ops, idxPtr);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -237,6 +272,13 @@ namespace MultiArrayHelper
|
|||
{
|
||||
std::get<0>(bs) = PackNum<sizeof...(Indices)-1>::blockSize(ip);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<0>(ip);
|
||||
++si;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static inline size_t pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
|
@ -252,6 +294,13 @@ namespace MultiArrayHelper
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static inline size_t mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<0>(ip);
|
||||
--si;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static inline size_t mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
|
@ -353,6 +402,15 @@ namespace MultiArrayHelper
|
|||
return f(std::get<0>(tp).get(), args...);
|
||||
}
|
||||
|
||||
template <class... Ops>
|
||||
static void makeBlockTypeVec(std::vector<std::pair<BlockType,size_t> >& btv,
|
||||
const std::tuple<Ops...>& ops,
|
||||
std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
auto& subvec = std::get<0>(ops).block(idxPtr);
|
||||
btv.insert(btv.end(), subvec.begin(), subvec.end() );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // end namespace MultiArrayHelper
|
||||
|
|
|
@ -38,6 +38,20 @@ namespace MultiArrayTools
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
size_t SingleIndex<U,TYPE>::pp(std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
++(*this);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
size_t SingleIndex<U,TYPE>::mm(std::shared_ptr<const IndexBase>& idxPtr)
|
||||
{
|
||||
--(*this);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
U SingleIndex<U,TYPE>::meta() const
|
||||
{
|
||||
|
|
|
@ -33,6 +33,9 @@ namespace MultiArrayTools
|
|||
virtual SingleIndex& operator++() override;
|
||||
virtual SingleIndex& operator--() override;
|
||||
|
||||
virtual size_t pp(std::shared_ptr<const IndexBase>& idxPtr) override;
|
||||
virtual size_t mm(std::shared_ptr<const IndexBase>& idxPtr) override;
|
||||
|
||||
virtual U meta() const override;
|
||||
virtual SingleIndex& at(const U& metaPos) override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue