From 2a7dd9aa83eb454702923c9a24aa6d0d1c4465ee Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 23 Mar 2017 15:10:56 +0100 Subject: [PATCH] change linkage behavior of contract indices... should be save now --- CMakeLists.txt | 2 +- src/multi_array.cc | 19 +++++++++++++++++++ src/multi_array.h | 6 ++++++ src/multi_array_operation.cc | 19 ++++++++++++++++--- src/multi_array_operation.h | 6 +++++- src/single_range.cc | 2 +- 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 526ed3e..61aa4d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ include_directories(src) add_executable(utest src/unit_test.cc) target_link_libraries(utest ${GTEST_BOTH_LIBRARIES}) -add_test(AllTests utest) +add_test(NAME utest COMMAND utest) #install(TARGETS testm DESTINATION install) diff --git a/src/multi_array.cc b/src/multi_array.cc index 84fb7bd..ca01b44 100644 --- a/src/multi_array.cc +++ b/src/multi_array.cc @@ -439,6 +439,25 @@ namespace MultiArrayTools } } + template + template + ConstMultiArrayOperationRoot MutableMultiArrayBase::operator()(const NameTypes&... str) const + { + return ConstMultiArrayOperationRoot(*this, Name("master", str...)); + } + + template + template + ConstMultiArrayOperationRoot MutableMultiArrayBase::operator()(const NameType& name, bool master) const + { + //CHECK; + if(master){ + return ConstMultiArrayOperationRoot(*this, name); + } + else { + return operator()(name); + } + } /******************* * MultiArray * diff --git a/src/multi_array.h b/src/multi_array.h index d0d1242..acc8a9b 100644 --- a/src/multi_array.h +++ b/src/multi_array.h @@ -186,6 +186,12 @@ namespace MultiArrayTools template MultiArrayOperationRoot operator()(const NameType& name, bool master); + template + ConstMultiArrayOperationRoot operator()(const NameTypes&... str) const; + + template + ConstMultiArrayOperationRoot operator()(const NameType& name, bool master) const; + }; template diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index 74c34f7..3c2bde6 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -20,7 +20,7 @@ namespace MultiArrayTools { return *mIibPtr; } - + template void MultiArrayOperationBase::freeIndex() const { @@ -306,6 +306,7 @@ namespace MultiArrayTools template void MultiArrayOperationRoot::linkIndicesTo(IndefinitIndexBase* target) const { + MAOB::mIibPtr = &mIndex; MAOB::mIibPtr->linkTo(target); } @@ -553,6 +554,7 @@ namespace MultiArrayTools template void ConstMultiArrayOperationRoot::linkIndicesTo(IndefinitIndexBase* target) const { + MAOB::mIibPtr = &mIndex; MAOB::mIibPtr->linkTo(target); } @@ -798,7 +800,8 @@ namespace MultiArrayTools { mBeginIndex.setPos(0); mEndIndex.setPos(mRunIndex.max()); - linkIndicesTo(&mRunIndex); + // DON'T link here !! + //linkIndicesTo(&mRunIndex); } template @@ -815,7 +818,8 @@ namespace MultiArrayTools { mBeginIndex.setPos(begin); mEndIndex.setPos(end); - linkIndicesTo(&mRunIndex); + // DON'T link here !! + //linkIndicesTo(&mRunIndex); } @@ -897,10 +901,19 @@ namespace MultiArrayTools { return LinkedIndexGetter::getLinked(mArgs, name, nullptr); } + + template + void MultiArrayContraction::setInternalLinks() const + { + linkIndicesTo(&mRunIndex); + } template void MultiArrayContraction::linkIndicesTo(IndefinitIndexBase* target) const { + if(target != &mRunIndex){ + setInternalLinks(); + } TupleIndicesLinker::linkTupleIndicesTo(mArgs, target); } diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 9056f39..16185e1 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -27,6 +27,8 @@ namespace MultiArrayTools virtual const T& get() const = 0; + virtual void setInternalLinks() const {} + virtual void freeIndex() const; protected: @@ -285,7 +287,7 @@ namespace MultiArrayTools auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides(), sec)); virtual size_t argNum() const override; - + virtual IndefinitIndexBase* getLinked(const std::string& name) const override; virtual void linkIndicesTo(IndefinitIndexBase* target) const override; @@ -344,6 +346,8 @@ namespace MultiArrayTools template auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides(), sec)); + + virtual void setInternalLinks() const override; virtual size_t argNum() const override; diff --git a/src/single_range.cc b/src/single_range.cc index 95c3697..e215bc7 100644 --- a/src/single_range.cc +++ b/src/single_range.cc @@ -194,7 +194,7 @@ namespace MultiArrayTools #ifdef LORENTZ_DIMENSION return LORENTZ_DIMENSION; #else - return 1; // 4 + return 4; // 4 #endif }