From e624667fbb13d65515764a50e40982495a1fa9dc Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 22 Mar 2017 21:51:54 +0100 Subject: [PATCH] im com --- src/multi_array.cc | 20 ++++++ src/multi_array.h | 6 ++ src/multi_array_operation.cc | 132 ++++++++++++++++++++--------------- src/multi_array_operation.h | 20 ++++-- src/single_range.cc | 2 +- src/unit_test.cc | 5 +- 6 files changed, 121 insertions(+), 64 deletions(-) diff --git a/src/multi_array.cc b/src/multi_array.cc index 84fb7bd..4b25d73 100644 --- a/src/multi_array.cc +++ b/src/multi_array.cc @@ -439,6 +439,26 @@ 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..ee2dada 100644 --- a/src/multi_array.h +++ b/src/multi_array.h @@ -179,6 +179,12 @@ namespace MultiArrayTools { return MAB::operator()(str...); } + + template + ConstMultiArrayOperationRoot operator()(const NameTypes&... str) const; + + template + ConstMultiArrayOperationRoot operator()(const NameType& name, bool master) const; template MultiArrayOperationRoot operator()(const NameTypes&... str); diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index e5f6ef1..30a2a81 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -46,6 +46,7 @@ namespace MultiArrayTools for(iref = mArrayRef.beginIndex().pos(); iref != mArrayRef.endIndex(); ++iref){ std::cout << iref.pos() << '\r' << std::flush; get() = in.get(); + //assert(not std::isnan( get() )); } //CHECK; MAOB::mIibPtr->freeLinked(); @@ -90,6 +91,19 @@ namespace MultiArrayTools //mIndex.name(nm); } + template + MultiArrayOperationRoot:: + MultiArrayOperationRoot(const MultiArrayOperationRoot& in) : + MutableMultiArrayOperationBase(), + mArrayRef(in.mArrayRef), + mIndex(mArrayRef.beginIndex()), + mNm(in.mNm) + { + MAOB::mIibPtr = &mIndex; + MAOB::mIibPtr->name(mNm); + //mIndex.name(nm); + } + template MultiArrayOperationRoot& MultiArrayOperationRoot::operator=(const MultiArrayOperationRoot& in) @@ -312,14 +326,20 @@ namespace MultiArrayTools template T& MultiArrayOperationRoot::get() { + //CHECK; //return mArrayRef[mIndex]; + assert(MAOB::mIibPtr == &mIndex); + //VCHECK(mArrayRef[*dynamic_cast(MAOB::mIibPtr)]); return mArrayRef[*dynamic_cast(MAOB::mIibPtr)]; } template const T& MultiArrayOperationRoot::get() const { + //CHECK; //return mArrayRef[mIndex]; + assert(MAOB::mIibPtr == &mIndex); + //VCHECK(mArrayRef[*dynamic_cast(MAOB::mIibPtr)]); return mArrayRef[*dynamic_cast(MAOB::mIibPtr)]; } @@ -407,6 +427,19 @@ namespace MultiArrayTools //mIndex.name(nm); } + template + ConstMultiArrayOperationRoot:: + ConstMultiArrayOperationRoot(const ConstMultiArrayOperationRoot& in) : + MultiArrayOperationBase(), + mArrayRef(in.mArrayRef), + mIndex(mArrayRef.beginIndex()), + mNm(in.mNm) + { + MAOB::mIibPtr = &mIndex; + MAOB::mIibPtr->name(mNm); + //mIndex.name(nm); + } + /* template const ConstMultiArrayOperationRoot& @@ -553,12 +586,17 @@ namespace MultiArrayTools template void ConstMultiArrayOperationRoot::linkIndicesTo(IndefinitIndexBase* target) const { + //CHECK; + MAOB::mIibPtr = &mIndex; + //VCHECK(MAOB::mIibPtr->name()); MAOB::mIibPtr->linkTo(target); } template const T& ConstMultiArrayOperationRoot::get() const { + //CHECK; + assert(MAOB::mIibPtr == &mIndex); return mArrayRef[*dynamic_cast(MAOB::mIibPtr)]; } @@ -681,13 +719,13 @@ namespace MultiArrayTools MultiArrayOperation:: MultiArrayOperation(Operation& op, const MAOps&... args) : mOp(op), - mArgs(std::make_tuple(args...)) {} + mArgs(std::make_tuple(args...)) { /*CHECK;*/ } template MultiArrayOperation:: MultiArrayOperation(const Operation& op, const MAOps&... args) : mOp(op), - mArgs(std::make_tuple(args...)) {} + mArgs(std::make_tuple(args...)) { /*CHECK;*/ } template template @@ -775,9 +813,9 @@ namespace MultiArrayTools template const T& MultiArrayOperation::get() const { + //CHECK; mVal = OperationCall:: template callOperation(mOp, mArgs); - std::cout << mVal << std::endl; return mVal; } @@ -789,12 +827,42 @@ namespace MultiArrayTools template MultiArrayContraction:: MultiArrayContraction(const ContractOperation& op, + //const std::string runIndexName, const typename Range::IndexType& runIndex, const MAOps&... args) : mOp(op), - mArgs(std::make_tuple(args...)) {} + mArgs(std::make_tuple(args...)) + { + mRunIndex = runIndex; + mBeginIndex = mRunIndex; + mEndIndex = mRunIndex; + mBeginIndex.setPos(0); + mEndIndex.setPos(mRunIndex.max()); + + //mRunIndex = *dynamic_cast( getLinked(runIndexName) ); + linkIndicesTo(&mRunIndex); + } + + template + MultiArrayContraction:: + MultiArrayContraction(const ContractOperation& op, + //const std::string runIndexName, + const typename Range::IndexType& runIndex, + size_t begin, size_t end, + const MAOps&... args) : + mOp(op), + mArgs(std::make_tuple(args...)) + { + mRunIndex = runIndex; + mBeginIndex = mRunIndex; + mEndIndex = mRunIndex; + mBeginIndex.setPos(begin); + mEndIndex.setPos(end); + //mRunIndex = *dynamic_cast( getLinked(runIndexName) ); + linkIndicesTo(&mRunIndex); + + } - // !!!!! template template @@ -815,8 +883,8 @@ namespace MultiArrayTools } - template - template + template + template MultiArrayContraction,MAOps2...> MultiArrayContraction:: @@ -883,62 +951,14 @@ namespace MultiArrayTools template const T& MultiArrayContraction::get() const { + //CHECK; mOp.reset(); for(mRunIndex.copyPos( mBeginIndex ); mRunIndex.pos() != mEndIndex.pos(); ++mRunIndex){ OperationCall:: template callOperation(mOp, mArgs); - //MAO::mOp(std::get<0>(MAO::mArgs).get() ); } mOp.endOp(); - std::cout << MAO::mOp() << std::endl; return mOp(); } - - /* - template - MultiArrayContraction:: - MultiArrayContraction(const ContractOperation& cop, - const typename Range::IndexType& runIndex, - const MAOps&... mao) : - MultiArrayContraction(cop, mao...), - mBeginIndex(runIndex), mEndIndex(runIndex), - mRunIndex(runIndex) - { - mBeginIndex.setPos(0); - mEndIndex.setPos(mRunIndex.max()); - MAO::linkIndicesTo(&mRunIndex); - } - - template - MultiArrayContraction:: - MultiArrayContraction(const ContractOperation& cop, - const typename Range::IndexType& runIndex, - size_t begin, - size_t end, - const MAOps&... mao) : - MultiArrayContraction(cop, mao...), - mBeginIndex(runIndex), mEndIndex(runIndex), - mRunIndex(runIndex) - { - mBeginIndex.setPos(begin); - mEndIndex.setPos(end); - MAO::linkIndicesTo(&mRunIndex); - } - - - // for the moment simplest case only: - template - const T& MultiArrayContraction::get() const - { - MAO::mOp.reset(); - for(mRunIndex.copyPos( mBeginIndex ); mRunIndex.pos() != mEndIndex.pos(); ++mRunIndex){ - OperationCall:: - template callOperation(MAO::mOp, MAO::mArgs); - //MAO::mOp(std::get<0>(MAO::mArgs).get() ); - } - MAO::mOp.endOp(); - std::cout << MAO::mOp() << std::endl; - return MAO::mOp(); - }*/ } diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 162bedd..5270d1f 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -5,6 +5,7 @@ #include #include +#include #include "base_def.h" #include "index_base.h" @@ -53,6 +54,7 @@ namespace MultiArrayTools //typedef decltype(MultiArray().begin()) IndexType; MultiArrayOperationRoot(MutableMultiArrayBase& ma, const Name& nm); + MultiArrayOperationRoot(const MultiArrayOperationRoot& in); MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in); MultiArrayOperationRoot& operator=(MultiArrayOperationRoot& in); @@ -173,7 +175,8 @@ namespace MultiArrayTools ConstMultiArrayOperationRoot(const MultiArrayBase& ma, const Name& nm); ConstMultiArrayOperationRoot(const MultiArrayOperationRoot& in); - + ConstMultiArrayOperationRoot(const ConstMultiArrayOperationRoot& in); + template MultiArrayOperation, MAOps...> operator()(const Operation& op, const MAOps&... secs) const; @@ -305,10 +308,19 @@ namespace MultiArrayTools typedef MultiArrayOperationBase MAOB; typedef std::tuple OBT; - - MultiArrayContraction(ContractOperation& op, const MAOps&... secs); - MultiArrayContraction(const ContractOperation& op, const MAOps&... secs); + MultiArrayContraction(const ContractOperation& op, + //const std::string runIndexName, + const typename Range::IndexType& runIndex, + const MAOps&... args); + + MultiArrayContraction(const ContractOperation& op, + //const std::string runIndexName, + const typename Range::IndexType& runIndex, + size_t begin, size_t end, + const MAOps&... args); + + template MultiArrayOperation,MAOps2...> operator()(Operation2& op, const MAOps2&... secs) const; 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 } diff --git a/src/unit_test.cc b/src/unit_test.cc index 8e2b690..371b323 100644 --- a/src/unit_test.cc +++ b/src/unit_test.cc @@ -191,7 +191,6 @@ namespace { MultiArray2dAny max; }; - /* TEST_F(OneDimTest, CorrectExtensions) { EXPECT_EQ(ma.size(), 5); @@ -510,7 +509,7 @@ namespace { EXPECT_EQ(sl[j(j1 = 2, j2 = 0)], 14); EXPECT_EQ(sl[j(j1 = 2, j2 = 1)], 34); } - */ + TEST_F(ContractionTest, ContractionWorks) { MultiArray2dAny ma2(ra); @@ -542,7 +541,7 @@ namespace { auto i1 = i.template getIndex<0>(); auto i2 = i.template getIndex<1>(); - EXPECT_EQ(ma2[i(i1 = 0, i2 = 0)], -275); + EXPECT_EQ(ma2[i(i1 = 0, i2 = 0)], -165); EXPECT_EQ(ma2[i(i1 = 0, i2 = 1)], 324); EXPECT_EQ(ma2[i(i1 = 1, i2 = 0)], 130);