im com
This commit is contained in:
parent
c9cdb1a430
commit
e624667fbb
6 changed files with 121 additions and 64 deletions
|
@ -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 *
|
||||
|
|
|
@ -180,6 +180,12 @@ namespace MultiArrayTools
|
|||
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>
|
||||
MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str);
|
||||
|
||||
|
|
|
@ -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 <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>
|
||||
MultiArrayOperationRoot<T,Range>&
|
||||
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range>& in)
|
||||
|
@ -312,14 +326,20 @@ namespace MultiArrayTools
|
|||
template <typename T, class Range>
|
||||
T& MultiArrayOperationRoot<T,Range>::get()
|
||||
{
|
||||
//CHECK;
|
||||
//return mArrayRef[mIndex];
|
||||
assert(MAOB::mIibPtr == &mIndex);
|
||||
//VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]);
|
||||
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& MultiArrayOperationRoot<T,Range>::get() const
|
||||
{
|
||||
//CHECK;
|
||||
//return mArrayRef[mIndex];
|
||||
assert(MAOB::mIibPtr == &mIndex);
|
||||
//VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]);
|
||||
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
|
||||
}
|
||||
|
||||
|
@ -407,6 +427,19 @@ namespace MultiArrayTools
|
|||
//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>
|
||||
const ConstMultiArrayOperationRoot<T,Range>&
|
||||
|
@ -553,12 +586,17 @@ namespace MultiArrayTools
|
|||
template <typename T, class Range>
|
||||
void ConstMultiArrayOperationRoot<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const
|
||||
{
|
||||
//CHECK;
|
||||
MAOB::mIibPtr = &mIndex;
|
||||
//VCHECK(MAOB::mIibPtr->name());
|
||||
MAOB::mIibPtr->linkTo(target);
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& ConstMultiArrayOperationRoot<T,Range>::get() const
|
||||
{
|
||||
//CHECK;
|
||||
assert(MAOB::mIibPtr == &mIndex);
|
||||
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
|
||||
}
|
||||
|
||||
|
@ -681,13 +719,13 @@ namespace MultiArrayTools
|
|||
MultiArrayOperation<T,Operation,MAOps...>::
|
||||
MultiArrayOperation(Operation& op, const MAOps&... args) :
|
||||
mOp(op),
|
||||
mArgs(std::make_tuple(args...)) {}
|
||||
mArgs(std::make_tuple(args...)) { /*CHECK;*/ }
|
||||
|
||||
template <typename T, class Operation, class... MAOps>
|
||||
MultiArrayOperation<T,Operation,MAOps...>::
|
||||
MultiArrayOperation(const Operation& op, const MAOps&... args) :
|
||||
mOp(op),
|
||||
mArgs(std::make_tuple(args...)) {}
|
||||
mArgs(std::make_tuple(args...)) { /*CHECK;*/ }
|
||||
|
||||
template <typename T, class Operation, class... MAOps>
|
||||
template <class Operation2, class... MAOps2>
|
||||
|
@ -775,9 +813,9 @@ namespace MultiArrayTools
|
|||
template <typename T, class Operation, class... MAOps>
|
||||
const T& MultiArrayOperation<T,Operation,MAOps...>::get() const
|
||||
{
|
||||
//CHECK;
|
||||
mVal = OperationCall<sizeof...(MAOps)-1>::
|
||||
template callOperation(mOp, mArgs);
|
||||
std::cout << mVal << std::endl;
|
||||
return mVal;
|
||||
}
|
||||
|
||||
|
@ -789,12 +827,42 @@ namespace MultiArrayTools
|
|||
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,
|
||||
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<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 <class Operation2, class... MAOps2>
|
||||
|
@ -815,8 +883,8 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
|
||||
template <typename T, class ContractOperation2, class Range, class... MAOps>
|
||||
template <class Range2, class ContractOperation, class... MAOps2>
|
||||
template <typename T, class ContractOperation, class Range, class... MAOps>
|
||||
template <class Range2, class ContractOperation2, class... MAOps2>
|
||||
MultiArrayContraction<T,ContractOperation2,Range2,
|
||||
MultiArrayContraction<T,ContractOperation,Range,MAOps...>,MAOps2...>
|
||||
MultiArrayContraction<T,ContractOperation,Range,MAOps...>::
|
||||
|
@ -883,62 +951,14 @@ namespace MultiArrayTools
|
|||
template <typename T, class ContractOperation, class Range, class... MAOps>
|
||||
const T& MultiArrayContraction<T,ContractOperation,Range,MAOps...>::get() const
|
||||
{
|
||||
//CHECK;
|
||||
mOp.reset();
|
||||
for(mRunIndex.copyPos( mBeginIndex ); mRunIndex.pos() != mEndIndex.pos(); ++mRunIndex){
|
||||
OperationCall<sizeof...(MAOps)-1>::
|
||||
template callOperation(mOp, mArgs);
|
||||
//MAO::mOp(std::get<0>(MAO::mArgs).get() );
|
||||
}
|
||||
mOp.endOp();
|
||||
std::cout << MAO::mOp() << std::endl;
|
||||
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();
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <cmath>
|
||||
|
||||
#include "base_def.h"
|
||||
#include "index_base.h"
|
||||
|
@ -53,6 +54,7 @@ namespace MultiArrayTools
|
|||
//typedef decltype(MultiArray<T,Range>().begin()) IndexType;
|
||||
|
||||
MultiArrayOperationRoot(MutableMultiArrayBase<T,Range>& ma, const Name& nm);
|
||||
MultiArrayOperationRoot(const MultiArrayOperationRoot& in);
|
||||
MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in);
|
||||
|
||||
MultiArrayOperationRoot& operator=(MultiArrayOperationRoot& in);
|
||||
|
@ -173,6 +175,7 @@ namespace MultiArrayTools
|
|||
|
||||
ConstMultiArrayOperationRoot(const MultiArrayBase<T,Range>& ma, const Name& nm);
|
||||
ConstMultiArrayOperationRoot(const MultiArrayOperationRoot<T,Range>& in);
|
||||
ConstMultiArrayOperationRoot(const ConstMultiArrayOperationRoot& in);
|
||||
|
||||
template <class Operation, class... MAOps>
|
||||
MultiArrayOperation<T,Operation,ConstMultiArrayOperationRoot<T,Range>, MAOps...>
|
||||
|
@ -306,8 +309,17 @@ namespace MultiArrayTools
|
|||
typedef MultiArrayOperationBase<T> MAOB;
|
||||
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>
|
||||
MultiArrayOperation<T,Operation2,MultiArrayContraction<T,ContractOperation,Range,MAOps...>,MAOps2...>
|
||||
|
|
|
@ -194,7 +194,7 @@ namespace MultiArrayTools
|
|||
#ifdef LORENTZ_DIMENSION
|
||||
return LORENTZ_DIMENSION;
|
||||
#else
|
||||
return 1; // 4
|
||||
return 4; // 4
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue