From 6126188ed0dbb531960504086b7ba0f5d95321ad Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 26 Mar 2017 16:55:52 +0200 Subject: [PATCH] start implementing map and functional array --- src/multi_array.h | 22 +++++++++++++ src/multi_array_operation.cc | 60 ++++++++++++++++++++++++++++++++++++ src/multi_array_operation.h | 41 +++++++++++++++--------- 3 files changed, 108 insertions(+), 15 deletions(-) diff --git a/src/multi_array.h b/src/multi_array.h index ee2dada..d31d1b2 100644 --- a/src/multi_array.h +++ b/src/multi_array.h @@ -211,6 +211,8 @@ namespace MultiArrayTools template MultiArray(const MultiArray,Range3> in); + // implement contstructor using FunctionalMultiArray as Input !!! + template MultiArray& operator=(const MultiArray,Range3> in); @@ -231,6 +233,26 @@ namespace MultiArrayTools std::vector mCont; }; + template + class FunctionalMultiArray : public MultiArrayBase + { + public: + typedef MultiArrayBase MAB; + typedef typename MultiArrayBase::const_iterator const_iterator; + + DEFAULT_MEMBERS(FunctionalMultiArray); + FunctionalMultiArray(const Range& range, /*Function*/); + + T& operator[](const typename Range::IndexType& i) override; + const T& operator[](const typename Range::IndexType& i) const override; + + virtual bool isConst() const override; + virtual bool isSlice() const override; + + protected: + // FUNCTION !!!! + }; + } #include "multi_array.cc" diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index 151c354..0b65ea4 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -513,6 +513,66 @@ namespace MultiArrayTools MAOB::mIibPtr->name(mNm); } + /******************************** + * MultiArrayOperationMap * + ********************************/ + + template + MultiArrayOperationMap:: + MultiArrayOperationMap(MultiArrayOperationRoot& root, const MapFunction mf) : + MultiArrayOperationBase(), + mMF(mf), + mRoot(root) + //mIndex(mArrayRef.beginIndex()), + //mNm(nm) + { + MAOB::mIibPtr = &mIndex; + //MAOB::mIibPtr->name(nm); + //mIndex.name(nm); + } + + template + MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot& in) + { + mIndex = dynamic_cast( in.getIndex() ); + MAOB::mIibPtr = &mIndex; + mNm = in.name(); + mIndex.setPos( mIndex.max() ); + typename OutRange::IndexType endIndex = mIndex; + + // Implement Map Functions !!!! + mRoot.linkIndicesTo( &mMF.index() ); + mMF.linkIndicesTo( &mIndex ); + + MultiArray cnt(mRoot->range()); + auto cnto = cnt(mRoot.name(), true); + cnto.linkIndicesTo( &mMF.index() ) + + for(mIndex.setPos(0); mIndex != endIndex; ++mIndex){ + mRoot.get() += in.get(); + ++cnto.get(); + } + mRoot /= cnto; + } + + template + virtual size_t argNum() const override; + + template + virtual IndefinitIndexBase* getLinked(const std::string& name) const override; + + template + virtual void linkIndicesTo(IndefinitIndexBase* target) const override; + + template + virtual void setInternalLinks() const override; + + template + virtual const T& get() const override; + + template + virtual T& get() override; + /***************************** * MultiArrayOperation * diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 33da214..ad2dd8f 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -154,13 +154,6 @@ namespace MultiArrayTools void performAssignment(const MultiArrayOperationBase& in); - /* - template - MultiArrayOperationRoot& makeSlice(MultiArrayOperationRoot& in); - - template - const MultiArrayOperationRoot& makeConstSlice(const MultiArrayOperationRoot& in); - */ MutableMultiArrayBase& mArrayRef; mutable IndexType mIndex; Name mNm; @@ -238,19 +231,37 @@ namespace MultiArrayTools protected: - /* - template - const ConstMultiArrayOperationRoot& makeConstSlice(const ConstMultiArrayOperationRoot& in); - - template - const ConstMultiArrayOperationRoot& makeConstSlice(const MultiArrayOperationRoot& in); - */ - // const MultiArrayBase const& mArrayRef; mutable IndexType mIndex; Name mNm; }; + template + class MultiArrayOperationMap : public MutableMultiArrayOperationBase + { + public: + typedef MultiArrayOperationBase MAOB; + + MultiArrayOperationMap(MultiArrayOperationRoot& root, const MapFunction mf); + MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot& in); + + virtual size_t argNum() const override; + + virtual IndefinitIndexBase* getLinked(const std::string& name) const override; + virtual void linkIndicesTo(IndefinitIndexBase* target) const override; + + virtual void setInternalLinks() const override; + + virtual const T& get() const override; + virtual T& get() override; + // !!!! + protected: + MapFunction mMF; + MultiArrayOperationRoot& mRoot; + mutable IndexType mIndex; // Index of incoming range + Name mNm; // Name of incoming range + }; + template class MultiArrayOperation : public MultiArrayOperationBase {