From 2116abc556214447699891e879b753c1e6cf91f4 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 3 Jan 2018 17:39:45 +0100 Subject: [PATCH] remove unused code + BlockArray --- src/block/bbase_def.h | 3 +- src/block/block.h | 117 +++++++++++++++++++++++++++++++----- src/multi_array_operation.h | 59 ------------------ 3 files changed, 103 insertions(+), 76 deletions(-) diff --git a/src/block/bbase_def.h b/src/block/bbase_def.h index 129dcd2..63f0ece 100644 --- a/src/block/bbase_def.h +++ b/src/block/bbase_def.h @@ -51,7 +51,8 @@ namespace MultiArrayHelper BLOCK = 1, VALUE = 2, SPLIT = 3, - RESULT = 4 + RESULT = 4, + ARRAY = 5 }; diff --git a/src/block/block.h b/src/block/block.h index be046d8..f097a27 100644 --- a/src/block/block.h +++ b/src/block/block.h @@ -19,7 +19,7 @@ namespace MultiArrayHelper { public: BlockBinaryOp(BlockResult& mRes); - void operator()(const BlockClass1& arg1, const BlockClass2& arg2); + BlockResult& operator()(const BlockClass1& arg1, const BlockClass2& arg2); private: BlockResult& mRes; }; @@ -29,11 +29,20 @@ namespace MultiArrayHelper { public: BlockBinaryOpSelf(BlockResult& res); - void operator()(const BlockClass& arg); + BlockResult& operator()(const BlockClass& arg); private: BlockResult& mRes; }; + template + class BlockContraction + { + public: + BlockContraction(T& res); + T& operator()(const BlockClass& arg); + private: + T& mRes; + }; // EVERYTHING IN HERE MUST N O T BE VITUAL !! @@ -112,6 +121,26 @@ namespace MultiArrayHelper size_t mStepSize; }; + template + class BlockArray : public BlockBase + { + + DEFAULT_MEMBERS(BlockArray); + + template + 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 class MBlock : public MutableBlockBase { @@ -148,14 +177,16 @@ namespace MultiArrayHelper BlockResult& operator=(const BlockResult& in); BlockResult& operator=(BlockResult&& in); - BlockResult(size_t size); - + template + BlockResult(size_t size, const ArgTypes&... args); + ~BlockResult(); template BlockResult& operator=(const BlockClass& in); - BlockResult& init(size_t size); + template + BlockResult& init(size_t size, const Args&... args); BlockType type() const; const T& operator[](size_t pos) const; @@ -184,29 +215,45 @@ namespace MultiArrayHelper BlockBinaryOp::BlockBinaryOp(BlockResult& res) : mRes(res) {} template - void BlockBinaryOp::operator()(const BlockClass1& arg1, + BlockResult& BlockBinaryOp::operator()(const BlockClass1& arg1, const BlockClass2& arg2) { static OpFunc f; - assert(mRes.init() and arg1.init() and arg2.init()); - assert(arg1.size() == arg2.size()); + //assert(mRes.init() and arg1.init() and arg2.init()); + //assert(arg1.size() == arg2.size()); for(size_t i = 0; i != arg1.size(); ++i){ mRes[i] = f(arg1[i], arg2[i]); } + return mRes; } template BlockBinaryOpSelf::BlockBinaryOpSelf(BlockResult& res) : mRes(res) {} template - void BlockBinaryOpSelf::operator()(const BlockClass& arg) + BlockResult& BlockBinaryOpSelf::operator()(const BlockClass& arg) { static OpFunc f; - assert(mRes.init() and arg.init()); - assert(mRes.size() == arg.size()); + //assert(mRes.init() and arg.init()); + //assert(mRes.size() == arg.size()); for(size_t i = 0; i != arg.size(); ++i){ mRes[i] = f(mRes[i], arg[i]); } + return mRes; + } + + template + BlockContraction::BlockContraction(T& res) : mRes(res) {} + + template + T& BlockContraction::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; } + + + /****************** + * BlockArray * + ******************/ + + template + template + BlockArray::BlockArray(size_t stepSize, const Args&... args) : + mBlock(args...), mStepSize(stepSize) {} + + template + BlockType BlockArray::type() const + { + return BlockType::ARRAY; + } + + template + BlockClass& BlockArray::operator[](size_t pos) + { + return mBlock.set(mStepSize * pos); + } + + template + BlockArray& BlockArray::set(size_t npos) + { + mBlock.set(npos); + return *this; + } + + template + size_t BlockArray::stepSize() const + { + return mStepSize; + } + /************** * MBlock * @@ -390,11 +473,12 @@ namespace MultiArrayHelper } template - BlockResult::BlockResult(size_t size) : + template + BlockResult::BlockResult(size_t size, const ArgTypes&... args) : MutableBlockBase(size) { if(BB::mInit){ - mResPtr = new T[BB::mSize]; + mResPtr = new T[BB::mSize](args...); } for(size_t i = 0; i != BB::mSize; ++i){ mResPtr[i] = static_cast( 0 ); @@ -451,15 +535,16 @@ namespace MultiArrayHelper { return 1; } - + template - BlockResult& BlockResult::init(size_t size) + template + BlockResult& BlockResult::init(size_t size, const Args&... args) { BB::mSize = size; delete[] mResPtr; if(BB::mSize != 0){ BB::mInit = true; - mResPtr = new T[BB::mSize]; + mResPtr = new T[BB::mSize](args...); } else { BB::mInit = false; diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 37eadce..c18234b 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -110,7 +110,6 @@ namespace MultiArrayTools MBlock& get(); const Block& get() const; - std::vector block(const std::shared_ptr blockIndex, bool init = false) const; std::vector block(const IndexInfo* blockIndex, bool init = false) const; const OperationMaster& block() const; @@ -143,7 +142,6 @@ namespace MultiArrayTools const Block& get() const; - std::vector block(const std::shared_ptr blockIndex, bool init = false) const; std::vector block(const IndexInfo* blockIndex, bool init = false) const; const ConstOperationRoot& block() const; @@ -183,7 +181,6 @@ namespace MultiArrayTools OperationRoot& set(const IndexInfo* blockIndex); OperationRoot& set(std::shared_ptr blockIndex); - std::vector block(const std::shared_ptr blockIndex, bool init = false) const; std::vector block(const IndexInfo* blockIndex, bool init = false) const; const OperationRoot& block() const; @@ -216,7 +213,6 @@ namespace MultiArrayTools const BlockResult& get() const; - std::vector block(const std::shared_ptr blockIndex, bool init = false) const; std::vector block(const IndexInfo* blockIndex, bool init = false) const; const Operation& block() const; @@ -237,7 +233,6 @@ namespace MultiArrayTools const BlockResult& get() const; - std::vector block(const std::shared_ptr blockIndex, bool init = false) const; std::vector block(const IndexInfo* blockIndex, bool init = false) const; const Contraction& block() const; @@ -429,16 +424,6 @@ namespace MultiArrayTools return mBlock; } - template - std::vector OperationMaster::block(const std::shared_ptr blockIndex, bool init) const - { - std::vector btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) ); - if(init){ - mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max()); - } - return btv; - } - template std::vector OperationMaster::block(const IndexInfo* blockIndex, bool init) const { @@ -487,17 +472,6 @@ namespace MultiArrayTools return mBlock; } - template - std::vector ConstOperationRoot::block(const std::shared_ptr blockIndex, bool init) const - { - assert(0); - std::vector btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) ); - if(init){ - mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max()); - } - return btv; - } - template std::vector ConstOperationRoot::block(const IndexInfo* blockIndex, bool init) const { @@ -581,18 +555,6 @@ namespace MultiArrayTools return *this; } - - template - std::vector OperationRoot::block(const std::shared_ptr blockIndex, bool init) const - { - assert(0); - std::vector btv(1, getBlockType( make_viwb( mIndex ), blockIndex, true) ); - if(init){ - mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max()); - } - return btv; - } - template std::vector OperationRoot::block(const IndexInfo* blockIndex, bool init) const { @@ -626,18 +588,6 @@ namespace MultiArrayTools return mRes; } - template - std::vector Operation::block(const std::shared_ptr blockIndex, bool init) const - { - assert(0); - std::vector btv; - PackNum::makeBlockTypeVec(btv, mOps, blockIndex, init); - if(init){ - mRes.init(blockIndex->max()); - } - return btv; - } - template std::vector Operation::block(const IndexInfo* blockIndex, bool init) const { @@ -676,15 +626,6 @@ namespace MultiArrayTools } return mRes; } - - template - std::vector Contraction::block(const std::shared_ptr blockIndex, bool init) const - { - if(init){ - mRes.init(blockIndex->max()); - } - return mOp.block(blockIndex, init); - } template std::vector Contraction::block(const IndexInfo* blockIndex, bool init) const