remove virtual stuff in block and operation classes
This commit is contained in:
parent
b75f2b4cf8
commit
3e502b2496
6 changed files with 133 additions and 378 deletions
|
@ -131,7 +131,7 @@ namespace MultiArrayTools
|
|||
class OperationTemplate;
|
||||
|
||||
// multi_array_operation.h
|
||||
template <typename T, class... Ranges>
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
class OperationMaster;
|
||||
|
||||
// multi_array_operation.h
|
||||
|
@ -189,7 +189,7 @@ namespace MultiArrayTools
|
|||
namespace MultiArrayHelper
|
||||
{
|
||||
// block.h
|
||||
template <typename T, class OpFunc>
|
||||
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
|
||||
class BlockBinaryOp;
|
||||
|
||||
// block.h
|
||||
|
|
222
src/block.cc
222
src/block.cc
|
@ -9,9 +9,10 @@ namespace MultiArrayHelper
|
|||
* BlockBinaryOp *
|
||||
*********************/
|
||||
|
||||
template <typename T, class OpFunc>
|
||||
BlockResult<T> BlockBinaryOp<T,OpFunc>::operator()(const BlockBase<T>& arg1,
|
||||
const BlockBase<T>& arg2)
|
||||
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
|
||||
BlockResult<T>
|
||||
BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::operator()(const BlockClass1& arg1,
|
||||
const BlockClass2& arg2)
|
||||
{
|
||||
static OpFunc f;
|
||||
BlockResult<T> res(arg1.size());
|
||||
|
@ -80,14 +81,6 @@ namespace MultiArrayHelper
|
|||
template <typename T>
|
||||
MutableBlockBase<T>::MutableBlockBase(size_t size) : BlockBase<T>(size) {}
|
||||
|
||||
template <typename T>
|
||||
MutableBlockBase<T>& MutableBlockBase<T>::operator=(const BlockBase<T>& in)
|
||||
{
|
||||
for(size_t i = 0; i != BlockBase<T>::mSize; ++i){
|
||||
(*this)[i] = in[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*************
|
||||
* Block *
|
||||
|
@ -95,22 +88,24 @@ namespace MultiArrayHelper
|
|||
|
||||
template <typename T>
|
||||
Block<T>::Block(const std::vector<T>& data,
|
||||
size_t begPos, size_t size) :
|
||||
size_t begPos, size_t size, size_t stepSize) :
|
||||
BlockBase<T>(size),
|
||||
mData(&data),
|
||||
mBegPtr(data.data() + begPos) {}
|
||||
mBegPtr(data.data() + begPos),
|
||||
mStepSize(stepSize) {}
|
||||
|
||||
template <typename T>
|
||||
BlockType Block<T>::type() const
|
||||
{
|
||||
return BlockType::BLOCK;
|
||||
return mStepSize == 0 ? BlockType::VALUE :
|
||||
( mStepSize == 1 ? BlockType::BLOCK : BlockType::SPLIT );
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& Block<T>::operator[](size_t i) const
|
||||
{
|
||||
|
||||
return *(mBegPtr + i);
|
||||
return *(mBegPtr + i * mStepSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -132,29 +127,41 @@ namespace MultiArrayHelper
|
|||
|
||||
template <typename T>
|
||||
MBlock<T>::MBlock(std::vector<T>& data,
|
||||
size_t begPos, size_t size) :
|
||||
size_t begPos, size_t size, size_t stepSize) :
|
||||
MutableBlockBase<T>(size),
|
||||
mData(&data),
|
||||
mBegPtr(data.data() + begPos) {}
|
||||
mBegPtr(data.data() + begPos),
|
||||
mStepSize(stepSize) {}
|
||||
|
||||
template <typename T>
|
||||
template <class BlockClass>
|
||||
MBlock<T>& MBlock<T>::operator=(const BlockClass& in)
|
||||
{
|
||||
for(size_t i = 0; i != BlockBase<T>::mSize; ++i){
|
||||
(*this)[i] = in[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
BlockType MBlock<T>::type() const
|
||||
{
|
||||
return BlockType::BLOCK;
|
||||
return mStepSize == 0 ? BlockType::VALUE :
|
||||
( mStepSize == 1 ? BlockType::BLOCK : BlockType::SPLIT );
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& MBlock<T>::operator[](size_t i) const
|
||||
{
|
||||
|
||||
return *(mBegPtr + i);
|
||||
return *(mBegPtr + i * mStepSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& MBlock<T>::operator[](size_t i)
|
||||
{
|
||||
|
||||
return *(mBegPtr + i);
|
||||
return *(mBegPtr + i * mStepSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -170,170 +177,6 @@ namespace MultiArrayHelper
|
|||
return 1;
|
||||
}
|
||||
|
||||
/******************
|
||||
* BlockValue *
|
||||
******************/
|
||||
|
||||
template <typename T>
|
||||
BlockValue<T>::BlockValue(const std::vector<T>& data,
|
||||
size_t pos, size_t size) :
|
||||
BlockBase<T>(size),
|
||||
mData(&data),
|
||||
mVal(&data[pos]) {}
|
||||
|
||||
template <typename T>
|
||||
BlockType BlockValue<T>::type() const
|
||||
{
|
||||
return BlockType::VALUE;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& BlockValue<T>::operator[](size_t i) const
|
||||
{
|
||||
|
||||
return *mVal;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
BlockValue<T>& BlockValue<T>::set(size_t npos)
|
||||
{
|
||||
mVal = &(*mData)[npos];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t BlockValue<T>::stepSize() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************
|
||||
* MBlockValue *
|
||||
*******************/
|
||||
|
||||
template <typename T>
|
||||
MBlockValue<T>::MBlockValue(std::vector<T>& data,
|
||||
size_t pos, size_t size) :
|
||||
MutableBlockBase<T>(size),
|
||||
mData(&data),
|
||||
mVal(&data[pos]) {}
|
||||
|
||||
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(size_t npos)
|
||||
{
|
||||
mVal = &(*mData)[npos];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t MBlockValue<T>::stepSize() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************
|
||||
* SplitBlock *
|
||||
******************/
|
||||
|
||||
template <typename T>
|
||||
SplitBlock<T>::SplitBlock(const std::vector<T>& data, size_t begPos,
|
||||
size_t stepSize, size_t size) :
|
||||
BlockBase<T>(size),
|
||||
mData(&data),
|
||||
mStepSize(stepSize),
|
||||
mBegPtr(&data[begPos]) {}
|
||||
|
||||
template <typename T>
|
||||
BlockType SplitBlock<T>::type() const
|
||||
{
|
||||
return BlockType::SPLIT;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& SplitBlock<T>::operator[](size_t pos) const
|
||||
{
|
||||
|
||||
return *(mBegPtr + pos*mStepSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
SplitBlock<T>& SplitBlock<T>::set(size_t npos)
|
||||
{
|
||||
mBegPtr = &(*mData)[npos];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t SplitBlock<T>::stepSize() const
|
||||
{
|
||||
return mStepSize;
|
||||
}
|
||||
|
||||
/*******************
|
||||
* MSplitBlock *
|
||||
*******************/
|
||||
|
||||
template <typename T>
|
||||
MSplitBlock<T>::MSplitBlock(std::vector<T>& data, size_t begPos,
|
||||
size_t stepSize, size_t size) :
|
||||
MutableBlockBase<T>(size),
|
||||
mData(&data),
|
||||
mStepSize(stepSize),
|
||||
mBegPtr(&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(size_t npos)
|
||||
{
|
||||
mBegPtr = &(*mData)[npos];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t MSplitBlock<T>::stepSize() const
|
||||
{
|
||||
return mStepSize;
|
||||
}
|
||||
|
||||
/*******************
|
||||
* BlockResult *
|
||||
*******************/
|
||||
|
@ -343,6 +186,16 @@ namespace MultiArrayHelper
|
|||
MutableBlockBase<T>(size),
|
||||
mRes(size) {}
|
||||
|
||||
template <typename T>
|
||||
template <class BlockClass>
|
||||
BlockResult<T>& BlockResult<T>::operator=(const BlockClass& in)
|
||||
{
|
||||
for(size_t i = 0; i != BlockBase<T>::mSize; ++i){
|
||||
(*this)[i] = in[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
BlockType BlockResult<T>::type() const
|
||||
{
|
||||
|
@ -352,7 +205,6 @@ namespace MultiArrayHelper
|
|||
template <typename T>
|
||||
const T& BlockResult<T>::operator[](size_t i) const
|
||||
{
|
||||
|
||||
return mRes[i];
|
||||
}
|
||||
|
||||
|
|
143
src/block.h
143
src/block.h
|
@ -20,14 +20,16 @@ namespace MultiArrayHelper
|
|||
};
|
||||
|
||||
// manage vectorization in the future !!
|
||||
|
||||
template <typename T, class OpFunc>
|
||||
|
||||
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
|
||||
class BlockBinaryOp
|
||||
{
|
||||
public:
|
||||
BlockBinaryOp() = default;
|
||||
BlockResult<T> operator()(const BlockBase<T>& arg1, const BlockBase<T>& arg2);
|
||||
BlockResult<T> operator()(const BlockClass1& arg1, const BlockClass2& arg2);
|
||||
};
|
||||
|
||||
// EVERYTHING IN HERE MUST N O T BE VITUAL !!
|
||||
|
||||
template <typename T>
|
||||
class BlockBase
|
||||
|
@ -35,14 +37,8 @@ namespace MultiArrayHelper
|
|||
public:
|
||||
DEFAULT_MEMBERS(BlockBase);
|
||||
BlockBase(size_t size);
|
||||
|
||||
virtual BlockType type() const = 0;
|
||||
virtual size_t stepSize() const = 0;
|
||||
|
||||
virtual size_t size() const;
|
||||
virtual const T& operator[](size_t pos) const = 0;
|
||||
|
||||
virtual BlockBase& set(size_t npos) = 0;
|
||||
size_t size() const;
|
||||
|
||||
template <class OpFunction>
|
||||
BlockResult<T> operate(const BlockBase& in);
|
||||
|
@ -74,10 +70,6 @@ namespace MultiArrayHelper
|
|||
DEFAULT_MEMBERS(MutableBlockBase);
|
||||
MutableBlockBase(size_t size);
|
||||
|
||||
MutableBlockBase& operator=(const BlockBase<T>& in);
|
||||
|
||||
virtual T& operator[](size_t pos) = 0;
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -85,16 +77,17 @@ namespace MultiArrayHelper
|
|||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(Block);
|
||||
Block(const std::vector<T>& data, size_t begPos, size_t size);
|
||||
Block(const std::vector<T>& data, size_t begPos, size_t size, size_t stepSize);
|
||||
|
||||
virtual BlockType type() const override;
|
||||
virtual const T& operator[](size_t pos) const override;
|
||||
virtual Block& set(size_t npos) override;
|
||||
virtual size_t stepSize() const override;
|
||||
BlockType type() const;
|
||||
const T& operator[](size_t pos) const;
|
||||
Block& set(size_t npos);
|
||||
size_t stepSize() const;
|
||||
|
||||
protected:
|
||||
const std::vector<T>* mData;
|
||||
const T* mBegPtr;
|
||||
size_t mStepSize;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -102,102 +95,23 @@ namespace MultiArrayHelper
|
|||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(MBlock);
|
||||
MBlock(std::vector<T>& data, size_t begPos, size_t size);
|
||||
MBlock(std::vector<T>& data, size_t begPos, size_t size, size_t stepSize);
|
||||
|
||||
virtual BlockType type() const override;
|
||||
virtual const T& operator[](size_t pos) const override;
|
||||
virtual T& operator[](size_t pos) override;
|
||||
virtual MBlock& set(size_t npos) override;
|
||||
virtual size_t stepSize() const override;
|
||||
template <class BlockClass>
|
||||
MBlock& operator=(const BlockClass& in);
|
||||
|
||||
BlockType type() const;
|
||||
const T& operator[](size_t pos) const;
|
||||
T& operator[](size_t pos);
|
||||
MBlock& set(size_t npos);
|
||||
size_t stepSize() const;
|
||||
|
||||
protected:
|
||||
std::vector<T>* mData;
|
||||
T* mBegPtr;
|
||||
size_t mStepSize;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class BlockValue : public BlockBase<T>
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(BlockValue);
|
||||
|
||||
BlockValue(const std::vector<T>& data,
|
||||
size_t pos, size_t size);
|
||||
|
||||
virtual BlockType type() const override;
|
||||
virtual const T& operator[](size_t pos) const override;
|
||||
virtual BlockValue& set(size_t npos) override;
|
||||
virtual size_t stepSize() const override;
|
||||
|
||||
protected:
|
||||
const std::vector<T>* mData;
|
||||
const T* mVal;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MBlockValue : public MutableBlockBase<T>
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(MBlockValue);
|
||||
|
||||
MBlockValue(std::vector<T>& data,
|
||||
size_t pos, 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 MBlockValue& set(size_t npos) override;
|
||||
virtual size_t stepSize() const override;
|
||||
|
||||
protected:
|
||||
std::vector<T>* mData;
|
||||
T* mVal;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class SplitBlock : public BlockBase<T>
|
||||
{
|
||||
public:
|
||||
|
||||
DEFAULT_MEMBERS(SplitBlock);
|
||||
|
||||
SplitBlock(const 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 SplitBlock& set(size_t npos) override;
|
||||
virtual size_t stepSize() const override;
|
||||
|
||||
protected:
|
||||
const std::vector<T>* mData;
|
||||
size_t mStepSize;
|
||||
const T* mBegPtr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MSplitBlock : public MutableBlockBase<T>
|
||||
{
|
||||
public:
|
||||
|
||||
DEFAULT_MEMBERS(MSplitBlock);
|
||||
|
||||
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 MSplitBlock& set(size_t npos) override;
|
||||
virtual size_t stepSize() const override;
|
||||
|
||||
protected:
|
||||
std::vector<T>* mData;
|
||||
size_t mStepSize;
|
||||
T* mBegPtr;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class BlockResult : public MutableBlockBase<T>
|
||||
{
|
||||
|
@ -206,11 +120,14 @@ namespace MultiArrayHelper
|
|||
|
||||
BlockResult(size_t size);
|
||||
|
||||
virtual BlockType type() const override;
|
||||
virtual const T& operator[](size_t pos) const override;
|
||||
virtual T& operator[](size_t i) override;
|
||||
virtual BlockResult& set(size_t npos) override;
|
||||
virtual size_t stepSize() const override;
|
||||
template <class BlockClass>
|
||||
BlockResult& operator=(const BlockClass& in);
|
||||
|
||||
BlockType type() const;
|
||||
const T& operator[](size_t pos) const;
|
||||
T& operator[](size_t i);
|
||||
BlockResult& set(size_t npos);
|
||||
size_t stepSize() const;
|
||||
|
||||
protected:
|
||||
std::vector<T> mRes;
|
||||
|
|
|
@ -58,31 +58,15 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<BlockBase<T> > makeBlock(const std::vector<T>& vec, size_t stepSize, size_t blockSize)
|
||||
std::shared_ptr<Block<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);
|
||||
}
|
||||
return std::make_shared<Block<T> >(vec, 0, blockSize, stepSize);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<MutableBlockBase<T> > makeBlock(std::vector<T>& vec, size_t stepSize, size_t blockSize)
|
||||
std::shared_ptr<MBlock<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);
|
||||
}
|
||||
return std::make_shared<MBlock<T> >(vec, 0, blockSize, stepSize);
|
||||
}
|
||||
|
||||
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt)
|
||||
|
@ -119,9 +103,9 @@ namespace MultiArrayTools
|
|||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class OpClass>
|
||||
std::shared_ptr<IndexBase> seekBlockIndex(std::shared_ptr<IndexBase> ownIdx,
|
||||
const OperationBase<T>& second)
|
||||
const OpClass& second)
|
||||
{
|
||||
std::vector<std::shared_ptr<IndexBase> > ivec;
|
||||
seekIndexInst(ownIdx, ivec);
|
||||
|
@ -189,9 +173,9 @@ namespace MultiArrayTools
|
|||
* OperationMaster *
|
||||
*************************/
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
OperationMaster<T,Ranges...>::
|
||||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OperationBase<T>& second,
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
OperationMaster<T,OpClass,Ranges...>::
|
||||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
|
||||
std::shared_ptr<typename CRange::IndexType>& index) :
|
||||
mSecond(second), mArrayRef(ma), mIndex()
|
||||
{
|
||||
|
@ -211,30 +195,30 @@ namespace MultiArrayTools
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
MutableBlockBase<T>& OperationMaster<T,Ranges...>::get()
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
MBlock<T>& OperationMaster<T,OpClass,Ranges...>::get()
|
||||
{
|
||||
block();
|
||||
return *mBlockPtr;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
const BlockBase<T>& OperationMaster<T,Ranges...>::get() const
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
const Block<T>& OperationMaster<T,OpClass,Ranges...>::get() const
|
||||
{
|
||||
block();
|
||||
return *mBlockPtr;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
std::vector<BTSS> OperationMaster<T,Ranges...>::block(const std::shared_ptr<IndexBase> blockIndex) const
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const std::shared_ptr<IndexBase> blockIndex) const
|
||||
{
|
||||
std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) );
|
||||
mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max());
|
||||
return btv;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
const OperationMaster<T,Ranges...>& OperationMaster<T,Ranges...>::block() const
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
const OperationMaster<T,OpClass,Ranges...>& OperationMaster<T,OpClass,Ranges...>::block() const
|
||||
{
|
||||
mBlockPtr->set( mIndex->pos() );
|
||||
return *this;
|
||||
|
@ -248,14 +232,14 @@ namespace MultiArrayTools
|
|||
ConstOperationRoot<T,Ranges...>::
|
||||
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||
OperationBase<T>(), OperationTemplate<T,ConstOperationRoot<T,Ranges...> >(this),
|
||||
OperationTemplate<T,ConstOperationRoot<T,Ranges...> >(this),
|
||||
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
|
||||
{
|
||||
(*mIndex)(indices...);
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
const BlockBase<T>& ConstOperationRoot<T,Ranges...>::get() const
|
||||
const Block<T>& ConstOperationRoot<T,Ranges...>::get() const
|
||||
{
|
||||
block();
|
||||
return *mBlockPtr;
|
||||
|
@ -284,27 +268,28 @@ namespace MultiArrayTools
|
|||
OperationRoot<T,Ranges...>::
|
||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||
MutableOperationBase<T>(), OperationTemplate<T,OperationRoot<T,Ranges...> >(this),
|
||||
OperationTemplate<T,OperationRoot<T,Ranges...> >(this),
|
||||
mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
|
||||
{
|
||||
(*mIndex)(indices...);
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
OperationMaster<T,Ranges...> OperationRoot<T,Ranges...>::operator=(const OperationBase<T>& in)
|
||||
template <class OpClass>
|
||||
OperationMaster<T,OpClass,Ranges...> OperationRoot<T,Ranges...>::operator=(const OpClass& in)
|
||||
{
|
||||
return OperationMaster<T,Ranges...>(mArrayRef, in, mIndex);
|
||||
return OperationMaster<T,OpClass,Ranges...>(mArrayRef, in, mIndex);
|
||||
}
|
||||
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
const BlockBase<T>& OperationRoot<T,Ranges...>::get() const
|
||||
const MBlock<T>& OperationRoot<T,Ranges...>::get() const
|
||||
{
|
||||
block();
|
||||
return *mBlockPtr;
|
||||
}
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
MutableBlockBase<T>& OperationRoot<T,Ranges...>::get()
|
||||
MBlock<T>& OperationRoot<T,Ranges...>::get()
|
||||
{
|
||||
block();
|
||||
return *mBlockPtr;
|
||||
|
@ -331,11 +316,11 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
Operation<T,OpFunction,Ops...>::Operation(const Ops&... ops) :
|
||||
OperationBase<T>(), OperationTemplate<T,Operation<T,OpFunction,Ops...> >(this),
|
||||
OperationTemplate<T,Operation<T,OpFunction,Ops...> >(this),
|
||||
mOps(ops...) {}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
const BlockBase<T>& Operation<T,OpFunction,Ops...>::get() const
|
||||
const BlockResult<T>& Operation<T,OpFunction,Ops...>::get() const
|
||||
{
|
||||
mRes = std::move( PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mOps) );
|
||||
return mRes;
|
||||
|
|
|
@ -43,20 +43,20 @@ namespace MultiArrayTools
|
|||
bool first, size_t higherStepSize = 1);
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<BlockBase<T> > makeBlock(const std::vector<T>& vec, size_t stepSize, size_t blockSize);
|
||||
std::shared_ptr<Block<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);
|
||||
std::shared_ptr<MBlock<T> > makeBlock(std::vector<T>& vec, size_t stepSize, size_t blockSize);
|
||||
|
||||
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt);
|
||||
|
||||
void minimizeAppearanceOfType(std::map<std::shared_ptr<IndexBase>, std::vector<BTSS> >& mp,
|
||||
BlockType bt);
|
||||
|
||||
template <typename T>
|
||||
template <class OpClass>
|
||||
std::shared_ptr<IndexBase> seekBlockIndex(std::shared_ptr<IndexBase> ownIdx,
|
||||
const OperationBase<T>& second);
|
||||
|
||||
const OpClass& second);
|
||||
/*
|
||||
template <typename T>
|
||||
class OperationBase
|
||||
{
|
||||
|
@ -71,7 +71,7 @@ namespace MultiArrayTools
|
|||
virtual const OperationBase& block() const = 0; // update block
|
||||
|
||||
//virtual size_t argNum() const = 0;
|
||||
virtual const BlockBase<T>& get() const = 0;
|
||||
virtual const Block<T>& get() const = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -82,10 +82,10 @@ namespace MultiArrayTools
|
|||
|
||||
MutableOperationBase() = default;
|
||||
|
||||
virtual MutableBlockBase<T>& get() = 0;
|
||||
virtual MBlock<T>& get() = 0;
|
||||
|
||||
};
|
||||
|
||||
*/
|
||||
template <typename T, class OperationClass>
|
||||
class OperationTemplate
|
||||
{
|
||||
|
@ -113,8 +113,8 @@ namespace MultiArrayTools
|
|||
OperationClass* mOc;
|
||||
};
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
class OperationMaster : public MutableOperationBase<T>
|
||||
template <typename T, class OpClass, class... Ranges>
|
||||
class OperationMaster/* : public MutableOperationBase<T>*/
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -123,27 +123,27 @@ namespace MultiArrayTools
|
|||
typedef ContainerRange<Ranges...> CRange;
|
||||
typedef typename MultiRange<Ranges...>::IndexType IndexType;
|
||||
|
||||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OperationBase<T>& second,
|
||||
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
|
||||
std::shared_ptr<typename CRange::IndexType>& index);
|
||||
|
||||
virtual MutableBlockBase<T>& get() override;
|
||||
virtual const BlockBase<T>& get() const override;
|
||||
|
||||
MBlock<T>& get();
|
||||
const Block<T>& get() const;
|
||||
|
||||
virtual std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const override;
|
||||
virtual const OperationMaster& block() const override;
|
||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
||||
const OperationMaster& block() const;
|
||||
|
||||
protected:
|
||||
|
||||
//void performAssignment(const OperationBase<T>& in);
|
||||
OperationBase<T> const& mSecond;
|
||||
OpClass const& mSecond;
|
||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
mutable std::shared_ptr<MutableBlockBase<T> > mBlockPtr;
|
||||
mutable std::shared_ptr<MBlock<T> > mBlockPtr;
|
||||
};
|
||||
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
class ConstOperationRoot : public OperationBase<T>,
|
||||
class ConstOperationRoot : /*public OperationBase<T>,*/
|
||||
public OperationTemplate<T,ConstOperationRoot<T,Ranges...> >
|
||||
{
|
||||
public:
|
||||
|
@ -157,20 +157,20 @@ namespace MultiArrayTools
|
|||
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
virtual const BlockBase<T>& get() const override;
|
||||
const Block<T>& get() const;
|
||||
|
||||
virtual std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const override;
|
||||
virtual const ConstOperationRoot& block() const override;
|
||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
||||
const ConstOperationRoot& block() const;
|
||||
|
||||
protected:
|
||||
|
||||
MultiArrayBase<T,Ranges...> const& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
mutable std::shared_ptr<BlockBase<T> > mBlockPtr;
|
||||
mutable std::shared_ptr<Block<T> > mBlockPtr;
|
||||
};
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
class OperationRoot : public MutableOperationBase<T>,
|
||||
class OperationRoot : /*public MutableOperationBase<T>,*/
|
||||
public OperationTemplate<T,OperationRoot<T,Ranges...> >
|
||||
{
|
||||
public:
|
||||
|
@ -184,23 +184,24 @@ namespace MultiArrayTools
|
|||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
OperationMaster<T,Ranges...> operator=(const OperationBase<T>& in);
|
||||
template <class OpClass>
|
||||
OperationMaster<T,OpClass,Ranges...> operator=(const OpClass& in);
|
||||
|
||||
virtual const BlockBase<T>& get() const override;
|
||||
virtual MutableBlockBase<T>& get() override;
|
||||
const MBlock<T>& get() const;
|
||||
MBlock<T>& get();
|
||||
|
||||
virtual std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const override;
|
||||
virtual const OperationRoot& block() const override;
|
||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
||||
const OperationRoot& block() const;
|
||||
|
||||
protected:
|
||||
|
||||
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
|
||||
std::shared_ptr<IndexType> mIndex;
|
||||
mutable std::shared_ptr<MutableBlockBase<T> > mBlockPtr;
|
||||
mutable std::shared_ptr<MBlock<T> > mBlockPtr;
|
||||
};
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
class Operation : public OperationBase<T>,
|
||||
class Operation : /*public OperationBase<T>,*/
|
||||
public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
|
||||
{
|
||||
public:
|
||||
|
@ -212,10 +213,10 @@ namespace MultiArrayTools
|
|||
|
||||
Operation(const Ops&... ops);
|
||||
|
||||
virtual const BlockBase<T>& get() const override;
|
||||
const BlockResult<T>& get() const;
|
||||
|
||||
virtual std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const override;
|
||||
virtual const Operation& block() const override;
|
||||
std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
|
||||
const Operation& block() const;
|
||||
|
||||
protected:
|
||||
std::tuple<Ops...> mOps;
|
||||
|
|
|
@ -408,7 +408,7 @@ namespace MultiArrayHelper
|
|||
{
|
||||
static_assert(sizeof...(Args) == std::tuple_size<ArgTuple>::value-1,
|
||||
"inconsistent number of arguments");
|
||||
static BlockBinaryOp<T,Func> f;
|
||||
static BlockBinaryOp<T,Func,decltype(std::get<0>(tp).get()), decltype(args)...> f;
|
||||
return f(std::get<0>(tp).get(), args...);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue