start implementing map and functional array

This commit is contained in:
Christian Zimmermann 2017-03-26 16:55:52 +02:00
parent 344ae475ae
commit 6126188ed0
3 changed files with 108 additions and 15 deletions

View file

@ -211,6 +211,8 @@ namespace MultiArrayTools
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);
// implement contstructor using FunctionalMultiArray as Input !!!
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);
@ -231,6 +233,26 @@ namespace MultiArrayTools
std::vector<T> mCont; std::vector<T> mCont;
}; };
template <typename T, class Range>
class FunctionalMultiArray : public MultiArrayBase<T>
{
public:
typedef MultiArrayBase<T,Range> MAB;
typedef typename MultiArrayBase<T,Range>::const_iterator const_iterator;
DEFAULT_MEMBERS(FunctionalMultiArray);
FunctionalMultiArray(const Range& range, /*Function*/);
T& operator[](const typename Range::IndexType& i) override;
const T& operator[](const typename Range::IndexType& i) const override;
virtual bool isConst() const override;
virtual bool isSlice() const override;
protected:
// FUNCTION !!!!
};
} }
#include "multi_array.cc" #include "multi_array.cc"

View file

@ -513,6 +513,66 @@ namespace MultiArrayTools
MAOB::mIibPtr->name(mNm); MAOB::mIibPtr->name(mNm);
} }
/********************************
* MultiArrayOperationMap *
********************************/
template <typename T, class MapFunction, class InRange, class OutRange>
MultiArrayOperationMap<T,MapFunction,InRange,OutRange>::
MultiArrayOperationMap(MultiArrayOperationRoot<T,OutRange>& root, const MapFunction mf) :
MultiArrayOperationBase<T>(),
mMF(mf),
mRoot(root)
//mIndex(mArrayRef.beginIndex()),
//mNm(nm)
{
MAOB::mIibPtr = &mIndex;
//MAOB::mIibPtr->name(nm);
//mIndex.name(nm);
}
template <typename T, class MapFunction, class InRange, class OutRange>
MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot<T,InRange>& in)
{
mIndex = dynamic_cast<typename InRange::IndexType&>( in.getIndex() );
MAOB::mIibPtr = &mIndex;
mNm = in.name();
mIndex.setPos( mIndex.max() );
typename OutRange::IndexType endIndex = mIndex;
// Implement Map Functions !!!!
mRoot.linkIndicesTo( &mMF.index() );
mMF.linkIndicesTo( &mIndex );
MultiArray<size_t,OutRange> cnt(mRoot->range());
auto cnto = cnt(mRoot.name(), true);
cnto.linkIndicesTo( &mMF.index() )
for(mIndex.setPos(0); mIndex != endIndex; ++mIndex){
mRoot.get() += in.get();
++cnto.get();
}
mRoot /= cnto;
}
template <typename T, class MapFunction, class InRange, class OutRange>
virtual size_t argNum() const override;
template <typename T, class MapFunction, class InRange, class OutRange>
virtual IndefinitIndexBase* getLinked(const std::string& name) const override;
template <typename T, class MapFunction, class InRange, class OutRange>
virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
template <typename T, class MapFunction, class InRange, class OutRange>
virtual void setInternalLinks() const override;
template <typename T, class MapFunction, class InRange, class OutRange>
virtual const T& get() const override;
template <typename T, class MapFunction, class InRange, class OutRange>
virtual T& get() override;
/***************************** /*****************************
* MultiArrayOperation * * MultiArrayOperation *

View file

@ -154,13 +154,6 @@ namespace MultiArrayTools
void performAssignment(const MultiArrayOperationBase<T>& in); void performAssignment(const MultiArrayOperationBase<T>& in);
/*
template <class RangeX>
MultiArrayOperationRoot& makeSlice(MultiArrayOperationRoot<T,RangeX>& in);
template <class RangeX>
const MultiArrayOperationRoot& makeConstSlice(const MultiArrayOperationRoot<T,RangeX>& in);
*/
MutableMultiArrayBase<T,Range>& mArrayRef; MutableMultiArrayBase<T,Range>& mArrayRef;
mutable IndexType mIndex; mutable IndexType mIndex;
Name mNm; Name mNm;
@ -238,19 +231,37 @@ namespace MultiArrayTools
protected: protected:
/*
template <class RangeX>
const ConstMultiArrayOperationRoot& makeConstSlice(const ConstMultiArrayOperationRoot<T,RangeX>& in);
template <class RangeX>
const ConstMultiArrayOperationRoot& makeConstSlice(const MultiArrayOperationRoot<T,RangeX>& in);
*/
// const
MultiArrayBase<T,Range> const& mArrayRef; MultiArrayBase<T,Range> const& mArrayRef;
mutable IndexType mIndex; mutable IndexType mIndex;
Name mNm; Name mNm;
}; };
template <typename T, class MapFunction, class InRange, class OutRange>
class MultiArrayOperationMap : public MutableMultiArrayOperationBase<T>
{
public:
typedef MultiArrayOperationBase<T> MAOB;
MultiArrayOperationMap(MultiArrayOperationRoot<T,OutRange>& root, const MapFunction mf);
MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot<T,InRange>& in);
virtual size_t argNum() const override;
virtual IndefinitIndexBase* getLinked(const std::string& name) const override;
virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
virtual void setInternalLinks() const override;
virtual const T& get() const override;
virtual T& get() override;
// !!!!
protected:
MapFunction mMF;
MultiArrayOperationRoot<T,OutRange>& mRoot;
mutable IndexType mIndex; // Index of incoming range
Name mNm; // Name of incoming range
};
template <typename T, class Operation, class... MAOps> template <typename T, class Operation, class... MAOps>
class MultiArrayOperation : public MultiArrayOperationBase<T> class MultiArrayOperation : public MultiArrayOperationBase<T>
{ {