continuing...

This commit is contained in:
Christian Zimmermann 2017-05-22 18:21:14 +02:00
parent 030d26a3bb
commit 3fde2b9f66
5 changed files with 120 additions and 209 deletions

View file

@ -9,10 +9,7 @@ namespace MultiArrayTools
IndefinitIndexBase::~IndefinitIndexBase() IndefinitIndexBase::~IndefinitIndexBase()
{ {
//freeLinked();
mLinked = nullptr;
mMajor = nullptr; mMajor = nullptr;
mSoftLinked = nullptr;
} }
size_t IndefinitIndexBase::pos() const size_t IndefinitIndexBase::pos() const
@ -21,42 +18,26 @@ namespace MultiArrayTools
return static_cast<size_t>( mPos ); return static_cast<size_t>( mPos );
} }
const std::string& IndefinitIndexBase::name() const
{
//assert(not virt());
return mName;
}
void IndefinitIndexBase::name(const std::string& str)
{
//assert(not virt());
mName = str;
}
void IndefinitIndexBase::name(const Name& nm)
{
//assert(not virt());
mName = nm.own();
}
void IndefinitIndexBase::setPos(size_t pos) void IndefinitIndexBase::setPos(size_t pos)
{ {
//CHECK; //CHECK;
//assert(not virt()); //assert(not virt());
mPos = pos; mPos = pos;
if(linked()){
mLinked->setPos(mPos);
mLinked->evalMajor();
}
} }
void IndefinitIndexBase::setPosRel(int relPos) void IndefinitIndexBase::setPosRel(int relPos)
{ {
mPos += relPos; mPos += relPos;
if(linked()){
mLinked->setPosRel(relPos);
mLinked->evalMajor(relPos);
} }
// MAJOR INDEX UPDATE !!!!!
void IndefinitIndexBase::toFirst()
{
mPos = 0;
}
void IndefinitIndexBase::toLast()
{
mPos = max() - 1;
} }
int IndefinitIndexBase::outOfRange() const int IndefinitIndexBase::outOfRange() const
@ -72,6 +53,11 @@ namespace MultiArrayTools
} }
} }
bool atEdge() const
{
return mPos == max();
}
bool IndefinitIndexBase::toNull() const bool IndefinitIndexBase::toNull() const
{ {
//assert(not virt()); //assert(not virt());

View file

@ -33,18 +33,17 @@ namespace MultiArrayTools
virtual size_t dim() const = 0; virtual size_t dim() const = 0;
virtual size_t pos() const; virtual size_t pos() const;
virtual const std::string& name() const;
virtual void name(const std::string& str);
virtual void name(const Name& nm);
virtual MultiRangeType rangeType() const = 0; virtual MultiRangeType rangeType() const = 0;
virtual void setPos(size_t pos); virtual void setPos(size_t pos);
virtual void setPosRel(int relPos); virtual void setPosRel(int relPos);
virtual IndefinitIndexBase& toFirst();
virtual IndefinitIndexBase& toLast();
virtual size_t max() const = 0; virtual size_t max() const = 0;
virtual int outOfRange() const; virtual int outOfRange() const;
virtual bool atEdge() const;
virtual bool toNull() const; virtual bool toNull() const;
virtual void eval() = 0; virtual void eval() = 0;
@ -55,17 +54,10 @@ namespace MultiArrayTools
virtual void subOrd(IndefinitIndexBase* major); virtual void subOrd(IndefinitIndexBase* major);
virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) = 0; virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) = 0;
virtual size_t majorStep() const;
//virtual bool virt() const { return true; }
protected: protected:
std::string mName;
int mPos; int mPos;
size_t mMajorStep; std::map<IndefinitIndexBase*,size_t> mMajor;
IndefinitIndexBase* mMajor = nullptr;
}; };
template <class Index> template <class Index>

View file

