remove unused code + BlockArray

This commit is contained in:
Christian Zimmermann 2018-01-03 17:39:45 +01:00
parent 358f327a63
commit 2116abc556
3 changed files with 103 additions and 76 deletions

View file

@ -51,7 +51,8 @@ namespace MultiArrayHelper
BLOCK = 1, BLOCK = 1,
VALUE = 2, VALUE = 2,
SPLIT = 3, SPLIT = 3,
RESULT = 4 RESULT = 4,
ARRAY = 5
}; };

View file

@ -19,7 +19,7 @@ namespace MultiArrayHelper
{ {
public: public:
BlockBinaryOp(BlockResult<T>& mRes); BlockBinaryOp(BlockResult<T>& mRes);
void operator()(const BlockClass1& arg1, const BlockClass2& arg2); BlockResult<T>& operator()(const BlockClass1& arg1, const BlockClass2& arg2);
private: private:
BlockResult<T>& mRes; BlockResult<T>& mRes;
}; };
@ -29,11 +29,20 @@ namespace MultiArrayHelper
{ {
public: public:
BlockBinaryOpSelf(BlockResult<T>& res); BlockBinaryOpSelf(BlockResult<T>& res);
void operator()(const BlockClass& arg); BlockResult<T>& operator()(const BlockClass& arg);
private: private:
BlockResult<T>& mRes; BlockResult<T>& mRes;
}; };
template <typename T, class OpFunc, class BlockClass>
class BlockContraction
{
public:
BlockContraction(T& res);
T& operator()(const BlockClass& arg);
private:
T& mRes;
};
// EVERYTHING IN HERE MUST N O T BE VITUAL !! // EVERYTHING IN HERE MUST N O T BE VITUAL !!
@ -112,6 +121,26 @@ namespace MultiArrayHelper
size_t mStepSize; size_t mStepSize;
}; };
template <class BlockClass>
class BlockArray : public BlockBase<BlockClass>
{
DEFAULT_MEMBERS(BlockArray);
template <typename... Args>
BlockArray(size_t stepSize, const Args&... args);
BlockType type() const;
BlockClass& operator[](size_t pos);
BlockArray& set(size_t npos);
size_t stepSize() const;
protected:
BlockClass mBlock;
size_t mStepSize; // total stepSize !!
};
template <typename T> template <typename T>
class MBlock : public MutableBlockBase<T> class MBlock : public MutableBlockBase<T>
{ {
@ -148,14 +177,16 @@ namespace MultiArrayHelper
BlockResult& operator=(const BlockResult& in); BlockResult& operator=(const BlockResult& in);
BlockResult& operator=(BlockResult&& in); BlockResult& operator=(BlockResult&& in);
BlockResult(size_t size); template <typename... ArgTypes>
BlockResult(size_t size, const ArgTypes&... args);
~BlockResult(); ~BlockResult();
template <class BlockClass> template <class BlockClass>
BlockResult& operator=(const BlockClass& in); BlockResult& operator=(const BlockClass& in);
BlockResult& init(size_t size); template <typename... Args>
BlockResult& init(size_t size, const Args&... args);
BlockType type() const; BlockType type() const;
const T& operator[](size_t pos) const; const T& operator[](size_t pos) const;
@ -184,29 +215,45 @@ namespace MultiArrayHelper
BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::BlockBinaryOp(BlockResult<T>& res) : mRes(res) {} BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::BlockBinaryOp(BlockResult<T>& res) : mRes(res) {}
template <typename T, class OpFunc, class BlockClass1, class BlockClass2> template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
void BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::operator()(const BlockClass1& arg1, BlockResult<T>& BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::operator()(const BlockClass1& arg1,
const BlockClass2& arg2) const BlockClass2& arg2)
{ {
static OpFunc f; static OpFunc f;
assert(mRes.init() and arg1.init() and arg2.init()); //assert(mRes.init() and arg1.init() and arg2.init());
assert(arg1.size() == arg2.size()); //assert(arg1.size() == arg2.size());
for(size_t i = 0; i != arg1.size(); ++i){ for(size_t i = 0; i != arg1.size(); ++i){
mRes[i] = f(arg1[i], arg2[i]); mRes[i] = f(arg1[i], arg2[i]);
} }
return mRes;
} }
template <typename T, class OpFunc, class BlockClass> template <typename T, class OpFunc, class BlockClass>
BlockBinaryOpSelf<T,OpFunc,BlockClass>::BlockBinaryOpSelf(BlockResult<T>& res) : mRes(res) {} BlockBinaryOpSelf<T,OpFunc,BlockClass>::BlockBinaryOpSelf(BlockResult<T>& res) : mRes(res) {}
template <typename T, class OpFunc, class BlockClass> template <typename T, class OpFunc, class BlockClass>
void BlockBinaryOpSelf<T,OpFunc,BlockClass>::operator()(const BlockClass& arg) BlockResult<T>& BlockBinaryOpSelf<T,OpFunc,BlockClass>::operator()(const BlockClass& arg)
{ {
static OpFunc f; static OpFunc f;
assert(mRes.init() and arg.init()); //assert(mRes.init() and arg.init());
assert(mRes.size() == arg.size()); //assert(mRes.size() == arg.size());
for(size_t i = 0; i != arg.size(); ++i){ for(size_t i = 0; i != arg.size(); ++i){
mRes[i] = f(mRes[i], arg[i]); mRes[i] = f(mRes[i], arg[i]);
} }
return mRes;
}
template <typename T, class OpFunc, class BlockClass>
BlockContraction<T,OpFunc,BlockClass>::BlockContraction(T& res) : mRes(res) {}
template <typename T, class OpFunc, class BlockClass>
T& BlockContraction<T,OpFunc,BlockClass>::operator()(const BlockClass& arg)
{
static OpFunc f;
for(size_t i = 0; i != arg.size(); ++i){
mRes = f(mRes, arg[i]);
}
return mRes;
} }
@ -275,6 +322,42 @@ namespace MultiArrayHelper
{ {
return 1; return 1;
} }
/******************
* BlockArray *
******************/
template <class BlockClass>
template <typename... Args>
BlockArray<BlockClass>::BlockArray(size_t stepSize, const Args&... args) :
mBlock(args...), mStepSize(stepSize) {}
template <class BlockClass>
BlockType BlockArray<BlockClass>::type() const
{
return BlockType::ARRAY;
}
template <class BlockClass>
BlockClass& BlockArray<BlockClass>::operator[](size_t pos)
{
return mBlock.set(mStepSize * pos);
}
template <class BlockClass>
BlockArray<BlockClass>& BlockArray<BlockClass>::set(size_t npos)
{
mBlock.set(npos);
return *this;
}
template <class BlockClass>
size_t BlockArray<BlockClass>::stepSize() const
{
return mStepSize;
}
/************** /**************
* MBlock * * MBlock *
@ -390,11 +473,12 @@ namespace MultiArrayHelper
} }
template <typename T> template <typename T>
BlockResult<T>::BlockResult(size_t size) : template <typename... ArgTypes>
BlockResult<T>::BlockResult(size_t size, const ArgTypes&... args) :
MutableBlockBase<T>(size) MutableBlockBase<T>(size)
{ {
if(BB::mInit){ if(BB::mInit){
mResPtr = new T[BB::mSize]; mResPtr = new T[BB::mSize](args...);
} }
for(size_t i = 0; i != BB::mSize; ++i){ for(size_t i = 0; i != BB::mSize; ++i){
mResPtr[i] = static_cast<T>( 0 ); mResPtr[i] = static_cast<T>( 0 );
@ -451,15 +535,16 @@ namespace MultiArrayHelper
{ {
return 1; return 1;
} }
template <typename T> template <typename T>
BlockResult<T>& BlockResult<T>::init(size_t size) template <typename... Args>
BlockResult<T>& BlockResult<T>::init(size_t size, const Args&... args)
{ {
BB::mSize = size; BB::mSize = size;
delete[] mResPtr; delete[] mResPtr;
if(BB::mSize != 0){ if(BB::mSize != 0){
BB::mInit = true; BB::mInit = true;
mResPtr = new T[BB::mSize]; mResPtr = new T[BB::mSize](args...);
} }
else { else {
BB::mInit = false; BB::mInit = false;

View file

@ -110,7 +110,6 @@ 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<VIWB> blockIndex, bool init = false) const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const OperationMaster& block() const; const OperationMaster& block() const;
@ -143,7 +142,6 @@ namespace MultiArrayTools
const Block<T>& get() const; const Block<T>& get() const;
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex, bool init = false) const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const ConstOperationRoot& block() const; const ConstOperationRoot& block() const;
@ -183,7 +181,6 @@ namespace MultiArrayTools
OperationRoot& set(const IndexInfo* blockIndex); OperationRoot& set(const IndexInfo* blockIndex);
OperationRoot& set(std::shared_ptr<VIWB> blockIndex); OperationRoot& set(std::shared_ptr<VIWB> blockIndex);
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex, bool init = false) const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const OperationRoot& block() const; const OperationRoot& block() const;
@ -216,7 +213,6 @@ namespace MultiArrayTools
const BlockResult<T>& get() const; const BlockResult<T>& get() const;
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex, bool init = false) const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const Operation& block() const; const Operation& block() const;
@ -237,7 +233,6 @@ namespace MultiArrayTools
const BlockResult<T>& get() const; const BlockResult<T>& get() const;
std::vector<BTSS> block(const std::shared_ptr<VIWB> blockIndex, bool init = false) const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const Contraction& block() const; const Contraction& block() const;
@ -429,16 +424,6 @@ namespace MultiArrayTools
return mBlock; return mBlock;
} }
template <typename T, class OpClass, class... Ranges>
std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const std::shared_ptr<VIWB> blockIndex, bool init) const
{
std::vector<BTSS> btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) );
if(init){
mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
}
return btv;
}
template <typename T, class OpClass, class... Ranges> template <typename T, class OpClass, class... Ranges>
std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -487,17 +472,6 @@ namespace MultiArrayTools
return mBlock; return mBlock;
} }
template <typename T, class... Ranges>
std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const std::shared_ptr<VIWB> blockIndex, bool init) const
{
assert(0);
std::vector<BTSS> btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) );
if(init){
mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
}
return btv;
}
template <typename T, class... Ranges> template <typename T, class... Ranges>
std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -581,18 +555,6 @@ namespace MultiArrayTools
return *this; return *this;
} }
template <typename T, class... Ranges>
std::vector<BTSS> OperationRoot<T,Ranges...>::block(const std::shared_ptr<VIWB> blockIndex, bool init) const
{
assert(0);
std::vector<BTSS> btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) );
if(init){
mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
}
return btv;
}
template <typename T, class... Ranges> template <typename T, class... Ranges>
std::vector<BTSS> OperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> OperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -626,18 +588,6 @@ namespace MultiArrayTools
return mRes; return mRes;
} }
template <typename T, class OpFunction, class... Ops>
std::vector<BTSS> Operation<T,OpFunction,Ops...>::block(const std::shared_ptr<VIWB> blockIndex, bool init) const
{
assert(0);
std::vector<BTSS> btv;
PackNum<sizeof...(Ops)-1>::makeBlockTypeVec(btv, mOps, blockIndex, init);
if(init){
mRes.init(blockIndex->max());
}
return btv;
}
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
std::vector<BTSS> Operation<T,OpFunction,Ops...>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> Operation<T,OpFunction,Ops...>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -676,15 +626,6 @@ namespace MultiArrayTools
} }
return mRes; return mRes;
} }
template <typename T, class Op, class IndexType>
std::vector<BTSS> Contraction<T,Op,IndexType>::block(const std::shared_ptr<VIWB> blockIndex, bool init) const
{
if(init){
mRes.init(blockIndex->max());
}
return mOp.block(blockIndex, init);
}
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
std::vector<BTSS> Contraction<T,Op,IndexType>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> Contraction<T,Op,IndexType>::block(const IndexInfo* blockIndex, bool init) const