From 871a9be3832cfa05f88b5e8c2c5d5214a2c250d1 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 28 Mar 2017 17:55:12 +0200 Subject: [PATCH] first index mapping application works --- src/base_def.h | 13 +++---- src/ma_functional.cc | 9 ++--- src/ma_functional.h | 19 ++++++---- src/multi_array.cc | 6 ++-- src/multi_array.h | 2 +- src/multi_array_operation.cc | 67 +++++++++++++++++++++++++----------- src/multi_array_operation.h | 4 +++ 7 files changed, 79 insertions(+), 41 deletions(-) diff --git a/src/base_def.h b/src/base_def.h index 8e77542..3266202 100644 --- a/src/base_def.h +++ b/src/base_def.h @@ -5,12 +5,6 @@ #include -#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 #ifdef DEBUG_MODE_X @@ -26,6 +20,13 @@ #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 { template diff --git a/src/ma_functional.cc b/src/ma_functional.cc index 5d5e3b8..95b8e10 100644 --- a/src/ma_functional.cc +++ b/src/ma_functional.cc @@ -13,6 +13,7 @@ namespace MultiArrayTools mOutRange(new OutRange( outRange )), mOIndex(mOutRange->begin()) { + //CHECK; mOIndex.name(outName); } @@ -35,10 +36,10 @@ namespace MultiArrayTools } - /* - vec3d2Function::vec3d2Function(std::shared_ptr& outRange) : mOutRange(outRange), - out(mOutRange->begin()) {} - */ + + vec3d2Function::vec3d2Function(const OutRange& outRange) : mOutRange(new OutRange( outRange )), + out(mOutRange->begin()) {} + vec3d2Function::OutIndex vec3d2Function::operator()(const InIndex& i) const { OutSubIndex& osi = out.template getIndex<0>(); diff --git a/src/ma_functional.h b/src/ma_functional.h index 4b86de6..fb69163 100644 --- a/src/ma_functional.h +++ b/src/ma_functional.h @@ -21,9 +21,13 @@ namespace MultiArrayTools typedef OutRange OR; typedef typename OutRange::IndexType OutIndex; + //IndexMapFunction() = default; + IndexMapFunction(const MultiArrayBase& ma, const OutRange& outRange, const Name& inName, const Name& outName); + + IndexMapFunction(const IndexMapFunction& in) = default; void linkIndicesTo(IndefinitIndexBase* target); void eval() const; @@ -45,16 +49,17 @@ namespace MultiArrayTools typedef MultiIndex InIndex; typedef SingleIndex OutSubIndex; typedef MultiIndex OutIndex; - - vec3d2Function() = default; - //vec3d2Function(std::shared_ptr& outRange); - vec3d2Function(const vec3d2Function& in) = default; - vec3d2Function& operator=(const vec3d2Function& in) = default; + typedef MultiRange > OutRange; + + DEFAULT_MEMBERS(vec3d2Function); + + vec3d2Function(const OutRange& outRange); + //vec3d2Function& operator=(const vec3d2Function& in) = default; OutIndex operator()(const InIndex& i) const; - + private: - //std::shared_ptr mOutRange; + std::shared_ptr mOutRange; mutable OutIndex out; }; diff --git a/src/multi_array.cc b/src/multi_array.cc index 91c8ab0..3592fc3 100644 --- a/src/multi_array.cc +++ b/src/multi_array.cc @@ -183,6 +183,7 @@ namespace MultiArrayTools template auto MultiArrayBase::beginIndex() const -> decltype(Range().begin()) { + //CHECK; return mRange->begin(); } @@ -561,14 +562,15 @@ namespace MultiArrayTools * FunctionalMultiArray * ****************************/ + /* template FunctionalMultiArray::FunctionalMultiArray(const Range& range) : MultiArrayBase(range), mFunc() {} - + */ template FunctionalMultiArray::FunctionalMultiArray(const Range& range, const Function& func) : - MultiArrayBase(range), mFunc(func) {} + MultiArrayBase(range), mFunc(func) { /*CHECK;*/ } template const T& FunctionalMultiArray::operator[](const typename Range::IndexType& i) const diff --git a/src/multi_array.h b/src/multi_array.h index fe2ffa2..058c35f 100644 --- a/src/multi_array.h +++ b/src/multi_array.h @@ -243,7 +243,7 @@ namespace MultiArrayTools typedef typename MultiArrayBase::const_iterator const_iterator; DEFAULT_MEMBERS(FunctionalMultiArray); - FunctionalMultiArray(const Range& range); + //FunctionalMultiArray(const Range& range); FunctionalMultiArray(const Range& range, const Function& func); virtual const T& operator[](const typename Range::IndexType& i) const override; diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index d649d3f..64911a4 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -44,8 +44,10 @@ namespace MultiArrayTools std::cout << "assignment: " << endPos << " elements" << std::endl; // assignment loop for(iref = mArrayRef.beginIndex().pos(); iref != mArrayRef.endIndex(); ++iref){ + //std::cout << get() << " / " << in.get() << std::endl; //std::cout << iref.pos() << '\r' << std::flush; get() = in.get(); + //assert(not std::isnan( get() )); } //CHECK; @@ -61,8 +63,10 @@ namespace MultiArrayTools mIndex(mArrayRef.beginIndex()), mNm(nm) { + //CHECK; MAOB::mIibPtr = &mIndex; MAOB::mIibPtr->name(nm); + //CHECK; //mIndex.name(nm); } @@ -74,8 +78,10 @@ namespace MultiArrayTools mIndex(mArrayRef.beginIndex()), mNm(in.mNm) { + //CHECK; MAOB::mIibPtr = &mIndex; MAOB::mIibPtr->name(mNm); + //CHECK; //mIndex.name(nm); } @@ -180,7 +186,10 @@ namespace MultiArrayTools MultiArrayOperationMap MultiArrayOperationRoot::map(const IndexMapFunction& imf) { - return MultiArrayOperationMap(*this, imf); + //CHECK; + MultiArrayOperationMap mom(*this, imf); + //CHECK; + return mom; } template @@ -292,7 +301,7 @@ namespace MultiArrayTools { //CHECK; //return mArrayRef[mIndex]; - assert(MAOB::mIibPtr == &mIndex); + //assert(MAOB::mIibPtr == &mIndex); //VCHECK(mArrayRef[*dynamic_cast(MAOB::mIibPtr)]); return mArrayRef[*dynamic_cast(MAOB::mIibPtr)]; } @@ -302,7 +311,7 @@ namespace MultiArrayTools { //CHECK; //return mArrayRef[mIndex]; - assert(MAOB::mIibPtr == &mIndex); + //assert(MAOB::mIibPtr == &mIndex); //VCHECK(mArrayRef[*dynamic_cast(MAOB::mIibPtr)]); return mArrayRef[*dynamic_cast(MAOB::mIibPtr)]; } @@ -494,7 +503,7 @@ namespace MultiArrayTools const T& ConstMultiArrayOperationRoot::get() const { //CHECK; - assert(MAOB::mIibPtr == &mIndex); + //assert(MAOB::mIibPtr == &mIndex); return mArrayRef[*dynamic_cast(MAOB::mIibPtr)]; } @@ -534,37 +543,46 @@ namespace MultiArrayTools //mIndex(mArrayRef.beginIndex()), //mNm(nm) { + //CHECK; MAOB::mIibPtr = &mIndex; + //CHECK; //MAOB::mIibPtr->name(nm); //mIndex.name(nm); } - + template MultiArrayOperationMap& MultiArrayOperationMap:: operator=(const MultiArrayOperationRoot& in) { mIndex = dynamic_cast( in.index() ); + MAOB::mIibPtr = &mIndex; mNm = in.name(); mIndex.name(mNm); // to be sure... - mIndex.setPos( mIndex.max() ); + 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() ); mMF.linkIndicesTo( &mIndex ); - - MultiArray cnt(mRoot->range()); - auto cnto = cnt(mRoot.name(), true); + in.linkIndicesTo( &mIndex ); + + MultiArray cnt(mRoot->range()); + MultiArrayOperationRoot cnto(cnt, mRoot.name()); + cnto.linkIndicesTo( &mIndex ); cnto.linkIndicesTo( &mMF.index() ); for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){ get() += in.get(); - ++cnto.get(); + cnto.get() += 1.; } + mRoot.freeIndex(); // CHECK whether T / size_t mixture works!! - mRoot /= cnto; + mRoot /= cnt(mRoot.name(), true); return *this; } @@ -573,27 +591,34 @@ namespace MultiArrayTools MultiArrayOperationMap:: operator=(const ConstMultiArrayOperationRoot& in) { - mIndex = dynamic_cast( in.index() ); + mIndex = dynamic_cast( in.index() ); + MAOB::mIibPtr = &mIndex; mNm = in.name(); 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() ); mMF.linkIndicesTo( &mIndex ); - - MultiArray cnt(mRoot->range()); - auto cnto = cnt(mRoot.name(), true); + in.linkIndicesTo( &mIndex ); + + MultiArray cnt(mRoot->range()); + MultiArrayOperationRoot cnto(cnt, mRoot.name()); + cnto.linkIndicesTo( &mIndex ); cnto.linkIndicesTo( &mMF.index() ); for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){ get() += in.get(); - ++cnto.get(); + cnto.get() += 1.; } + mRoot.freeIndex(); // CHECK whether T / size_t mixture works!! - mRoot /= cnto; + mRoot /= cnt(mRoot.name(), true); return *this; } diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index bc79481..1aa590d 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -21,6 +21,7 @@ namespace MultiArrayTools typedef T value_type; MultiArrayOperationBase() /*{ CHECK; }*/ = default; + //MultiArrayOperationBase(const MultiArrayOperationBase& in) = default; virtual ~MultiArrayOperationBase(); virtual size_t argNum() const = 0; @@ -45,6 +46,7 @@ namespace MultiArrayTools public: MutableMultiArrayOperationBase() /*{ CHECK; }*/ = default; + //MutableMultiArrayOperationBase(const MutableMultiArrayOperationBase& in) = default; virtual T& get() = 0; }; @@ -250,6 +252,8 @@ namespace MultiArrayTools MultiArrayOperationMap(MultiArrayOperationRoot& root, const IndexMapFunction& mf); + MultiArrayOperationMap(const MultiArrayOperationMap& in) = default; + MultiArrayOperationMap& operator=(const MultiArrayOperationRoot& in); MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot& in);