change linkage behavior of contract indices... should be save now

This commit is contained in:
Christian Zimmermann 2017-03-23 15:10:56 +01:00
parent dc436af07d
commit 2a7dd9aa83
6 changed files with 48 additions and 6 deletions

View file

@ -15,7 +15,7 @@ include_directories(src)
add_executable(utest src/unit_test.cc) add_executable(utest src/unit_test.cc)
target_link_libraries(utest ${GTEST_BOTH_LIBRARIES}) target_link_libraries(utest ${GTEST_BOTH_LIBRARIES})
add_test(AllTests utest) add_test(NAME utest COMMAND utest)
#install(TARGETS testm DESTINATION install) #install(TARGETS testm DESTINATION install)

View file

@ -439,6 +439,25 @@ namespace MultiArrayTools
} }
} }
template <typename T, class Range>
template <class... NameTypes>
ConstMultiArrayOperationRoot<T,Range> MutableMultiArrayBase<T,Range>::operator()(const NameTypes&... str) const
{
return ConstMultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
}
template <typename T, class Range>
template <class NameType>
ConstMultiArrayOperationRoot<T,Range> MutableMultiArrayBase<T,Range>::operator()(const NameType& name, bool master) const
{
//CHECK;
if(master){
return ConstMultiArrayOperationRoot<T,Range>(*this, name);
}
else {
return operator()(name);
}
}
/******************* /*******************
* MultiArray * * MultiArray *

View file

@ -186,6 +186,12 @@ namespace MultiArrayTools
template <class NameType> template <class NameType>
MultiArrayOperationRoot<T,Range> operator()(const NameType& name, bool master); MultiArrayOperationRoot<T,Range> operator()(const NameType& name, bool master);
template <class... NameTypes>
ConstMultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str) const;
template <class NameType>
ConstMultiArrayOperationRoot<T,Range> operator()(const NameType& name, bool master) const;
}; };
template <typename T, class Range> template <typename T, class Range>

View file

@ -306,6 +306,7 @@ namespace MultiArrayTools
template <typename T, class Range> template <typename T, class Range>
void MultiArrayOperationRoot<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const void MultiArrayOperationRoot<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const
{ {
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->linkTo(target); MAOB::mIibPtr->linkTo(target);
} }
@ -553,6 +554,7 @@ namespace MultiArrayTools
template <typename T, class Range> template <typename T, class Range>
void ConstMultiArrayOperationRoot<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const void ConstMultiArrayOperationRoot<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const
{ {
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->linkTo(target); MAOB::mIibPtr->linkTo(target);
} }
@ -798,7 +800,8 @@ namespace MultiArrayTools
{ {
mBeginIndex.setPos(0); mBeginIndex.setPos(0);
mEndIndex.setPos(mRunIndex.max()); mEndIndex.setPos(mRunIndex.max());
linkIndicesTo(&mRunIndex); // DON'T link here !!
//linkIndicesTo(&mRunIndex);
} }
template <typename T, class ContractOperation, class Range, class... MAOps> template <typename T, class ContractOperation, class Range, class... MAOps>
@ -815,7 +818,8 @@ namespace MultiArrayTools
{ {
mBeginIndex.setPos(begin); mBeginIndex.setPos(begin);
mEndIndex.setPos(end); mEndIndex.setPos(end);
linkIndicesTo(&mRunIndex); // DON'T link here !!
//linkIndicesTo(&mRunIndex);
} }
@ -898,9 +902,18 @@ namespace MultiArrayTools
return LinkedIndexGetter<sizeof...(MAOps)-1>::getLinked(mArgs, name, nullptr); return LinkedIndexGetter<sizeof...(MAOps)-1>::getLinked(mArgs, name, nullptr);
} }
template <typename T, class ContractOperation, class Range, class... MAOps>
void MultiArrayContraction<T,ContractOperation,Range,MAOps...>::setInternalLinks() const
{
linkIndicesTo(&mRunIndex);
}
template <typename T, class ContractOperation, class Range, class... MAOps> template <typename T, class ContractOperation, class Range, class... MAOps>
void MultiArrayContraction<T,ContractOperation,Range,MAOps...>::linkIndicesTo(IndefinitIndexBase* target) const void MultiArrayContraction<T,ContractOperation,Range,MAOps...>::linkIndicesTo(IndefinitIndexBase* target) const
{ {
if(target != &mRunIndex){
setInternalLinks();
}
TupleIndicesLinker<sizeof...(MAOps)-1>::linkTupleIndicesTo(mArgs, target); TupleIndicesLinker<sizeof...(MAOps)-1>::linkTupleIndicesTo(mArgs, target);
} }

View file

@ -27,6 +27,8 @@ namespace MultiArrayTools
virtual const T& get() const = 0; virtual const T& get() const = 0;
virtual void setInternalLinks() const {}
virtual void freeIndex() const; virtual void freeIndex() const;
protected: protected:
@ -345,6 +347,8 @@ namespace MultiArrayTools
template <class MAOp2> template <class MAOp2>
auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides<T>(), sec)); auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides<T>(), sec));
virtual void setInternalLinks() const override;
virtual size_t argNum() const override; virtual size_t argNum() const override;
virtual IndefinitIndexBase* getLinked(const std::string& name) const override; virtual IndefinitIndexBase* getLinked(const std::string& name) const override;

View file

@ -194,7 +194,7 @@ namespace MultiArrayTools
#ifdef LORENTZ_DIMENSION #ifdef LORENTZ_DIMENSION
return LORENTZ_DIMENSION; return LORENTZ_DIMENSION;
#else #else
return 1; // 4 return 4; // 4
#endif #endif
} }