first index mapping application works

This commit is contained in:
Christian Zimmermann 2017-03-28 17:55:12 +02:00
parent 83a712a772
commit 871a9be383
7 changed files with 79 additions and 41 deletions

View file

@ -5,12 +5,6 @@
#include <cassert> #include <cassert>
#define DEFAULT_MEMBERS(__class_name__) __class_name__() = default; \
__class_name__(const __class_name__& in) = default; \
__class_name__& operator=(const __class_name__& in) = default; \
__class_name__(__class_name__&& in) = default; \
__class_name__& operator=(__class_name__&& in) = default
#define DEBUG_MODE_X #define DEBUG_MODE_X
#ifdef DEBUG_MODE_X #ifdef DEBUG_MODE_X
@ -26,6 +20,13 @@
#endif #endif
#define DEFAULT_MEMBERS(__class_name__) __class_name__() = default; \
__class_name__(const __class_name__& in) = default; \
__class_name__& operator=(const __class_name__& in) = default; \
__class_name__(__class_name__&& in) = default; \
__class_name__& operator=(__class_name__&& in) = default
namespace MultiArrayTools namespace MultiArrayTools
{ {
template <class MultiArray> template <class MultiArray>

View file

@ -13,6 +13,7 @@ namespace MultiArrayTools
mOutRange(new OutRange( outRange )), mOutRange(new OutRange( outRange )),
mOIndex(mOutRange->begin()) mOIndex(mOutRange->begin())
{ {
//CHECK;
mOIndex.name(outName); mOIndex.name(outName);
} }
@ -35,10 +36,10 @@ namespace MultiArrayTools
} }
/*
vec3d2Function::vec3d2Function(std::shared_ptr<OutRange>& outRange) : mOutRange(outRange), vec3d2Function::vec3d2Function(const OutRange& outRange) : mOutRange(new OutRange( outRange )),
out(mOutRange->begin()) {} out(mOutRange->begin()) {}
*/
vec3d2Function::OutIndex vec3d2Function::operator()(const InIndex& i) const vec3d2Function::OutIndex vec3d2Function::operator()(const InIndex& i) const
{ {
OutSubIndex& osi = out.template getIndex<0>(); OutSubIndex& osi = out.template getIndex<0>();

View file

@ -21,9 +21,13 @@ namespace MultiArrayTools
typedef OutRange OR; typedef OutRange OR;
typedef typename OutRange::IndexType OutIndex; typedef typename OutRange::IndexType OutIndex;
//IndexMapFunction() = default;
IndexMapFunction(const MultiArrayBase<typename OutRange::IndexType,InRange>& ma, IndexMapFunction(const MultiArrayBase<typename OutRange::IndexType,InRange>& ma,
const OutRange& outRange, const OutRange& outRange,
const Name& inName, const Name& outName); const Name& inName, const Name& outName);
IndexMapFunction(const IndexMapFunction& in) = default;
void linkIndicesTo(IndefinitIndexBase* target); void linkIndicesTo(IndefinitIndexBase* target);
void eval() const; void eval() const;
@ -45,16 +49,17 @@ namespace MultiArrayTools
typedef MultiIndex<CoordIndex,CoordIndex,CoordIndex> InIndex; typedef MultiIndex<CoordIndex,CoordIndex,CoordIndex> InIndex;
typedef SingleIndex<size_t,RangeType::DISTANCE> OutSubIndex; typedef SingleIndex<size_t,RangeType::DISTANCE> OutSubIndex;
typedef MultiIndex<OutSubIndex> OutIndex; typedef MultiIndex<OutSubIndex> OutIndex;
typedef MultiRange<SingleRange<size_t,RangeType::DISTANCE> > OutRange;
vec3d2Function() = default;
//vec3d2Function(std::shared_ptr<OutRange>& outRange); DEFAULT_MEMBERS(vec3d2Function);
vec3d2Function(const vec3d2Function& in) = default;
vec3d2Function& operator=(const vec3d2Function& in) = default; vec3d2Function(const OutRange& outRange);
//vec3d2Function& operator=(const vec3d2Function& in) = default;
OutIndex operator()(const InIndex& i) const; OutIndex operator()(const InIndex& i) const;
private: private:
//std::shared_ptr<OutRange> mOutRange; std::shared_ptr<OutRange> mOutRange;
mutable OutIndex out; mutable OutIndex out;
}; };

View file

