From 062f9619d07fd0d0633862a6a86e7249565f6a9d Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 21 Mar 2017 18:12:24 +0100 Subject: [PATCH] some adds to the last commit --- src/base_def.h | 2 +- src/index_base.h | 2 +- src/multi_array_operation.cc | 116 +++++++++++++++++++++++++---------- src/multi_array_operation.h | 65 +++++++++++++------- src/unit_test.cc | 2 +- 5 files changed, 128 insertions(+), 59 deletions(-) diff --git a/src/base_def.h b/src/base_def.h index 6409a6e..cd71a3c 100644 --- a/src/base_def.h +++ b/src/base_def.h @@ -114,7 +114,7 @@ namespace MultiArrayTools class MultiArrayOperation; // multi_array_operation.h - template + template class MultiArrayContraction; // slice.h diff --git a/src/index_base.h b/src/index_base.h index 67b5e2a..c766b17 100644 --- a/src/index_base.h +++ b/src/index_base.h @@ -40,7 +40,7 @@ namespace MultiArrayTools virtual MultiRangeType rangeType() const = 0; virtual bool link(IndefinitIndexBase* toLink); - virtual void freeLinked(); + virtual void freeLinked(); virtual bool linked() const; virtual bool linkedTo(IndefinitIndexBase* link) const; virtual void linkTo(IndefinitIndexBase* target) = 0; diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index 113605a..fb9c25a 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -22,7 +22,7 @@ namespace MultiArrayTools } template - void MultiArrayOperationBase::freeIndex() + void MultiArrayOperationBase::freeIndex() const { mIibPtr->freeLinked(); } @@ -168,27 +168,37 @@ namespace MultiArrayTools } template - template - MultiArrayContraction > + template + MultiArrayContraction,MAOps...> MultiArrayOperationRoot::contract(const ContractOperation& cop, - const std::string& indexName) const + const std::string& indexName, + const MAOps&... mao) const { + //typename Range2::IndexType ind; + //ind.name(indexName); + typename Range2::IndexType* ind = dynamic_cast( mIndex.getLinked(indexName) ); return MultiArrayContraction >(cop, *this, *ind); + MultiArrayOperationRoot, + MAOps...>(cop, *ind, *this, mao...); } template - template - MultiArrayContraction > + template + MultiArrayContraction,MAOps...> MultiArrayOperationRoot::contract(const ContractOperation& cop, const std::string& indexName, const typename Range2::IndexType& begin, - const typename Range2::IndexType& end) const + const typename Range2::IndexType& end, + const MAOps&... mao) const { + //typename Range2::IndexType ind; + //ind.name(indexName); + typename Range2::IndexType* ind = dynamic_cast( mIndex.getLinked(indexName) ); return MultiArrayContraction >(cop, *this, *ind, begin, end); + MultiArrayOperationRoot, + MAOps...>(cop, *ind, begin, end, *this, mao...); } @@ -324,7 +334,7 @@ namespace MultiArrayTools } template - void MultiArrayOperationRoot::freeIndex() + void MultiArrayOperationRoot::freeIndex() const { MAOB::mIibPtr->freeLinked(); mIndex = mArrayRef.beginIndex(); @@ -438,27 +448,31 @@ namespace MultiArrayTools } template - template - MultiArrayContraction > + template + MultiArrayContraction,MAOps...> ConstMultiArrayOperationRoot::contract(const ContractOperation& cop, - const std::string& indexName) const + const std::string& indexName, + const MAOps&... mao) const { typename Range2::IndexType* ind = dynamic_cast( mIndex.getLinked(indexName) ); return MultiArrayContraction >(cop, *this, *ind); + ConstMultiArrayOperationRoot, + MAOps...>(cop, *ind, *this, mao...); } template - template - MultiArrayContraction > + template + MultiArrayContraction,MAOps...> ConstMultiArrayOperationRoot::contract(const ContractOperation& cop, const std::string& indexName, const typename Range2::IndexType& begin, - const typename Range2::IndexType& end) const + const typename Range2::IndexType& end, + const MAOps&... mao) const { typename Range2::IndexType* ind = dynamic_cast( mIndex.getLinked(indexName) ); return MultiArrayContraction >(cop, *this, *ind, begin, end); + ConstMultiArrayOperationRoot, + MAOps...>(cop, *ind, begin, end, *this, mao...); } @@ -546,7 +560,7 @@ namespace MultiArrayTools } template - void ConstMultiArrayOperationRoot::freeIndex() + void ConstMultiArrayOperationRoot::freeIndex() const { MAOB::mIibPtr->freeLinked(); mIndex = mArrayRef.beginIndex(); @@ -646,6 +660,38 @@ namespace MultiArrayTools MAOps2...>(op, *this, secs...); } + /* + template + template + MultiArrayContraction > + MultiArrayOperation:: + contract(const ContractOperation& cop, const std::string& indexName) const + { + typename Range2::IndexType* ind = dynamic_cast( mIndex.getLinked(indexName) ); + //typename Range2::IndexType ind = Range2().begin(); + //ind.name(indexName); + return MultiArrayContraction >(cop, *this, *ind); + + } + + template + template + MultiArrayContraction > + MultiArrayOperation:: + contract(const ContractOperation& cop, const std::string& indexName, + const typename Range2::IndexType& begin, + const typename Range2::IndexType& end) const + { + typename Range2::IndexType* ind = dynamic_cast( mIndex.getLinked(indexName) ); + //typename Range2::IndexType ind = Range2().begin(); + //ind.name(indexName); + return MultiArrayContraction >(cop, *this, *ind, begin, end); + + } + */ + template template auto MultiArrayOperation::operator+(const MAOp2& sec) @@ -703,11 +749,12 @@ namespace MultiArrayTools * MultiArrayContraction * *******************************/ - template - MultiArrayContraction:: - MultiArrayContraction(const ContractOperation& cop, const MAOp& mao, - const typename Range::IndexType& runIndex) : - MultiArrayOperation(cop, mao), + template + MultiArrayContraction:: + MultiArrayContraction(const ContractOperation& cop, + const typename Range::IndexType& runIndex, + const MAOps&... mao) : + MultiArrayOperation(cop, mao...), mBeginIndex(runIndex), mEndIndex(runIndex), mRunIndex(runIndex) { @@ -716,13 +763,14 @@ namespace MultiArrayTools MAO::linkIndicesTo(&mRunIndex); } - template - MultiArrayContraction:: - MultiArrayContraction(const ContractOperation& cop, const MAOp& mao, + template + MultiArrayContraction:: + MultiArrayContraction(const ContractOperation& cop, const typename Range::IndexType& runIndex, const typename Range::IndexType& beginIndex, - const typename Range::IndexType& endIndex) : - MultiArrayOperation(cop, mao), + const typename Range::IndexType& endIndex, + const MAOps&... mao) : + MultiArrayOperation(cop, mao...), mBeginIndex(beginIndex), mEndIndex(endIndex), mRunIndex(runIndex) { @@ -731,14 +779,16 @@ namespace MultiArrayTools // for the moment simplest case only: - template - const T& MultiArrayContraction::get() const + template + const T& MultiArrayContraction::get() const { MAO::mOp.reset(); for(mRunIndex.copyPos( mBeginIndex ); mRunIndex.pos() != mEndIndex.pos(); ++mRunIndex){ - MAO::mOp(std::get<0>(MAO::mArgs).get() ); + OperationCall:: + template callOperation(MAO::mOp, MAO::mArgs); + //MAO::mOp(std::get<0>(MAO::mArgs).get() ); } - MAO::mOp.endOp(MAO::mVal); + MAO::mOp.endOp(); return MAO::mOp(); } } diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index def9563..3cf184a 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -26,10 +26,10 @@ namespace MultiArrayTools virtual const T& get() const = 0; - virtual void freeIndex(); + virtual void freeIndex() const; protected: - IndefinitIndexBase* mIibPtr = nullptr; + mutable IndefinitIndexBase* mIibPtr = nullptr; }; @@ -74,15 +74,17 @@ namespace MultiArrayTools MultiArrayOperation, MAOps...> operator()(const Operation& op, const MAOps&... secs) const; - template < class Range2, class ContractOperation> - MultiArrayContraction > - contract(const ContractOperation& cop, const std::string& indexName) const; + template < class Range2, class ContractOperation, class... MAOps> + MultiArrayContraction, MAOps...> + contract(const ContractOperation& cop, const std::string& indexName, + const MAOps&... mao) const; - template - MultiArrayContraction > + template + MultiArrayContraction, MAOps...> contract(const ContractOperation& cop, const std::string& indexName, const typename Range2::IndexType& begin, - const typename Range2::IndexType& end) const; + const typename Range2::IndexType& end, + const MAOps&... mao) const; template @@ -128,7 +130,7 @@ namespace MultiArrayTools const Name& name() const; - virtual void freeIndex() override; + virtual void freeIndex() const override; const MultiArrayBase& getCont() const { return mArrayRef; } @@ -170,16 +172,18 @@ namespace MultiArrayTools MultiArrayOperation, MAOps...> operator()(const Operation& op, const MAOps&... secs) const; - template - MultiArrayContraction > - contract(const ContractOperation& cop, const std::string& indexName) const; + template + MultiArrayContraction, MAOps...> + contract(const ContractOperation& cop, const std::string& indexName, + const MAOps&... mao) const; - template - MultiArrayContraction > + template + MultiArrayContraction, MAOps...> contract(const ContractOperation& cop, const std::string& indexName, const typename Range2::IndexType& begin, - const typename Range2::IndexType& end) const; + const typename Range2::IndexType& end, + const MAOps&... mao) const; template auto operator+(const MAOp& sec) const -> decltype(operator()(std::plus(), sec)); @@ -210,7 +214,7 @@ namespace MultiArrayTools const Name& name() const; - virtual void freeIndex() override; + virtual void freeIndex() const override; const MultiArrayBase& getCont() const { return mArrayRef; } @@ -253,6 +257,19 @@ namespace MultiArrayTools template MultiArrayOperation,MAOps2...> operator()(const Operation2& op, const MAOps2&... secs) const; + + /* + template + MultiArrayContraction > + contract(const ContractOperation& cop, const std::string& indexName) const; + + + template + MultiArrayContraction > + contract(const ContractOperation& cop, const std::string& indexName, + const typename Range2::IndexType& begin, + const typename Range2::IndexType& end) const; + */ template auto operator+(const MAOp2& sec) -> decltype(operator()(std::plus(), sec)); @@ -279,21 +296,23 @@ namespace MultiArrayTools OBT mArgs; // include first arg also here !!! }; - template - class MultiArrayContraction : public MultiArrayOperation + template + class MultiArrayContraction : public MultiArrayOperation { public: typedef MultiArrayOperationBase MAOB; - typedef MultiArrayOperation MAO; + typedef MultiArrayOperation MAO; - MultiArrayContraction(const ContractOperation& cop, const MAOp& mao, - const typename Range::IndexType& runIndex); + MultiArrayContraction(const ContractOperation& cop, + const typename Range::IndexType& runIndex, + const MAOps&... mao); - MultiArrayContraction(const ContractOperation& cop, const MAOp& mao, + MultiArrayContraction(const ContractOperation& cop, const typename Range::IndexType& runIndex, const typename Range::IndexType& beginIndex, - const typename Range::IndexType& endIndex); + const typename Range::IndexType& endIndex, + const MAOps&... mao); virtual const T& get() const override; diff --git a/src/unit_test.cc b/src/unit_test.cc index f1c7298..ae64fec 100644 --- a/src/unit_test.cc +++ b/src/unit_test.cc @@ -26,7 +26,7 @@ namespace { return res += a; } - void endOp(T& res) const {} + void endOp() const {} void reset() const {