This commit is contained in:
Christian Zimmermann 2017-03-22 21:51:54 +01:00
parent c9cdb1a430
commit e624667fbb
6 changed files with 121 additions and 64 deletions

View file

@ -439,6 +439,26 @@ 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

@ -179,6 +179,12 @@ namespace MultiArrayTools
{ {
return MAB::operator()(str...); return MAB::operator()(str...);
} }
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 <class... NameTypes> template <class... NameTypes>
MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str); MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str);

View file

@ -46,6 +46,7 @@ namespace MultiArrayTools
for(iref = mArrayRef.beginIndex().pos(); iref != mArrayRef.endIndex(); ++iref){ for(iref = mArrayRef.beginIndex().pos(); iref != mArrayRef.endIndex(); ++iref){
std::cout << iref.pos() << '\r' << std::flush; std::cout << iref.pos() << '\r' << std::flush;
get() = in.get(); get() = in.get();
//assert(not std::isnan( get() ));
} }
//CHECK; //CHECK;
MAOB::mIibPtr->freeLinked(); MAOB::mIibPtr->freeLinked();
@ -90,6 +91,19 @@ namespace MultiArrayTools
//mIndex.name(nm); //mIndex.name(nm);
} }
template <typename T, class Range>
MultiArrayOperationRoot<T,Range>::
MultiArrayOperationRoot(const MultiArrayOperationRoot& in) :
MutableMultiArrayOperationBase<T>(),
mArrayRef(in.mArrayRef),
mIndex(mArrayRef.beginIndex()),
mNm(in.mNm)
{
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
//mIndex.name(nm);
}
template <typename T, class Range> template <typename T, class Range>
MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range>& in) MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range>& in)
@ -312,14 +326,20 @@ namespace MultiArrayTools
template <typename T, class Range> template <typename T, class Range>
T& MultiArrayOperationRoot<T,Range>::get() T& MultiArrayOperationRoot<T,Range>::get()
{ {
//CHECK;
//return mArrayRef[mIndex]; //return mArrayRef[mIndex];
assert(MAOB::mIibPtr == &mIndex);
//VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]; return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
} }
template <typename T, class Range> template <typename T, class Range>
const T& MultiArrayOperationRoot<T,Range>::get() const const T& MultiArrayOperationRoot<T,Range>::get() const
{ {
//CHECK;
//return mArrayRef[mIndex]; //return mArrayRef[mIndex];
assert(MAOB::mIibPtr == &mIndex);
//VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]; return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
} }
@ -407,6 +427,19 @@ namespace MultiArrayTools
//mIndex.name(nm); //mIndex.name(nm);
} }
template <typename T, class Range>
ConstMultiArrayOperationRoot<T,Range>::
ConstMultiArrayOperationRoot(const ConstMultiArrayOperationRoot& in) :
MultiArrayOperationBase<T>(),
mArrayRef(in.mArrayRef),
mIndex(mArrayRef.beginIndex()),
mNm(in.mNm)
{
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
//mIndex.name(nm);
}
/* /*
template <typename T, class Range> template <typename T, class Range>
const ConstMultiArrayOperationRoot<T,Range>& const ConstMultiArrayOperationRoot<T,Range>&
@ -553,12 +586,17 @@ 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
{ {
//CHECK;
MAOB::mIibPtr = &mIndex;
//VCHECK(MAOB::mIibPtr->name());
MAOB::mIibPtr->linkTo(target); MAOB::mIibPtr->linkTo(target);
} }
template <typename T, class Range> template <typename T, class Range>
const T& ConstMultiArrayOperationRoot<T,Range>::get() const const T& ConstMultiArrayOperationRoot<T,Range>::get() const
{ {
//CHECK;
assert(MAOB::mIibPtr == &mIndex);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]; return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
} }
@ -681,13 +719,13 @@ namespace MultiArrayTools
MultiArrayOperation<T,Operation,MAOps...>:: MultiArrayOperation<T,Operation,MAOps...>::
MultiArrayOperation(Operation& op, const MAOps&... args) : MultiArrayOperation(Operation& op, const MAOps&... args) :
mOp(op), mOp(op),
mArgs(std::make_tuple(args...)) {} mArgs(std::make_tuple(args...)) { /*CHECK;*/ }
template <typename T, class Operation, class... MAOps> template <typename T, class Operation, class... MAOps>
MultiArrayOperation<T,Operation,MAOps...>:: MultiArrayOperation<T,Operation,MAOps...>::
MultiArrayOperation(const Operation& op, const MAOps&... args) : MultiArrayOperation(const Operation& op, const MAOps&... args) :
mOp(op), mOp(op),
mArgs(std::make_tuple(args...)) {} mArgs(std::make_tuple(args...)) { /*CHECK;*/ }
template <typename T, class Operation, class... MAOps> template <typename T, class Operation, class... MAOps>
template <class Operation2, class... MAOps2> template <class Operation2, class... MAOps2>
@ -775,9 +813,9 @@ namespace MultiArrayTools
template <typename T, class Operation, class... MAOps> template <typename T, class Operation, class... MAOps>
const T& MultiArrayOperation<T,Operation,MAOps...>::get() const const T& MultiArrayOperation<T,Operation,MAOps...>::get() const
{ {
//CHECK;
mVal = OperationCall<sizeof...(MAOps)-1>:: mVal = OperationCall<sizeof...(MAOps)-1>::
template callOperation(mOp, mArgs); template callOperation(mOp, mArgs);
std::cout << mVal << std::endl;
return mVal; return mVal;
} }
@ -789,12 +827,42 @@ namespace MultiArrayTools
template <typename T, class ContractOperation, class Range, class... MAOps> template <typename T, class ContractOperation, class Range, class... MAOps>
MultiArrayContraction<T,ContractOperation,Range,MAOps...>:: MultiArrayContraction<T,ContractOperation,Range,MAOps...>::
MultiArrayContraction(const ContractOperation& op, MultiArrayContraction(const ContractOperation& op,
//const std::string runIndexName,
const typename Range::IndexType& runIndex, const typename Range::IndexType& runIndex,
const MAOps&... args) : const MAOps&... args) :
mOp(op), 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<typename Range::IndexType*>( getLinked(runIndexName) );
linkIndicesTo(&mRunIndex);
}
template <typename T, class ContractOperation, class Range, class... MAOps>
MultiArrayContraction<T,ContractOperation,Range,MAOps...>::
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<typename Range::IndexType*>( getLinked(runIndexName) );
linkIndicesTo(&mRunIndex);
}
// !!!!!
template <typename T, class ContractOperation, class Range, class... MAOps> template <typename T, class ContractOperation, class Range, class... MAOps>
template <class Operation2, class... MAOps2> template <class Operation2, class... MAOps2>
@ -815,8 +883,8 @@ namespace MultiArrayTools
} }
template <typename T, class ContractOperation2, class Range, class... MAOps> template <typename T, class ContractOperation, class Range, class... MAOps>
template <class Range2, class ContractOperation, class... MAOps2> template <class Range2, class ContractOperation2, class... MAOps2>
MultiArrayContraction<T,ContractOperation2,Range2, MultiArrayContraction<T,ContractOperation2,Range2,
MultiArrayContraction<T,ContractOperation,Range,MAOps...>,MAOps2...> MultiArrayContraction<T,ContractOperation,Range,MAOps...>,MAOps2...>
MultiArrayContraction<T,ContractOperation,Range,MAOps...>:: MultiArrayContraction<T,ContractOperation,Range,MAOps...>::
@ -883,62 +951,14 @@ namespace MultiArrayTools
template <typename T, class ContractOperation, class Range, class... MAOps> template <typename T, class ContractOperation, class Range, class... MAOps>
const T& MultiArrayContraction<T,ContractOperation,Range,MAOps...>::get() const const T& MultiArrayContraction<T,ContractOperation,Range,MAOps...>::get() const
{ {
//CHECK;
mOp.reset(); mOp.reset();
for(mRunIndex.copyPos( mBeginIndex ); mRunIndex.pos() != mEndIndex.pos(); ++mRunIndex){ for(mRunIndex.copyPos( mBeginIndex ); mRunIndex.pos() != mEndIndex.pos(); ++mRunIndex){
OperationCall<sizeof...(MAOps)-1>:: OperationCall<sizeof...(MAOps)-1>::
template callOperation(mOp, mArgs); template callOperation(mOp, mArgs);
//MAO::mOp(std::get<0>(MAO::mArgs).get() );
} }
mOp.endOp(); mOp.endOp();
std::cout << MAO::mOp() << std::endl;
return mOp(); return mOp();
} }
/*
template <typename T, class ContractOperation, class Range, class... MAOps>
MultiArrayContraction<T,ContractOperation,Range,MAOps...>::
MultiArrayContraction(const ContractOperation& cop,
const typename Range::IndexType& runIndex,
const MAOps&... mao) :
MultiArrayContraction<T,ContractOperation,MAOps...>(cop, mao...),
mBeginIndex(runIndex), mEndIndex(runIndex),
mRunIndex(runIndex)
{
mBeginIndex.setPos(0);
mEndIndex.setPos(mRunIndex.max());
MAO::linkIndicesTo(&mRunIndex);
}
template <typename T, class ContractOperation, class Range, class... MAOps>
MultiArrayContraction<T,ContractOperation,Range,MAOps...>::
MultiArrayContraction(const ContractOperation& cop,
const typename Range::IndexType& runIndex,
size_t begin,
size_t end,
const MAOps&... mao) :
MultiArrayContraction<T,ContractOperation,MAOps...>(cop, mao...),
mBeginIndex(runIndex), mEndIndex(runIndex),
mRunIndex(runIndex)
{
mBeginIndex.setPos(begin);
mEndIndex.setPos(end);
MAO::linkIndicesTo(&mRunIndex);
}
// for the moment simplest case only:
template <typename T, class ContractOperation, class Range, class... MAOps>
const T& MultiArrayContraction<T,ContractOperation,Range,MAOps...>::get() const
{
MAO::mOp.reset();
for(mRunIndex.copyPos( mBeginIndex ); mRunIndex.pos() != mEndIndex.pos(); ++mRunIndex){
OperationCall<sizeof...(MAOps)-1>::
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();
}*/
} }