@ -183,6 +183,7 @@ namespace MultiArrayTools
template <typename T, class Range> template <typename T, class Range>
auto MultiArrayBase<T,Range>::beginIndex() const -> decltype(Range().begin()) auto MultiArrayBase<T,Range>::beginIndex() const -> decltype(Range().begin())
{ {
//CHECK;
return mRange->begin(); return mRange->begin();
} }
@ -561,14 +562,15 @@ namespace MultiArrayTools
* FunctionalMultiArray * * FunctionalMultiArray *
****************************/ ****************************/
/*
template <typename T, class Range, class Function> template <typename T, class Range, class Function>
FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range) : FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range) :
MultiArrayBase<T,Range>(range), mFunc() {} MultiArrayBase<T,Range>(range), mFunc() {}
*/
template <typename T, class Range, class Function> template <typename T, class Range, class Function>
FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range, FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range,
const Function& func) : const Function& func) :
MultiArrayBase<T,Range>(range), mFunc(func) {} MultiArrayBase<T,Range>(range), mFunc(func) { /*CHECK;*/ }
template <typename T, class Range, class Function> template <typename T, class Range, class Function>
const T& FunctionalMultiArray<T,Range,Function>::operator[](const typename Range::IndexType& i) const const T& FunctionalMultiArray<T,Range,Function>::operator[](const typename Range::IndexType& i) const

View file

@ -243,7 +243,7 @@ namespace MultiArrayTools
typedef typename MultiArrayBase<T,Range>::const_iterator const_iterator; typedef typename MultiArrayBase<T,Range>::const_iterator const_iterator;
DEFAULT_MEMBERS(FunctionalMultiArray); DEFAULT_MEMBERS(FunctionalMultiArray);
FunctionalMultiArray(const Range& range); //FunctionalMultiArray(const Range& range);
FunctionalMultiArray(const Range& range, const Function& func); FunctionalMultiArray(const Range& range, const Function& func);
virtual const T& operator[](const typename Range::IndexType& i) const override; virtual const T& operator[](const typename Range::IndexType& i) const override;

View file

