diff --git a/src/block.cc b/src/block.cc index a06bbd0..03d045e 100644 --- a/src/block.cc +++ b/src/block.cc @@ -26,11 +26,35 @@ namespace MultiArrayHelper OpFunction f; BlockResult res(mSize); for(size_t i = 0; i != mSize; ++i){ - res[i] = f(this->operator[](i), in[i]); + res[i] = f((*this)[i], in[i]); } return res; } + template + BlockResult BlockBase::operator+(const BlockBase& in) + { + return operate >(in); + } + + template + BlockResult BlockBase::operator-(const BlockBase& in) + { + return operate >(in); + } + + template + BlockResult BlockBase::operator*(const BlockBase& in) + { + return operate >(in); + } + + template + BlockResult BlockBase::operator/(const BlockBase& in) + { + return operate >(in); + } + /************* * Block * *************/ @@ -52,6 +76,13 @@ namespace MultiArrayHelper { return *(mBegPtr + i); } + + template + Block& Block::set(const T* nbeg) + { + mBegPtr = nbeg; + return *this; + } /****************** * BlockValue * @@ -73,26 +104,42 @@ namespace MultiArrayHelper { return mVal; } - + + template + BlockValue& BlockValue::set(const T* nbeg) + { + mVal = *nbeg; + return *this; + } + /****************** * SplitBlock * ******************/ template - SplitBlock::SplitBlock(std::vector&& begPtrVec) : - BlockBase(begPtrVec.size()), - mBegPtr(begPtrVec) {} + SplitBlock::SplitBlock(const std::vector& data, size_t begPos, + size_t stepSize, size_t size) : + BlockBase(size), + mStepSize(stepSize), + mBegPtr(data.data() + begPos) {} template BlockType SplitBlock::type() const { return BlockType::SPLIT; } + + template + const T& SplitBlock::operator[](size_t pos) const + { + return *(mBegPtr + pos*mStepSize); + } template - const T& SplitBlock::operator[](size_t i) const + SplitBlock& SplitBlock::set(const T* nbeg) { - return *(mBegPtrVec[i]); + mBegPtr = nbeg; + return *this; } /******************* @@ -122,6 +169,10 @@ namespace MultiArrayHelper return mRes[i]; } - + template + BlockResult& BlockResult::set(const T* nbeg) + { + return *this; + } } // end namespace MultiArrayHelper diff --git a/src/block.h b/src/block.h index fddf7e3..df7a324 100644 --- a/src/block.h +++ b/src/block.h @@ -16,7 +16,7 @@ namespace MultiArrayHelper BLOCK = 1, VALUE = 2, SPLIT = 3, - RESULT = 4 + RESULT = 4, }; // manage vectorization in the future !! @@ -33,8 +33,15 @@ namespace MultiArrayHelper virtual size_t size() const; virtual const T& operator[](size_t pos) const = 0; + virtual BlockBase& set(const T* nbeg) = 0; + template BlockResult operate(const BlockBase& in); + + BlockResult operator+(const BlockBase& in); + BlockResult operator-(const BlockBase& in); + BlockResult operator*(const BlockBase& in); + BlockResult operator/(const BlockBase& in); protected: size_t mSize; @@ -49,9 +56,10 @@ namespace MultiArrayHelper virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; - + virtual Block& set(const T* nbeg) override; + protected: - T* mBegPtr; + const T* mBegPtr; }; template @@ -63,28 +71,29 @@ namespace MultiArrayHelper virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; - - virtual BlockBase& set(size_t begPos) override; + virtual BlockValue& set(const T* nbeg) override; protected: T mVal; }; + template class SplitBlock : public BlockBase { public: SplitBlock() = default; - SplitBlock(std::vector&& begPtrVec); + SplitBlock(const std::vector& 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 BlockBase& set(size_t begPos) override; + virtual SplitBlock& set(const T* nbeg) override; protected: - std::vector mBegPtrVec; + size_t mStepSize; + const T* mBegPtr; }; template @@ -97,8 +106,7 @@ namespace MultiArrayHelper virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual T& operator[](size_t i); - - virtual BlockBase& set(size_t begPos) override; + virtual BlockResult& set(const T* nbeg) override; protected: std::vector mRes; diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index 7ca9321..a540870 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -26,33 +26,33 @@ namespace MultiArrayTools template template auto OperationTemplate::operator+(const Second& in) const - -> Operation,OperationClass,Second> + -> Operation,OperationClass,Second> { - return Operation,OperationClass,Second>(*mOc, in); + return Operation,OperationClass,Second>(*mOc, in); } template template auto OperationTemplate::operator-(const Second& in) const - -> Operation,OperationClass,Second> + -> Operation,OperationClass,Second> { - return Operation,OperationClass,Second>(*mOc, in); + return Operation,OperationClass,Second>(*mOc, in); } template template auto OperationTemplate::operator*(const Second& in) const - -> Operation,OperationClass,Second> + -> Operation,OperationClass,Second> { - return Operation,OperationClass,Second>(*mOc, in); + return Operation,OperationClass,Second>(*mOc, in); } template template auto OperationTemplate::operator/(const Second& in) const - -> Operation,OperationClass,Second> + -> Operation,OperationClass,Second> { - return Operation,OperationClass,Second>(*mOc, in); + return Operation,OperationClass,Second>(*mOc, in); } /************************* @@ -76,13 +76,13 @@ namespace MultiArrayTools } template - BlockBase& OperationMaster::get(const IndexBase& ind) + BlockBase& OperationMaster::get() { return mArrayRef.data()[ mIndex->pos() ]; } template - const BlockBase& OperationMaster::get(const IndexBase& ind) const + const BlockBase& OperationMaster::get() const { return mArrayRef.data()[ mIndex->pos() ]; } @@ -102,7 +102,7 @@ namespace MultiArrayTools } template - const BlockBase& ConstOperationRoot::get(const IndexBase& ind) const + const BlockBase& ConstOperationRoot::get() const { return mArrayRef[ (*mIndex)() ]; } @@ -128,13 +128,13 @@ namespace MultiArrayTools } template - const BlockBase& OperationRoot::get(const IndexBase& ind) const + const BlockBase& OperationRoot::get() const { return mArrayRef[ (*mIndex)() ]; } template - BlockBase& OperationRoot::get(const IndexBase& ind) + BlockBase& OperationRoot::get() { return mArrayRef[ (*mIndex)() ]; } @@ -149,7 +149,7 @@ namespace MultiArrayTools mOps(ops...) {} template - const BlockBase& Operation::get(const IndexBase& ind) const + const BlockBase& Operation::get() const { mRes = PackNum::template unpackArgs(mOps); return mRes; diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 01b1261..ed0612d 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -43,7 +43,7 @@ namespace MultiArrayTools virtual OperationBase& block(const std::shared_ptr& blockIndex) = 0; //virtual size_t argNum() const = 0; - virtual const BlockBase& get(const IndexBase& ind) const = 0; + virtual const BlockBase& get() const = 0; protected: mutable std::shared_ptr mBlockPtr; @@ -53,9 +53,10 @@ namespace MultiArrayTools class MutableOperationBase : public OperationBase { public: - + typedef T value_type; + MutableOperationBase() = default; - virtual BlockBase& get(const IndexBase& ind) = 0; + virtual BlockBase& get() = 0; }; template @@ -63,23 +64,25 @@ namespace MultiArrayTools { public: + typedef typename OperationClass::value_type value_type; + OperationTemplate(OperationClass* oc); template auto operator+(const Second& in) const - -> Operation,OperationClass,Second>; + -> Operation,OperationClass,Second>; template auto operator-(const Second& in) const - -> Operation,OperationClass,Second>; + -> Operation,OperationClass,Second>; template auto operator*(const Second& in) const - -> Operation,OperationClass,Second>; + -> Operation,OperationClass,Second>; template auto operator/(const Second& in) const - -> Operation,OperationClass,Second>; + -> Operation,OperationClass,Second>; private: OperationClass* mOc; @@ -90,6 +93,7 @@ namespace MultiArrayTools { public: + typedef T value_type; typedef OperationBase OB; typedef ContainerRange CRange; typedef typename MultiRange::IndexType IndexType; @@ -97,8 +101,8 @@ namespace MultiArrayTools OperationMaster(MutableMultiArrayBase& ma, const OperationBase& second, std::shared_ptr& index); - virtual BlockBase& get(const IndexBase& ind) override; - virtual const BlockBase& get(const IndexBase& ind) const override; + virtual BlockBase& get() override; + virtual const BlockBase& get() const override; protected: @@ -114,7 +118,8 @@ namespace MultiArrayTools public OperationTemplate > { public: - + + typedef T value_type; typedef OperationBase OB; typedef OperationTemplate > OT; typedef ContainerRange CRange; @@ -123,7 +128,7 @@ namespace MultiArrayTools ConstOperationRoot(const MultiArrayBase& ma, const std::shared_ptr&... indices); - virtual const BlockBase& get(const IndexBase& ind) const override; + virtual const BlockBase& get() const override; protected: @@ -136,7 +141,8 @@ namespace MultiArrayTools public OperationTemplate > { public: - + + typedef T value_type; typedef OperationBase OB; typedef OperationTemplate > OT; typedef ContainerRange CRange; @@ -147,8 +153,8 @@ namespace MultiArrayTools OperationMaster operator=(const OperationBase& in); - virtual const BlockBase& get(const IndexBase& ind) const override; - virtual BlockBase& get(const IndexBase& ind) override; + virtual const BlockBase& get() const override; + virtual BlockBase& get() override; protected: @@ -161,14 +167,15 @@ namespace MultiArrayTools public OperationTemplate > { public: - + + typedef T value_type; typedef OperationBase OB; typedef OperationTemplate > OT; typedef OpFunction F; Operation(const Ops&... ops); - virtual const BlockBase& get(const IndexBase& ind) const override; + virtual const BlockBase& get() const override; protected: std::tuple mOps;