@ -10,6 +10,7 @@
#include <algorithm> #include <algorithm>
#include "base_def.h" #include "base_def.h"
#include "multi_range.h"
#include "multi_array_operation.h" #include "multi_array_operation.h"
#include "manipulator.h" #include "manipulator.h"
#include "name.h" #include "name.h"
@ -17,11 +18,15 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
template <typename T, class Range> template <class... Ranges>
using TopRange = MultiRange<Ranges...>;
template <typename T, class... Ranges>
class MultiArrayBase class MultiArrayBase
{ {
public: public:
typedef TopRange<Ranges...> TopRangeType
typedef T value_type; typedef T value_type;
class const_iterator : public std::iterator<std::random_access_iterator_tag,T> class const_iterator : public std::iterator<std::random_access_iterator_tag,T>
@ -31,7 +36,7 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(const_iterator); DEFAULT_MEMBERS(const_iterator);
const_iterator(const MultiArrayBase& ma); const_iterator(const MultiArrayBase& ma);
const_iterator(const MultiArrayBase& ma, const typename Range::IndexType& index); const_iterator(const MultiArrayBase& ma, const typename TopRangeType::IndexType& index);
virtual ~const_iterator() = default; virtual ~const_iterator() = default;
// Requirements: // Requirements:
@ -62,23 +67,23 @@ namespace MultiArrayTools
// Multi Array specific: // Multi Array specific:
const typename Range::IndexType& index() const; const typename TopRangeType::IndexType& index() const;
typename Range::IndexType& index(); typename TopRangeType::IndexType& index();
protected: protected:
MultiArrayBase const* mMAPtr = nullptr; MultiArrayBase const* mMAPtr = nullptr;
typename Range::IndexType mIndex; typename TopRangeType::IndexType mIndex;
}; };
DEFAULT_MEMBERS(MultiArrayBase); DEFAULT_MEMBERS(MultiArrayBase);
MultiArrayBase(const Range& range); MultiArrayBase(const TopRangeType& range);
virtual ~MultiArrayBase() = default; virtual ~MultiArrayBase() = default;
// only relevant for slices... has no effect for usual multiarrays // only relevant for slices... has no effect for usual multiarrays
virtual void link(IndefinitIndexBase* iibPtr) const; virtual void link(IndefinitIndexBase* iibPtr) const;
virtual const T& operator[](const typename Range::IndexType& i) const = 0; virtual const T& operator[](const typename TopRangeType::IndexType& i) const = 0;
virtual size_t size() const; virtual size_t size() const;
virtual bool isSlice() const = 0; virtual bool isSlice() const = 0;
@ -89,31 +94,33 @@ namespace MultiArrayTools
virtual auto beginIndex() const -> decltype(Range().begin()); virtual auto beginIndex() const -> decltype(Range().begin());
virtual auto endIndex() const -> decltype(Range().end()); virtual auto endIndex() const -> decltype(Range().end());
virtual const Range& range() const; virtual const TopRangeType& range() const;
virtual bool isConst() const; virtual bool isConst() const;
template <class... NameTypes> template <class... NameTypes>
ConstMultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str) const; ConstMultiArrayOperationRoot<T,TopRangeType> operator()(const NameTypes&... str) const;
template <class NameType> template <class NameType>
ConstMultiArrayOperationRoot<T,Range> operator()(const NameType& name, bool master) const; ConstMultiArrayOperationRoot<T,TopRangeType> operator()(const NameType& name, bool master) const;
virtual bool isInit() const; virtual bool isInit() const;
protected: protected:
bool mInit = false; bool mInit = false;
std::shared_ptr<Range> mRange; std::shared_ptr<TopRangeType> mRange;
}; };
template <typename T, class Range> template <typename T, class... Ranges>
class MutableMultiArrayBase : public MultiArrayBase<T,Range> class MutableMultiArrayBase : public MultiArrayBase<T,Ranges...>
{ {
public: public:
typedef typename MultiArrayBase<T,Range>::const_iterator const_iterator; typedef typename MultiArrayBase<T,Ranges...>::const_iterator const_iterator;
typedef MultiArrayBase<T,Range> MAB; typedef MultiArrayBase<T,Ranges...> MAB;
typedef typename MAB::TopRangeType TopRangeType;
typedef typename TopRangeType::IndexType IndexType;
class iterator : public std::iterator<std::random_access_iterator_tag,T>, class iterator : public std::iterator<std::random_access_iterator_tag,T>,
public std::iterator<std::output_iterator_tag,T> public std::iterator<std::output_iterator_tag,T>
@ -123,7 +130,7 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(iterator); DEFAULT_MEMBERS(iterator);
iterator(MutableMultiArrayBase& ma); iterator(MutableMultiArrayBase& ma);
iterator(MutableMultiArrayBase& ma, const typename Range::IndexType& index); iterator(MutableMultiArrayBase& ma, const IndexType& index);
virtual ~iterator() = default; virtual ~iterator() = default;
// Requirements: // Requirements:
@ -157,19 +164,19 @@ namespace MultiArrayTools
// Multi Array specific: // Multi Array specific:
const typename Range::IndexType& index() const; const IndexType& index() const;
typename Range::IndexType& index(); IndexType& index();
protected: protected:
MutableMultiArrayBase* mMAPtr = nullptr; MutableMultiArrayBase* mMAPtr = nullptr;
typename Range::IndexType mIndex; IndexType mIndex;
}; };
DEFAULT_MEMBERS(MutableMultiArrayBase); DEFAULT_MEMBERS(MutableMultiArrayBase);
MutableMultiArrayBase(const Range& range); MutableMultiArrayBase(const TopRangeType& range);
virtual T& operator[](const typename Range::IndexType& i) = 0; virtual T& operator[](const IndexType& i) = 0;
virtual iterator begin(); virtual iterator begin();
virtual iterator end(); virtual iterator end();
@ -177,38 +184,40 @@ namespace MultiArrayTools
virtual bool isConst() const override; virtual bool isConst() const override;
template <class... NameTypes> template <class... NameTypes>
ConstMultiArrayOperationRoot<T,Range> operator()(bool x, const NameTypes&... str) const ConstMultiArrayOperationRoot<T,Ranges...> operator()(bool x, const NameTypes&... str) const
{ {
return MAB::operator()(str...); return MAB::operator()(str...);
} }
template <class... NameTypes> template <class... NameTypes>
ConstMultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str) const; ConstMultiArrayOperationRoot<T,Ranges...> operator()(const NameTypes&... str) const;
template <class NameType> template <class NameType>
ConstMultiArrayOperationRoot<T,Range> operator()(const NameType& name, bool master) const; ConstMultiArrayOperationRoot<T,Ranges...> operator()(const NameType& name, bool master) const;
template <class... NameTypes> template <class... NameTypes>
MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str); MultiArrayOperationRoot<T,Ranges...> operator()(const NameTypes&... str);
template <class NameType> template <class NameType>
MultiArrayOperationRoot<T,Range> operator()(const NameType& name, bool master); MultiArrayOperationRoot<T,Ranges...> operator()(const NameType& name, bool master);
}; };
template <typename T, class Range> template <typename T, class Ranges...>
class MultiArray : public MutableMultiArrayBase<T,Range> class MultiArray : public MutableMultiArrayBase<T,Ranges...>
{ {
public: public:
typedef MultiArrayBase<T,Range> MAB; typedef MultiArrayBase<T,Ranges...> MAB;
typedef typename MultiArrayBase<T,Range>::const_iterator const_iterator; typedef typename MultiArrayBase<T,Ranges...>::const_iterator const_iterator;
typedef typename MutableMultiArrayBase<T,Range>::iterator iterator; typedef typename MutableMultiArrayBase<T,Ranges...>::iterator iterator;
typedef typename MAB::TopRangeType TopRangeType;
typedef typename TopRangeType::IndexType IndexType;
DEFAULT_MEMBERS(MultiArray); DEFAULT_MEMBERS(MultiArray);
MultiArray(const Range& range); MultiArray(const TopRangeType& range);
MultiArray(const Range& range, const std::vector<T>& vec); MultiArray(const TopRangeType& range, const std::vector<T>& vec);
MultiArray(const Range& range, std::vector<T>&& vec); MultiArray(const TopRangeType& range, std::vector<T>&& vec);
template <class Range2, class Range3> template <class Range2, class Range3>
MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in); MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in);
@ -218,8 +227,8 @@ namespace MultiArrayTools
template <class Range2, class Range3> template <class Range2, class Range3>
MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in); MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in);
T& operator[](const typename Range::IndexType& i) override; T& operator[](const IndexType& i) override;
const T& operator[](const typename Range::IndexType& i) const override; const T& operator[](const IndexType& i) const override;
virtual bool isConst() const override; virtual bool isConst() const override;
virtual bool isSlice() const override; virtual bool isSlice() const override;
@ -227,8 +236,8 @@ namespace MultiArrayTools
const T* data() const; const T* data() const;
// virtual void manipulate(ManipulatorBase<T>& mb, // virtual void manipulate(ManipulatorBase<T>& mb,
// const typename Range::IndexType& manBegin, // const typename Ranges...::IndexType& manBegin,
// const typename Range::IndexType& manEnd); // const typename Ranges...::IndexType& manEnd);
template <typename U, class RangeX> template <typename U, class RangeX>
friend class MultiArray; friend class MultiArray;
@ -237,18 +246,20 @@ namespace MultiArrayTools
std::vector<T> mCont; std::vector<T> mCont;
}; };
template <typename T, class Range, class Function> template <typename T, class Ranges..., class Function>
class FunctionalMultiArray : public MultiArrayBase<T,Range> class FunctionalMultiArray : public MultiArrayBase<T,Ranges...>
{ {
public: public:
typedef MultiArrayBase<T,Range> MAB; typedef MultiArrayBase<T,Ranges...> MAB;
typedef typename MultiArrayBase<T,Range>::const_iterator const_iterator; typedef typename MultiArrayBase<T,Ranges...>::const_iterator const_iterator;
typedef typename MAB::TopRangeType TopRangeType;
typedef typename TopRangeType::IndexType IndexType;
DEFAULT_MEMBERS(FunctionalMultiArray); DEFAULT_MEMBERS(FunctionalMultiArray);
//FunctionalMultiArray(const Range& range); //FunctionalMultiArray(const Ranges...& range);
FunctionalMultiArray(const Range& range, const Function& func); FunctionalMultiArray(const TopRangeType& range, const Function& func);
virtual const T& operator[](const typename Range::IndexType& i) const override; virtual const T& operator[](const IndexType& i) const override;
virtual bool isConst() const override; virtual bool isConst() const override;
virtual bool isSlice() const override; virtual bool isSlice() const override;

View file

@ -5,45 +5,30 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
/*********************************
* MultiArrayOperationRoot *
*********************************/
template <typename T>
MultiArrayOperationBase<T>::~MultiArrayOperationBase()
{
//delete mIibPtr;
}
template <typename T>
const IndefinitIndexBase& MultiArrayOperationBase<T>::index() const
{
return *mIibPtr;
}
template <typename T>
void MultiArrayOperationBase<T>::freeIndex() const
{
mIibPtr->freeLinked();
}
/********************************* /*********************************
* MultiArrayOperationBase * * MultiArrayOperationBase *
*********************************/ *********************************/
// purely virtual at the moment
/*********************************
* MultiArrayOperationRoot *
*********************************/
template <typename T, class Range> template <typename T, class Range>
void MultiArrayOperationRoot<T,Range>::performAssignment(const MultiArrayOperationBase<T>& in) void MultiArrayOperationRoot<T,Range>::performAssignment(const MultiArrayOperationBase<T>& in)
{ {
//#error "WRITE MAOR INTRINSIC CONTRACT FUNCTION" //#error "WRITE MAOR INTRINSIC CONTRACT FUNCTION"
//CHECK; //CHECK;
IndexList il = in.getIndices();
setInternalIndex(il);
in.setInternalIndex(il);
//CHECK; //CHECK;
IndexType& iref = dynamic_cast<IndexType&>(*MAOB::mIibPtr); const size_t endPos = mIndex.max();
//CHECK;
const size_t endPos = mArrayRef.endIndex().pos();
std::cout << "assignment: " << endPos << " elements" << std::endl; std::cout << "assignment: " << endPos << " elements" << std::endl;
// assignment loop // assignment loop
for(iref = mArrayRef.beginIndex().pos(); iref != mArrayRef.endIndex(); ++iref){ for(mIndex.toFirst(); not mIndex.atEdge(); ++mIndex){
//std::cout << get() << " / " << in.get() << std::endl; //std::cout << get() << " / " << in.get() << std::endl;
//std::cout << iref.pos() << '\r' << std::flush; //std::cout << iref.pos() << '\r' << std::flush;
get() = in.get(); get() = in.get();
@ -51,7 +36,6 @@ namespace MultiArrayTools
//assert(not std::isnan( get() )); //assert(not std::isnan( get() ));
} }
//CHECK; //CHECK;
} }
template <typename T, class Range> template <typename T, class Range>
@ -60,37 +44,20 @@ namespace MultiArrayTools
const Name& nm) : const Name& nm) :
MutableMultiArrayOperationBase<T>(), MutableMultiArrayOperationBase<T>(),
mArrayRef(ma), mArrayRef(ma),
mIndex(mArrayRef.beginIndex()), mNm(nm) {}
mNm(nm)
{
//CHECK;
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(nm);
//CHECK;
//mIndex.name(nm);
}
template <typename T, class Range> template <typename T, class Range>
MultiArrayOperationRoot<T,Range>:: MultiArrayOperationRoot<T,Range>::
MultiArrayOperationRoot(const MultiArrayOperationRoot& in) : MultiArrayOperationRoot(const MultiArrayOperationRoot& in) :
MutableMultiArrayOperationBase<T>(), MutableMultiArrayOperationBase<T>(),
mArrayRef(in.mArrayRef), mArrayRef(in.mArrayRef),
mIndex(mArrayRef.beginIndex()), mNm(in.mNm) {}
mNm(in.mNm)
{
//CHECK;
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
//CHECK;
//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)
{ {
performAssignment(in); performAssignment(in);
return *this; return *this;
} }
@ -309,20 +276,14 @@ namespace MultiArrayTools
T& MultiArrayOperationRoot<T,Range>::get() T& MultiArrayOperationRoot<T,Range>::get()
{ {
//CHECK; //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)];
} }
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; //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)];
} }
template <typename T, class Range> template <typename T, class Range>
@ -345,14 +306,6 @@ namespace MultiArrayTools
return *this; return *this;
} }
template <typename T, class Range>
void MultiArrayOperationRoot<T,Range>::freeIndex() const
{
mIndex = mArrayRef.beginIndex();
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
}
/************************************** /**************************************
* ConstMultiArrayOperationBase * * ConstMultiArrayOperationBase *
**************************************/ **************************************/
@ -364,39 +317,21 @@ namespace MultiArrayTools
const Name& nm) : const Name& nm) :
MultiArrayOperationBase<T>(), MultiArrayOperationBase<T>(),
mArrayRef(ma), mArrayRef(ma),
mIndex(mArrayRef.beginIndex()), mNm(nm) {}
mNm(nm)
{
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(nm);
//mIndex.name(nm);
}
template <typename T, class Range> template <typename T, class Range>
ConstMultiArrayOperationRoot<T,Range>:: ConstMultiArrayOperationRoot<T,Range>::
ConstMultiArrayOperationRoot(const MultiArrayOperationRoot<T,Range>& in) : ConstMultiArrayOperationRoot(const MultiArrayOperationRoot<T,Range>& in) :
MultiArrayOperationBase<T>(), MultiArrayOperationBase<T>(),
mArrayRef(in.getCont()), mArrayRef(in.getCont()),
mIndex(mArrayRef.beginIndex()), mNm(in.name()) {}
mNm(in.name())
{
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
//mIndex.name(nm);
}
template <typename T, class Range> template <typename T, class Range>
ConstMultiArrayOperationRoot<T,Range>:: ConstMultiArrayOperationRoot<T,Range>::
ConstMultiArrayOperationRoot(const ConstMultiArrayOperationRoot& in) : ConstMultiArrayOperationRoot(const ConstMultiArrayOperationRoot& in) :
MultiArrayOperationBase<T>(), MultiArrayOperationBase<T>(),
mArrayRef(in.mArrayRef), mArrayRef(in.mArrayRef),
mIndex(mArrayRef.beginIndex()), mNm(in.mNm) {}
mNm(in.mNm)
{
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
//mIndex.name(nm);
}
template <typename T, class Range> template <typename T, class Range>
template <class Operation, class... MAOps> template <class Operation, class... MAOps>
@ -498,8 +433,7 @@ namespace MultiArrayTools
const T& ConstMultiArrayOperationRoot<T,Range>::get() const const T& ConstMultiArrayOperationRoot<T,Range>::get() const
{ {
//CHECK; //CHECK;
//assert(MAOB::mIibPtr == &mIndex); return mArrayRef[mIndex];
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
} }
template <typename T, class Range> template <typename T, class Range>
@ -525,16 +459,7 @@ namespace MultiArrayTools
const IndexMapFunction<InRange,OutRange>& mf) : const IndexMapFunction<InRange,OutRange>& mf) :
MutableMultiArrayOperationBase<T>(), MutableMultiArrayOperationBase<T>(),
mMF(mf), mMF(mf),
mRoot(root) mRoot(root) {}
//mIndex(mArrayRef.beginIndex()),
//mNm(nm)
{
//CHECK;
MAOB::mIibPtr = &mIndex;
//CHECK;
//MAOB::mIibPtr->name(nm);
//mIndex.name(nm);
}
template <typename T, class InRange, class TotalInRange, class OutRange, class TotalRange> template <typename T, class InRange, class TotalInRange, class OutRange, class TotalRange>
MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>& MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>&
@ -543,7 +468,6 @@ namespace MultiArrayTools
{ {
mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() ); mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() );
MAOB::mIibPtr = &mIndex;
mNm = in.name(); mNm = in.name();
mIndex.name(mNm); // to be sure... mIndex.name(mNm); // to be sure...
@ -557,7 +481,7 @@ namespace MultiArrayTools
MultiArray<T,TotalRange> cnt(mRoot->range()); MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name()); MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){ for(mIndex.toFirst(), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){
get() += in.get(); get() += in.get();
cnto.get() += 1.; cnto.get() += 1.;
} }
@ -574,19 +498,18 @@ namespace MultiArrayTools
{ {
mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() ); mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() );
MAOB::mIibPtr = &mIndex;
mNm = in.name(); mNm = in.name();
mIndex.name(mNm); // to be sure... mIndex.name(mNm); // to be sure...
typename TotalInRange::IndexType endIndex = mIndex; typename TotalInRange::IndexType endIndex = mIndex;
endIndex.setPos( mIndex.max() ); ++endIndex.toLast();
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl; std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
//!!!!!!! //!!!!!!!
MultiArray<T,TotalRange> cnt(mRoot->range()); MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name()); MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){ for(mIndex.toFirst(), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){
get() += in.get(); get() += in.get();
cnto.get() += 1.; cnto.get() += 1.;
} }
@ -765,8 +688,8 @@ namespace MultiArrayTools
mBeginIndex(runIndex), mEndIndex(runIndex), mBeginIndex(runIndex), mEndIndex(runIndex),
mRunIndex(runIndex) mRunIndex(runIndex)
{ {
mBeginIndex.setPos(0); mBeginIndex.toFirst();
mEndIndex.setPos(mRunIndex.max()); ++mEndIndex.toLast();
// DON'T link here !! // DON'T link here !!
//linkIndicesTo(&mRunIndex); //linkIndicesTo(&mRunIndex);
} }
@ -817,7 +740,7 @@ namespace MultiArrayTools
const std::string& indexName, const std::string& indexName,
const MAOps2&... mao) const const MAOps2&... mao) const
{ {
typename Range2::IndexType* ind = dynamic_cast<typename Range2::IndexType*>( getLinked(indexName) ); //
return MultiArrayContraction<T,ContractOperation2,Range2,MultiArrayContraction<T,ContractOperation,Range,MAOps...>, return MultiArrayContraction<T,ContractOperation2,Range2,MultiArrayContraction<T,ContractOperation,Range,MAOps...>,
MAOps2...>(cop, *ind, *this, mao...); MAOps2...>(cop, *ind, *this, mao...);
} }
@ -865,7 +788,7 @@ namespace MultiArrayTools
{ {
//CHECK; //CHECK;
mOp.reset(); mOp.reset();
for(mRunIndex.copyPos( mBeginIndex ); mRunIndex.pos() != mEndIndex.pos(); ++mRunIndex){ for(mRunIndex = mBeginIndex ; mRunIndex != mEndIndex; ++mRunIndex){
OperationCall<sizeof...(MAOps)-1>:: OperationCall<sizeof...(MAOps)-1>::
template callOperation(mOp, mArgs); template callOperation(mOp, mArgs);
} }

View file

@ -13,6 +13,8 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
typedef std::vector<std::shared_ptr<IndefinitIndexBase> > IndexList;
template <typename T> template <typename T>
class MultiArrayOperationBase class MultiArrayOperationBase
{ {
@ -21,18 +23,15 @@ namespace MultiArrayTools
typedef T value_type; typedef T value_type;
MultiArrayOperationBase() /*{ CHECK; }*/ = default; MultiArrayOperationBase() /*{ CHECK; }*/ = default;
//MultiArrayOperationBase(const MultiArrayOperationBase& in) = default;
virtual ~MultiArrayOperationBase(); virtual ~MultiArrayOperationBase();
virtual size_t argNum() const = 0; virtual size_t argNum() const = 0;
const IndefinitIndexBase& index() const; const IndefinitIndexBase& index() const = 0;
virtual const T& get() const = 0; virtual const T& get() const = 0;
virtual IndexList getIndices() const = 0;
virtual void setInternalIndex(const IndexList& il) = 0;
protected:
mutable IndefinitIndexBase* mIibPtr = nullptr;
}; };
@ -42,7 +41,6 @@ namespace MultiArrayTools
public: public:
MutableMultiArrayOperationBase() /*{ CHECK; }*/ = default; MutableMultiArrayOperationBase() /*{ CHECK; }*/ = default;
//MutableMultiArrayOperationBase(const MutableMultiArrayOperationBase& in) = default;
virtual T& get() = 0; virtual T& get() = 0;
}; };
@ -316,13 +314,14 @@ namespace MultiArrayTools
typedef MultiArrayOperationBase<T> MAOB; typedef MultiArrayOperationBase<T> MAOB;
typedef std::tuple<MAOps...> OBT; typedef std::tuple<MAOps...> OBT;
typedef typename Range::IndexType RunIndexType;
MultiArrayContraction(const ContractOperation& cop, MultiArrayContraction(const ContractOperation& cop,
const typename Range::IndexType& runIndex, const RunIndexType& runIndex,
const MAOps&... mao); const MAOps&... mao);
MultiArrayContraction(const ContractOperation& cop, MultiArrayContraction(const ContractOperation& cop,
const typename Range::IndexType& runIndex, const RunIndexType& runIndex,
size_t begin, size_t begin,
size_t end, size_t end,
const MAOps&... mao); const MAOps&... mao);
@ -364,9 +363,9 @@ namespace MultiArrayTools
mutable T mVal; mutable T mVal;
ContractOperation mOp; ContractOperation mOp;
OBT mArgs; // include first arg also here !!! OBT mArgs; // include first arg also here !!!
typename Range::IndexType mBeginIndex; RunIndexType mBeginIndex;
typename Range::IndexType mEndIndex; RunIndexType mEndIndex;
mutable typename Range::IndexType mRunIndex; mutable RunIndexType mRunIndex;
}; };
} }