@ -44,8 +44,10 @@ namespace MultiArrayTools
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(iref = mArrayRef.beginIndex().pos(); iref != mArrayRef.endIndex(); ++iref){
//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();
//assert(not std::isnan( get() )); //assert(not std::isnan( get() ));
} }
//CHECK; //CHECK;
@ -61,8 +63,10 @@ namespace MultiArrayTools
mIndex(mArrayRef.beginIndex()), mIndex(mArrayRef.beginIndex()),
mNm(nm) mNm(nm)
{ {
//CHECK;
MAOB::mIibPtr = &mIndex; MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(nm); MAOB::mIibPtr->name(nm);
//CHECK;
//mIndex.name(nm); //mIndex.name(nm);
} }
@ -74,8 +78,10 @@ namespace MultiArrayTools
mIndex(mArrayRef.beginIndex()), mIndex(mArrayRef.beginIndex()),
mNm(in.mNm) mNm(in.mNm)
{ {
//CHECK;
MAOB::mIibPtr = &mIndex; MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm); MAOB::mIibPtr->name(mNm);
//CHECK;
//mIndex.name(nm); //mIndex.name(nm);
} }
@ -180,7 +186,10 @@ namespace MultiArrayTools
MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,Range> MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,Range>
MultiArrayOperationRoot<T,Range>::map(const IndexMapFunction<InRange,OutRange>& imf) MultiArrayOperationRoot<T,Range>::map(const IndexMapFunction<InRange,OutRange>& imf)
{ {
return MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,Range>(*this, imf); //CHECK;
MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,Range> mom(*this, imf);
//CHECK;
return mom;
} }
template <typename T, class Range> template <typename T, class Range>
@ -292,7 +301,7 @@ namespace MultiArrayTools
{ {
//CHECK; //CHECK;
//return mArrayRef[mIndex]; //return mArrayRef[mIndex];
assert(MAOB::mIibPtr == &mIndex); //assert(MAOB::mIibPtr == &mIndex);
//VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]); //VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]; return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
} }
@ -302,7 +311,7 @@ namespace MultiArrayTools
{ {
//CHECK; //CHECK;
//return mArrayRef[mIndex]; //return mArrayRef[mIndex];
assert(MAOB::mIibPtr == &mIndex); //assert(MAOB::mIibPtr == &mIndex);
//VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]); //VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]; return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
} }
@ -494,7 +503,7 @@ namespace MultiArrayTools
const T& ConstMultiArrayOperationRoot<T,Range>::get() const const T& ConstMultiArrayOperationRoot<T,Range>::get() const
{ {
//CHECK; //CHECK;
assert(MAOB::mIibPtr == &mIndex); //assert(MAOB::mIibPtr == &mIndex);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]; return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
} }
@ -534,37 +543,46 @@ namespace MultiArrayTools
//mIndex(mArrayRef.beginIndex()), //mIndex(mArrayRef.beginIndex()),
//mNm(nm) //mNm(nm)
{ {
//CHECK;
MAOB::mIibPtr = &mIndex; MAOB::mIibPtr = &mIndex;
//CHECK;
//MAOB::mIibPtr->name(nm); //MAOB::mIibPtr->name(nm);
//mIndex.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>&
MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>:: MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>::
operator=(const MultiArrayOperationRoot<T,TotalInRange>& in) operator=(const MultiArrayOperationRoot<T,TotalInRange>& in)
{ {
mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() ); mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() );
MAOB::mIibPtr = &mIndex; MAOB::mIibPtr = &mIndex;
mNm = in.name(); mNm = in.name();
mIndex.name(mNm); // to be sure... mIndex.name(mNm); // to be sure...
mIndex.setPos( mIndex.max() );
typename TotalInRange::IndexType endIndex = mIndex; typename TotalInRange::IndexType endIndex = mIndex;
endIndex.setPos( mIndex.max() );
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
// Implement Map Functions !!!! mRoot.linkIndicesTo( &mIndex );
mRoot.linkIndicesTo( &mMF.index() ); mRoot.linkIndicesTo( &mMF.index() );
mMF.linkIndicesTo( &mIndex ); mMF.linkIndicesTo( &mIndex );
in.linkIndicesTo( &mIndex );
MultiArray<size_t,TotalRange> cnt(mRoot->range());
auto cnto = cnt(mRoot.name(), true); MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
cnto.linkIndicesTo( &mIndex );
cnto.linkIndicesTo( &mMF.index() ); cnto.linkIndicesTo( &mMF.index() );
for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){ for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){
get() += in.get(); get() += in.get();
++cnto.get(); cnto.get() += 1.;
} }
mRoot.freeIndex();
// CHECK whether T / size_t mixture works!! // CHECK whether T / size_t mixture works!!
mRoot /= cnto; mRoot /= cnt(mRoot.name(), true);
return *this; return *this;
} }
@ -573,27 +591,34 @@ namespace MultiArrayTools
MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>:: MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>::
operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in) operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in)
{ {
mIndex = dynamic_cast<typename InRange::IndexType&>( in.index() ); mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() );
MAOB::mIibPtr = &mIndex; MAOB::mIibPtr = &mIndex;
mNm = in.name(); mNm = in.name();
mIndex.name(mNm); // to be sure... mIndex.name(mNm); // to be sure...
mIndex.setPos( mIndex.max() );
typename OutRange::IndexType endIndex = mIndex; typename TotalInRange::IndexType endIndex = mIndex;
endIndex.setPos( mIndex.max() );
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
// Implement Map Functions !!!! mRoot.linkIndicesTo( &mIndex );
mRoot.linkIndicesTo( &mMF.index() ); mRoot.linkIndicesTo( &mMF.index() );
mMF.linkIndicesTo( &mIndex ); mMF.linkIndicesTo( &mIndex );
in.linkIndicesTo( &mIndex );
MultiArray<size_t,OutRange> cnt(mRoot->range());
auto cnto = cnt(mRoot.name(), true); MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
cnto.linkIndicesTo( &mIndex );
cnto.linkIndicesTo( &mMF.index() ); cnto.linkIndicesTo( &mMF.index() );
for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){ for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){
get() += in.get(); get() += in.get();
++cnto.get(); cnto.get() += 1.;
} }
mRoot.freeIndex();
// CHECK whether T / size_t mixture works!! // CHECK whether T / size_t mixture works!!
mRoot /= cnto; mRoot /= cnt(mRoot.name(), true);
return *this; return *this;
} }

View file

@ -21,6 +21,7 @@ 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;
@ -45,6 +46,7 @@ namespace MultiArrayTools
public: public:
MutableMultiArrayOperationBase() /*{ CHECK; }*/ = default; MutableMultiArrayOperationBase() /*{ CHECK; }*/ = default;
//MutableMultiArrayOperationBase(const MutableMultiArrayOperationBase& in) = default;
virtual T& get() = 0; virtual T& get() = 0;
}; };
@ -250,6 +252,8 @@ namespace MultiArrayTools
MultiArrayOperationMap(MultiArrayOperationRoot<T,TotalRange>& root, MultiArrayOperationMap(MultiArrayOperationRoot<T,TotalRange>& root,
const IndexMapFunction<InRange,OutRange>& mf); const IndexMapFunction<InRange,OutRange>& mf);
MultiArrayOperationMap(const MultiArrayOperationMap& in) = default;
MultiArrayOperationMap& operator=(const MultiArrayOperationRoot<T,TotalInRange>& in); MultiArrayOperationMap& operator=(const MultiArrayOperationRoot<T,TotalInRange>& in);
MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in); MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in);