remove virtual stuff in block and operation classes

This commit is contained in:
Christian Zimmermann 2017-10-31 19:22:34 +01:00
parent b75f2b4cf8
commit 3e502b2496
6 changed files with 133 additions and 378 deletions

View file

@ -131,7 +131,7 @@ namespace MultiArrayTools
class OperationTemplate; class OperationTemplate;
// multi_array_operation.h // multi_array_operation.h
template <typename T, class... Ranges> template <typename T, class OpClass, class... Ranges>
class OperationMaster; class OperationMaster;
// multi_array_operation.h // multi_array_operation.h
@ -189,7 +189,7 @@ namespace MultiArrayTools
namespace MultiArrayHelper namespace MultiArrayHelper
{ {
// block.h // block.h
template <typename T, class OpFunc> template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
class BlockBinaryOp; class BlockBinaryOp;
// block.h // block.h

View file

@ -9,9 +9,10 @@ namespace MultiArrayHelper
* BlockBinaryOp * * BlockBinaryOp *
*********************/ *********************/
template <typename T, class OpFunc> template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
BlockResult<T> BlockBinaryOp<T,OpFunc>::operator()(const BlockBase<T>& arg1, BlockResult<T>
const BlockBase<T>& arg2) BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::operator()(const BlockClass1& arg1,
const BlockClass2& arg2)
{ {
static OpFunc f; static OpFunc f;
BlockResult<T> res(arg1.size()); BlockResult<T> res(arg1.size());
@ -80,14 +81,6 @@ namespace MultiArrayHelper
template <typename T> template <typename T>
MutableBlockBase<T>::MutableBlockBase(size_t size) : BlockBase<T>(size) {} 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 * * Block *
@ -95,22 +88,24 @@ namespace MultiArrayHelper
template <typename T> template <typename T>
Block<T>::Block(const std::vector<T>& data, 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), BlockBase<T>(size),
mData(&data), mData(&data),
mBegPtr(data.data() + begPos) {} mBegPtr(data.data() + begPos),
mStepSize(stepSize) {}
template <typename T> template <typename T>
BlockType Block<T>::type() const BlockType Block<T>::type() const
{ {
return BlockType::BLOCK; return mStepSize == 0 ? BlockType::VALUE :
( mStepSize == 1 ? BlockType::BLOCK : BlockType::SPLIT );
} }
template <typename T> template <typename T>
const T& Block<T>::operator[](size_t i) const const T& Block<T>::operator[](size_t i) const
{ {
return *(mBegPtr + i); return *(mBegPtr + i * mStepSize);
} }
template <typename T> template <typename T>
@ -132,29 +127,41 @@ namespace MultiArrayHelper
template <typename T> template <typename T>
MBlock<T>::MBlock(std::vector<T>& data, 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), MutableBlockBase<T>(size),
mData(&data), 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> template <typename T>
BlockType MBlock<T>::type() const BlockType MBlock<T>::type() const
{ {
return BlockType::BLOCK; return mStepSize == 0 ? BlockType::VALUE :
( mStepSize == 1 ? BlockType::BLOCK : BlockType::SPLIT );
} }
template <typename T> template <typename T>
const T& MBlock<T>::operator[](size_t i) const const T& MBlock<T>::operator[](size_t i) const
{ {
return *(mBegPtr + i); return *(mBegPtr + i * mStepSize);
} }
template <typename T> template <typename T>
T& MBlock<T>::operator[](size_t i) T& MBlock<T>::operator[](size_t i)
{ {
return *(mBegPtr + i); return *(mBegPtr + i * mStepSize);
} }
template <typename T> template <typename T>
@ -170,170 +177,6 @@ namespace MultiArrayHelper
return 1; 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 * * BlockResult *
*******************/ *******************/
@ -343,6 +186,16 @@ namespace MultiArrayHelper
MutableBlockBase<T>(size), MutableBlockBase<T>(size),
mRes(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> template <typename T>
BlockType BlockResult<T>::type() const BlockType BlockResult<T>::type() const
{ {
@ -352,7 +205,6 @@ namespace MultiArrayHelper
template <typename T> template <typename T>
const T& BlockResult<T>::operator[](size_t i) const const T& BlockResult<T>::operator[](size_t i) const
{ {
return mRes[i]; return mRes[i];
} }

View file

@ -20,14 +20,16 @@ namespace MultiArrayHelper
}; };
// manage vectorization in the future !! // manage vectorization in the future !!
template <typename T, class OpFunc> template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
class BlockBinaryOp class BlockBinaryOp
{ {
public: public:
BlockBinaryOp() = default; 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> template <typename T>
class BlockBase class BlockBase
@ -35,14 +37,8 @@ namespace MultiArrayHelper
public: public:
DEFAULT_MEMBERS(BlockBase); DEFAULT_MEMBERS(BlockBase);
BlockBase(size_t size); 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> template <class OpFunction>
BlockResult<T> operate(const BlockBase& in); BlockResult<T> operate(const BlockBase& in);
@ -74,10 +70,6 @@ namespace MultiArrayHelper
DEFAULT_MEMBERS(MutableBlockBase); DEFAULT_MEMBERS(MutableBlockBase);
MutableBlockBase(size_t size); MutableBlockBase(size_t size);
MutableBlockBase& operator=(const BlockBase<T>& in);
virtual T& operator[](size_t pos) = 0;
}; };
template <typename T> template <typename T>
@ -85,16 +77,17 @@ namespace MultiArrayHelper
{ {
public: public:
DEFAULT_MEMBERS(Block); 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; BlockType type() const;
virtual const T& operator[](size_t pos) const override; const T& operator[](size_t pos) const;
virtual Block& set(size_t npos) override; Block& set(size_t npos);
virtual size_t stepSize() const override; size_t stepSize() const;
protected: protected:
const std::vector<T>* mData; const std::vector<T>* mData;
const T* mBegPtr; const T* mBegPtr;
size_t mStepSize;
}; };
template <typename T> template <typename T>
@ -102,102 +95,23 @@ namespace MultiArrayHelper
{ {
public: public:
DEFAULT_MEMBERS(MBlock); 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; template <class BlockClass>
virtual const T& operator[](size_t pos) const override; MBlock& operator=(const BlockClass& in);
virtual T& operator[](size_t pos) override;
virtual MBlock& set(size_t npos) override; BlockType type() const;
virtual size_t stepSize() const override; const T& operator[](size_t pos) const;
T& operator[](size_t pos);
MBlock& set(size_t npos);
size_t stepSize() const;
protected: protected:
std::vector<T>* mData; std::vector<T>* mData;
T* mBegPtr; 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> template <typename T>
class BlockResult : public MutableBlockBase<T> class BlockResult : public MutableBlockBase<T>
{ {
@ -206,11 +120,14 @@ namespace MultiArrayHelper
BlockResult(size_t size); BlockResult(size_t size);
virtual BlockType type() const override; template <class BlockClass>
virtual const T& operator[](size_t pos) const override; BlockResult& operator=(const BlockClass& in);
virtual T& operator[](size_t i) override;
virtual BlockResult& set(size_t npos) override; BlockType type() const;
virtual size_t stepSize() const override; const T& operator[](size_t pos) const;
T& operator[](size_t i);
BlockResult& set(size_t npos);
size_t stepSize() const;
protected: protected:
std::vector<T> mRes; std::vector<T> mRes;

View file

@ -58,31 +58,15 @@ namespace MultiArrayTools
} }
template <typename T> 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<Block<T> >(vec, 0, blockSize, stepSize);
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> 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<MBlock<T> >(vec, 0, blockSize, stepSize);
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);
}
} }
size_t getBTNum(const std::vector<BTSS>& mp, BlockType bt) 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, std::shared_ptr<IndexBase> seekBlockIndex(std::shared_ptr<IndexBase> ownIdx,
const OperationBase<T>& second) const OpClass& second)
{ {
std::vector<std::shared_ptr<IndexBase> > ivec; std::vector<std::shared_ptr<IndexBase> > ivec;
seekIndexInst(ownIdx, ivec); seekIndexInst(ownIdx, ivec);
@ -189,9 +173,9 @@ namespace MultiArrayTools
* OperationMaster * * OperationMaster *
*************************/ *************************/
template <typename T, class... Ranges> template <typename T, class OpClass, class... Ranges>
OperationMaster<T,Ranges...>:: OperationMaster<T,OpClass,Ranges...>::
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OperationBase<T>& second, OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index) : std::shared_ptr<typename CRange::IndexType>& index) :
mSecond(second), mArrayRef(ma), mIndex() mSecond(second), mArrayRef(ma), mIndex()
{ {
@ -211,30 +195,30 @@ namespace MultiArrayTools
} }
} }
template <typename T, class... Ranges> template <typename T, class OpClass, class... Ranges>
MutableBlockBase<T>& OperationMaster<T,Ranges...>::get() MBlock<T>& OperationMaster<T,OpClass,Ranges...>::get()
{ {
block(); block();
return *mBlockPtr; return *mBlockPtr;
} }
template <typename T, class... Ranges> template <typename T, class OpClass, class... Ranges>
const BlockBase<T>& OperationMaster<T,Ranges...>::get() const const Block<T>& OperationMaster<T,OpClass,Ranges...>::get() const
{ {
block(); block();
return *mBlockPtr; return *mBlockPtr;
} }
template <typename T, class... Ranges> template <typename T, class OpClass, class... Ranges>
std::vector<BTSS> OperationMaster<T,Ranges...>::block(const std::shared_ptr<IndexBase> blockIndex) const std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const std::shared_ptr<IndexBase> blockIndex) const
{ {
std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) ); std::vector<BTSS> btv(1, getBlockType(mIndex, blockIndex, true) );
mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max()); mBlockPtr = makeBlock(mArrayRef.datav(), btv[0].second, blockIndex->max());
return btv; return btv;
} }
template <typename T, class... Ranges> template <typename T, class OpClass, class... Ranges>
const OperationMaster<T,Ranges...>& OperationMaster<T,Ranges...>::block() const const OperationMaster<T,OpClass,Ranges...>& OperationMaster<T,OpClass,Ranges...>::block() const
{ {
mBlockPtr->set( mIndex->pos() ); mBlockPtr->set( mIndex->pos() );
return *this; return *this;
@ -248,14 +232,14 @@ namespace MultiArrayTools
ConstOperationRoot<T,Ranges...>:: ConstOperationRoot<T,Ranges...>::
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma, ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) : 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() ) ) mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
{ {
(*mIndex)(indices...); (*mIndex)(indices...);
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
const BlockBase<T>& ConstOperationRoot<T,Ranges...>::get() const const Block<T>& ConstOperationRoot<T,Ranges...>::get() const
{ {
block(); block();
return *mBlockPtr; return *mBlockPtr;
@ -284,27 +268,28 @@ namespace MultiArrayTools
OperationRoot<T,Ranges...>:: OperationRoot<T,Ranges...>::
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma, OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) : 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() ) ) mArrayRef(ma), mIndex( std::make_shared<IndexType>( mArrayRef.range() ) )
{ {
(*mIndex)(indices...); (*mIndex)(indices...);
} }
template <typename T, class... Ranges> 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> template <typename T, class... Ranges>
const BlockBase<T>& OperationRoot<T,Ranges...>::get() const const MBlock<T>& OperationRoot<T,Ranges...>::get() const
{ {
block(); block();
return *mBlockPtr; return *mBlockPtr;
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
MutableBlockBase<T>& OperationRoot<T,Ranges...>::get() MBlock<T>& OperationRoot<T,Ranges...>::get()
{ {
block(); block();
return *mBlockPtr; return *mBlockPtr;
@ -331,11 +316,11 @@ namespace MultiArrayTools
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
Operation<T,OpFunction,Ops...>::Operation(const Ops&... 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...) {} mOps(ops...) {}
template <typename T, class OpFunction, class... 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) ); mRes = std::move( PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mOps) );
return mRes; return mRes;

View file

@ -43,20 +43,20 @@ namespace MultiArrayTools
bool first, size_t higherStepSize = 1); bool first, size_t higherStepSize = 1);
template <typename T> 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> 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); 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<IndexBase>, std::vector<BTSS> >& mp,
BlockType bt); BlockType bt);
template <typename T> template <class OpClass>
std::shared_ptr<IndexBase> seekBlockIndex(std::shared_ptr<IndexBase> ownIdx, std::shared_ptr<IndexBase> seekBlockIndex(std::shared_ptr<IndexBase> ownIdx,
const OperationBase<T>& second); const OpClass& second);
/*
template <typename T> template <typename T>
class OperationBase class OperationBase
{ {
@ -71,7 +71,7 @@ namespace MultiArrayTools
virtual const OperationBase& block() const = 0; // update block virtual const OperationBase& block() const = 0; // update block
//virtual size_t argNum() const = 0; //virtual size_t argNum() const = 0;
virtual const BlockBase<T>& get() const = 0; virtual const Block<T>& get() const = 0;
}; };
template <typename T> template <typename T>
@ -82,10 +82,10 @@ namespace MultiArrayTools
MutableOperationBase() = default; MutableOperationBase() = default;
virtual MutableBlockBase<T>& get() = 0; virtual MBlock<T>& get() = 0;
}; };
*/
template <typename T, class OperationClass> template <typename T, class OperationClass>
class OperationTemplate class OperationTemplate
{ {
@ -113,8 +113,8 @@ namespace MultiArrayTools
OperationClass* mOc; OperationClass* mOc;
}; };
template <typename T, class... Ranges> template <typename T, class OpClass, class... Ranges>
class OperationMaster : public MutableOperationBase<T> class OperationMaster/* : public MutableOperationBase<T>*/
{ {
public: public:
@ -123,27 +123,27 @@ namespace MultiArrayTools
typedef ContainerRange<Ranges...> CRange; typedef ContainerRange<Ranges...> CRange;
typedef typename MultiRange<Ranges...>::IndexType IndexType; 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); std::shared_ptr<typename CRange::IndexType>& index);
virtual MutableBlockBase<T>& get() override; MBlock<T>& get();
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; std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
virtual const OperationMaster& block() const override; const OperationMaster& block() const;
protected: protected:
//void performAssignment(const OperationBase<T>& in); //void performAssignment(const OperationBase<T>& in);
OperationBase<T> const& mSecond; OpClass const& mSecond;
MutableMultiArrayBase<T,Ranges...>& mArrayRef; MutableMultiArrayBase<T,Ranges...>& mArrayRef;
std::shared_ptr<IndexType> mIndex; std::shared_ptr<IndexType> mIndex;
mutable std::shared_ptr<MutableBlockBase<T> > mBlockPtr; mutable std::shared_ptr<MBlock<T> > mBlockPtr;
}; };
template <typename T, class... Ranges> template <typename T, class... Ranges>
class ConstOperationRoot : public OperationBase<T>, class ConstOperationRoot : /*public OperationBase<T>,*/
public OperationTemplate<T,ConstOperationRoot<T,Ranges...> > public OperationTemplate<T,ConstOperationRoot<T,Ranges...> >
{ {
public: public:
@ -157,20 +157,20 @@ namespace MultiArrayTools
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma, ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices); 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; std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
virtual const ConstOperationRoot& block() const override; const ConstOperationRoot& block() const;
protected: protected:
MultiArrayBase<T,Ranges...> const& mArrayRef; MultiArrayBase<T,Ranges...> const& mArrayRef;
std::shared_ptr<IndexType> mIndex; std::shared_ptr<IndexType> mIndex;
mutable std::shared_ptr<BlockBase<T> > mBlockPtr; mutable std::shared_ptr<Block<T> > mBlockPtr;
}; };
template <typename T, class... Ranges> template <typename T, class... Ranges>
class OperationRoot : public MutableOperationBase<T>, class OperationRoot : /*public MutableOperationBase<T>,*/
public OperationTemplate<T,OperationRoot<T,Ranges...> > public OperationTemplate<T,OperationRoot<T,Ranges...> >
{ {
public: public:
@ -184,23 +184,24 @@ namespace MultiArrayTools
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma, OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices); 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; const MBlock<T>& get() const;
virtual MutableBlockBase<T>& get() override; MBlock<T>& get();
virtual std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const override; std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
virtual const OperationRoot& block() const override; const OperationRoot& block() const;
protected: protected:
MutableMultiArrayBase<T,Ranges...>& mArrayRef; MutableMultiArrayBase<T,Ranges...>& mArrayRef;
std::shared_ptr<IndexType> mIndex; 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> 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 OperationTemplate<T,Operation<T,OpFunction,Ops...> >
{ {
public: public:
@ -212,10 +213,10 @@ namespace MultiArrayTools
Operation(const Ops&... ops); 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; std::vector<BTSS> block(const std::shared_ptr<IndexBase> blockIndex) const;
virtual const Operation& block() const override; const Operation& block() const;
protected: protected:
std::tuple<Ops...> mOps; std::tuple<Ops...> mOps;

View file

@ -408,7 +408,7 @@ namespace MultiArrayHelper
{ {
static_assert(sizeof...(Args) == std::tuple_size<ArgTuple>::value-1, static_assert(sizeof...(Args) == std::tuple_size<ArgTuple>::value-1,
"inconsistent number of arguments"); "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...); return f(std::get<0>(tp).get(), args...);
} }