View file

@ -5,6 +5,7 @@
#include <cstdlib> #include <cstdlib>
#include <tuple> #include <tuple>
#include <cmath>
#include "base_def.h" #include "base_def.h"
#include "index_base.h" #include "index_base.h"
@ -53,6 +54,7 @@ namespace MultiArrayTools
//typedef decltype(MultiArray<T,Range>().begin()) IndexType; //typedef decltype(MultiArray<T,Range>().begin()) IndexType;
MultiArrayOperationRoot(MutableMultiArrayBase<T,Range>& ma, const Name& nm); MultiArrayOperationRoot(MutableMultiArrayBase<T,Range>& ma, const Name& nm);
MultiArrayOperationRoot(const MultiArrayOperationRoot& in);
MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in); MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in);
MultiArrayOperationRoot& operator=(MultiArrayOperationRoot& in); MultiArrayOperationRoot& operator=(MultiArrayOperationRoot& in);
@ -173,7 +175,8 @@ namespace MultiArrayTools
ConstMultiArrayOperationRoot(const MultiArrayBase<T,Range>& ma, const Name& nm); ConstMultiArrayOperationRoot(const MultiArrayBase<T,Range>& ma, const Name& nm);
ConstMultiArrayOperationRoot(const MultiArrayOperationRoot<T,Range>& in); ConstMultiArrayOperationRoot(const MultiArrayOperationRoot<T,Range>& in);
ConstMultiArrayOperationRoot(const ConstMultiArrayOperationRoot& in);
template <class Operation, class... MAOps> template <class Operation, class... MAOps>
MultiArrayOperation<T,Operation,ConstMultiArrayOperationRoot<T,Range>, MAOps...> MultiArrayOperation<T,Operation,ConstMultiArrayOperationRoot<T,Range>, MAOps...>
operator()(const Operation& op, const MAOps&... secs) const; operator()(const Operation& op, const MAOps&... secs) const;
@ -305,10 +308,19 @@ namespace MultiArrayTools
typedef MultiArrayOperationBase<T> MAOB; typedef MultiArrayOperationBase<T> MAOB;
typedef std::tuple<MAOps...> OBT; typedef std::tuple<MAOps...> 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 <class Operation2, class... MAOps2> template <class Operation2, class... MAOps2>
MultiArrayOperation<T,Operation2,MultiArrayContraction<T,ContractOperation,Range,MAOps...>,MAOps2...> MultiArrayOperation<T,Operation2,MultiArrayContraction<T,ContractOperation,Range,MAOps...>,MAOps2...>
operator()(Operation2& op, const MAOps2&... secs) const; operator()(Operation2& op, const MAOps2&... secs) const;

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
} }

View file

@ -191,7 +191,6 @@ namespace {
MultiArray2dAny max; MultiArray2dAny max;
}; };
/*
TEST_F(OneDimTest, CorrectExtensions) TEST_F(OneDimTest, CorrectExtensions)
{ {
EXPECT_EQ(ma.size(), 5); 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 = 0)], 14);
EXPECT_EQ(sl[j(j1 = 2, j2 = 1)], 34); EXPECT_EQ(sl[j(j1 = 2, j2 = 1)], 34);
} }
*/
TEST_F(ContractionTest, ContractionWorks) TEST_F(ContractionTest, ContractionWorks)
{ {
MultiArray2dAny ma2(ra); MultiArray2dAny ma2(ra);
@ -542,7 +541,7 @@ namespace {
auto i1 = i.template getIndex<0>(); auto i1 = i.template getIndex<0>();
auto i2 = i.template getIndex<1>(); 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 = 0, i2 = 1)], 324);
EXPECT_EQ(ma2[i(i1 = 1, i2 = 0)], 130); EXPECT_EQ(ma2[i(i1 = 1, i2 = 0)], 130);