From b50620a451ba8105bae038dd990e6908104965bb Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 11 Aug 2017 16:45:03 +0200 Subject: [PATCH] make first operation test run (index copying not supported at the moment) --- src/container_range.cc | 6 +++--- src/container_range.h | 6 +++--- src/multi_array.cc | 2 +- src/multi_array_operation.cc | 17 ++++++----------- src/multi_range.cc | 10 ++++------ src/multi_range.h | 6 +++--- src/op_unit_test.cc | 6 +++++- src/single_range.h | 4 ++-- 8 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/container_range.cc b/src/container_range.cc index 634c455..ffa784d 100644 --- a/src/container_range.cc +++ b/src/container_range.cc @@ -14,7 +14,7 @@ namespace MultiArrayTools /********************** * ContainerIndex * **********************/ - + /* template ContainerIndex::ContainerIndex(const ContainerIndex& in) : IndexInterface >(in) @@ -31,7 +31,7 @@ namespace MultiArrayTools IB::mPos = PackNum::makePos(mIPack); return *this; } - + */ template template ContainerIndex::ContainerIndex(const std::shared_ptr& range) : @@ -145,7 +145,7 @@ namespace MultiArrayTools } template - const std::shared_ptr::RangeType>& ContainerIndex::range() const; + std::shared_ptr::RangeType> ContainerIndex::range() const { return std::dynamic_pointer_cast( IB::mRangePtr ); } diff --git a/src/container_range.h b/src/container_range.h index fdc933a..45e8d91 100644 --- a/src/container_range.h +++ b/src/container_range.h @@ -32,8 +32,8 @@ namespace MultiArrayTools public: ContainerIndex() = delete; - ContainerIndex(const ContainerIndex& in); - ContainerIndex& operator=(const ContainerIndex& in); + //ContainerIndex(const ContainerIndex& in); + //ContainerIndex& operator=(const ContainerIndex& in); template ContainerIndex(const std::shared_ptr& range); @@ -62,7 +62,7 @@ namespace MultiArrayTools ContainerIndex& operator()(); // -> sync; just to shorten the code - const std::shared_ptr& range() const; + std::shared_ptr range() const; }; diff --git a/src/multi_array.cc b/src/multi_array.cc index e5051a7..859f80d 100644 --- a/src/multi_array.cc +++ b/src/multi_array.cc @@ -544,7 +544,7 @@ namespace MultiArrayTools template FunctionalMultiArray::FunctionalMultiArray(const std::shared_ptr& range, const Function& func) : - MultiArrayBase(range), mFunc(func) { /*CHECK;*/ } + MultiArrayBase(range), mFunc(func) {} template const T& FunctionalMultiArray::operator[](const typename CRange::IndexType& i) const diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index bcd24f6..90dd08f 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -39,14 +39,13 @@ namespace MultiArrayTools mSecond(second), mArrayRef(ma), mIndex() { MultiRangeFactory mrf( index->range() ); - mIndex = mrf.create(); - CHECK; + std::shared_ptr > mr = + std::dynamic_pointer_cast >( mrf.create() ); + mIndex = std::make_shared( mr->begin() ); (*mIndex) = *index; - CHECK; for(*mIndex = 0; mIndex->pos() != mIndex->max(); ++(*mIndex)){ get() = mSecond.get(); } - CHECK; } template @@ -72,15 +71,13 @@ namespace MultiArrayTools OperationBase(), OperationTemplate >(this), mArrayRef(ma), mIndex( std::make_shared( mArrayRef.range() ) ) { - CHECK; mIndex(indices...); - CHECK; } template const T& ConstOperationRoot::get() const { - return mArrayRef[ *mIndex ]; + return mArrayRef[ (*mIndex)() ]; } /*********************** @@ -94,9 +91,7 @@ namespace MultiArrayTools MutableOperationBase(), OperationTemplate >(this), mArrayRef(ma), mIndex( std::make_shared( mArrayRef.range() ) ) { - CHECK; (*mIndex)(indices...); - CHECK; } template @@ -108,13 +103,13 @@ namespace MultiArrayTools template const T& OperationRoot::get() const { - return mArrayRef[ *mIndex ]; + return mArrayRef[ (*mIndex)() ]; } template T& OperationRoot::get() { - return mArrayRef[ *mIndex ]; + return mArrayRef[ (*mIndex)() ]; } /*********************** diff --git a/src/multi_range.cc b/src/multi_range.cc index 0181457..0d74682 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -13,7 +13,8 @@ namespace MultiArrayTools /****************** * MultiIndex * ******************/ - + + /* template MultiIndex::MultiIndex(const MultiIndex& in) : IndexInterface >(in) @@ -30,15 +31,12 @@ namespace MultiArrayTools IB::mPos = PackNum::makePos(mIPack); return *this; } - + */ template MultiIndex& MultiIndex::operator=(ContainerIndex& ci) { - CHECK; PackNum::copyInst(mIPack, ci); - CHECK; IB::mPos = PackNum::makePos(mIPack); - CHECK; return *this; } @@ -155,7 +153,7 @@ namespace MultiArrayTools } template - const std::shared_ptr::RangeType>& MultiIndex::range() const + std::shared_ptr::RangeType> MultiIndex::range() const { return std::dynamic_pointer_cast( IB::mRangePtr ); } diff --git a/src/multi_range.h b/src/multi_range.h index 6307b39..e2699d1 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -32,8 +32,8 @@ namespace MultiArrayTools MultiIndex() = delete; // NO DEFAULT HERE !!! // ( have to assign sub-indices (ptr!) correctly ) - MultiIndex(const MultiIndex& in); - MultiIndex& operator=(const MultiIndex& in); + //MultiIndex(const MultiIndex& in); + //MultiIndex& operator=(const MultiIndex& in); MultiIndex& operator=(ContainerIndex& ci); template @@ -65,7 +65,7 @@ namespace MultiArrayTools virtual size_t dim() const override; - const std::shared_ptr& range() const; + std::shared_ptr range() const; }; /************************* diff --git a/src/op_unit_test.cc b/src/op_unit_test.cc index 0c82dc6..51528b8 100644 --- a/src/op_unit_test.cc +++ b/src/op_unit_test.cc @@ -66,8 +66,12 @@ namespace { MultiArray res(crptr); auto i = std::dynamic_pointer_cast( srptr->index() ); - CHECK; res.operator()(i) = ma1.operator()(i) + ma2.operator()(i); + + EXPECT_EQ( fabs( res.at('a') - (2.917+8.870) ) < 0.0001, true); + EXPECT_EQ( fabs( res.at('l') - (9.436+4.790) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at('f') - (0.373+8.215) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at('g') - (7.192+5.063) ) < 0.0001, true ); } } // anonymous namspace diff --git a/src/single_range.h b/src/single_range.h index 29d0762..c008ffb 100644 --- a/src/single_range.h +++ b/src/single_range.h @@ -23,10 +23,10 @@ namespace MultiArrayTools typedef U MetaType; typedef SingleRange RangeType; - DEFAULT_MEMBERS_X(SingleIndex); + //DEFAULT_MEMBERS_X(SingleIndex); SingleIndex(const std::shared_ptr >& range); - + virtual SingleIndex& operator=(size_t pos) override; virtual SingleIndex& operator++() override; virtual SingleIndex& operator--() override;