diff --git a/src/include/multi_array_base.h b/src/include/multi_array_base.h index a8e3d46..c8c93f5 100644 --- a/src/include/multi_array_base.h +++ b/src/include/multi_array_base.h @@ -60,7 +60,7 @@ namespace MultiArrayTools protected: bool mInit = false; std::shared_ptr mRange; - + std::shared_ptr mProtoI; }; template @@ -116,6 +116,7 @@ namespace MultiArrayTools { ContainerRangeFactory crf(ranges...); mRange = std::dynamic_pointer_cast >( crf.create() ); + mProtoI = std::make_shared( mRange ); } template @@ -123,6 +124,7 @@ namespace MultiArrayTools { ContainerRangeFactory crf(space); mRange = std::dynamic_pointer_cast >( crf.create() ); + mProtoI = std::make_shared( mRange ); } template @@ -134,14 +136,17 @@ namespace MultiArrayTools template typename MultiArrayBase::IndexType MultiArrayBase::begin() const { - IndexType i = mRange->begin(); + IndexType i(*mProtoI); + i = 0; return i.setData(data()); } template typename MultiArrayBase::IndexType MultiArrayBase::end() const { - IndexType i = mRange->end(); + IndexType i(*mProtoI); + i = i.max(); + //i = mRange->size(); return i.setData(data()); } @@ -149,7 +154,8 @@ namespace MultiArrayTools typename MultiArrayBase::IndexType MultiArrayBase::beginIndex() const { - IndexType i = mRange->begin(); + IndexType i(*mProtoI); + i = 0; return i.setData(data()); } @@ -157,7 +163,9 @@ namespace MultiArrayTools typename MultiArrayBase::IndexType MultiArrayBase::endIndex() const { - IndexType i = mRange->end(); + IndexType i(*mProtoI); + i = i.max(); + //i = mRange->size(); return i.setData(data()); } diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index b0a2fc3..ea7ed45 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -95,13 +95,15 @@ namespace MultiArrayTools typedef T value_type; typedef OperationBase OB; typedef ContainerRange CRange; - typedef typename MultiRange::IndexType IndexType; + typedef ContainerIndex IndexType; + //typedef typename MultiRange::IndexType IndexType; OperationMaster(MutableMultiArrayBase& ma, const OpClass& second, - std::shared_ptr& index); + IndexType& index); OperationMaster(MutableMultiArrayBase& ma, const OpClass& second, - std::shared_ptr& index, + //std::shared_ptr& index, + IndexType& index, const IndexInfo* blockIndex); inline void set(size_t pos, T val) { mDataPtr[pos] = val; } @@ -110,12 +112,11 @@ namespace MultiArrayTools private: - std::shared_ptr mkIndex(std::shared_ptr& index); void performAssignment(std::intptr_t blockIndexNum); OpClass const& mSecond; MutableMultiArrayBase& mArrayRef; T* mDataPtr; - std::shared_ptr mIndex; + IndexType mIndex; IndexInfo mIInfo; }; @@ -130,7 +131,7 @@ namespace MultiArrayTools typedef OperationBase OB; typedef OperationTemplate > OT; typedef ContainerRange CRange; - typedef typename CRange::IndexType IndexType; + typedef ContainerIndex IndexType; static constexpr size_t SIZE = 1; @@ -147,13 +148,10 @@ namespace MultiArrayTools private: - std::shared_ptr - mkIndex(const MultiArrayBase& ma, - const std::shared_ptr&... indices); - MultiArrayBase const& mArrayRef; const T* mDataPtr; - std::shared_ptr mIndex; + //std::shared_ptr mIndex; + IndexType mIndex; IndexInfo mIInfo; }; @@ -166,7 +164,7 @@ namespace MultiArrayTools typedef OperationBase OB; typedef OperationTemplate > OT; typedef ContainerRange CRange; - typedef typename CRange::IndexType IndexType; + typedef ContainerIndex IndexType; static constexpr size_t SIZE = 1; @@ -186,13 +184,9 @@ namespace MultiArrayTools private: - std::shared_ptr - mkIndex(const MultiArrayBase& ma, - const std::shared_ptr&... indices); - MutableMultiArrayBase& mArrayRef; T* mDataPtr; - std::shared_ptr mIndex; + IndexType mIndex; IndexInfo mIInfo; }; @@ -387,9 +381,9 @@ namespace MultiArrayTools template OperationMaster:: OperationMaster(MutableMultiArrayBase& ma, const OpClass& second, - std::shared_ptr& index) : + IndexType& index) : mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()), - mIndex(mkIndex(index)), mIInfo(*mIndex) + mIndex(index), mIInfo(mIndex) { performAssignment(0); } @@ -397,32 +391,19 @@ namespace MultiArrayTools template OperationMaster:: OperationMaster(MutableMultiArrayBase& ma, const OpClass& second, - std::shared_ptr& index, + IndexType& index, const IndexInfo* blockIndex) : mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()), - mIndex(mkIndex(index)), mIInfo(*mIndex) + mIndex(index), mIInfo(mIndex) { performAssignment(0); } - - template - std::shared_ptr::IndexType> - OperationMaster:: - mkIndex(std::shared_ptr& index) - { - MultiRangeFactory mrf( index->range() ); - std::shared_ptr > mr = - std::dynamic_pointer_cast >( mrf.create() ); - auto i = std::make_shared( mr->begin() ); - (*i) = *index; - return i; - } template void OperationMaster::performAssignment(std::intptr_t blockIndexNum) { AssignmentExpr ae(*this, mSecond); // Expression to be executed within loop - const auto loop = mSecond.template loopifor(ae))>( mIndex->ifor(ae) ); + const auto loop = mSecond.template loop( mIndex.ifor(ae) ); // hidden Loops outside ! -> auto vectorizable loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions } @@ -443,18 +424,10 @@ namespace MultiArrayTools ConstOperationRoot(const MultiArrayBase& ma, const std::shared_ptr&... indices) : mArrayRef(ma), mDataPtr(mArrayRef.data()), - mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex) - {} - - template - std::shared_ptr::IndexType> - ConstOperationRoot:: - mkIndex(const MultiArrayBase& ma, - const std::shared_ptr&... indices) + //mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex) + mIndex( ma.begin() ), mIInfo(mIndex) { - auto i = std::make_shared( ma.range() ); - (*mIndex)(indices...); - return i; + mIndex(indices...); } template @@ -467,7 +440,7 @@ namespace MultiArrayTools template MExt ConstOperationRoot::rootSteps(std::intptr_t iPtrNum) const { - return MExt(getStepSize( mIndex->info(), iPtrNum )); + return MExt(getStepSize( mIndex.info(), iPtrNum )); //return MExt(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); } @@ -488,20 +461,11 @@ namespace MultiArrayTools OperationRoot(MutableMultiArrayBase& ma, const std::shared_ptr&... indices) : mArrayRef(ma), mDataPtr(mArrayRef.data()), - mIndex( mkIndex( ma, indices... ) ), mIInfo(*mIndex) - {} - - template - std::shared_ptr::IndexType> - OperationRoot:: - mkIndex(const MultiArrayBase& ma, - const std::shared_ptr&... indices) + mIndex( ma.begin() ), mIInfo(mIndex) { - auto i = std::make_shared( ma.range() ); - (*mIndex)(indices...); - return i; + mIndex(indices...); } - + template template OperationMaster OperationRoot::operator=(const OpClass& in) @@ -519,7 +483,7 @@ namespace MultiArrayTools template MExt OperationRoot::rootSteps(std::intptr_t iPtrNum) const { - return MExt(getStepSize( mIndex->info(), iPtrNum )); + return MExt(getStepSize( mIndex.info(), iPtrNum )); //return MExt(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); } diff --git a/src/include/ranges/container_range.h b/src/include/ranges/container_range.h index 3c91462..5d6bc39 100644 --- a/src/include/ranges/container_range.h +++ b/src/include/ranges/container_range.h @@ -33,7 +33,9 @@ namespace MultiArrayTools static size_t totalDim() { return mkTotalDim(); } private: - + + ContainerIndex() = default; + bool mNonTrivialBlocks = false; bool mExternControl = false; IndexPack mIPack; @@ -42,7 +44,8 @@ namespace MultiArrayTools public: - ContainerIndex() = delete; + ContainerIndex(const ContainerIndex& in) = default; + ContainerIndex& operator=(const ContainerIndex& in) = default; template ContainerIndex(const std::shared_ptr& range); @@ -50,7 +53,7 @@ namespace MultiArrayTools template ContainerIndex(const std::shared_ptr& range, const std::array& blockSizes); - + template auto get() const -> decltype( *std::get( mIPack ) )&; diff --git a/src/tests/ranges/index_unit_test.cc b/src/tests/ranges/index_unit_test.cc index 1f37092..41bac60 100644 --- a/src/tests/ranges/index_unit_test.cc +++ b/src/tests/ranges/index_unit_test.cc @@ -50,6 +50,7 @@ namespace { typedef ContainerRangeFactory CRF; typedef CRF::oType CRange; + typedef ContainerIndex CIndex; IndexTest() { @@ -182,9 +183,13 @@ namespace { EXPECT_EQ(cr2ptr->size(), 12u); auto mi = mstrptr->begin(); - auto ci1 = cr1ptr->begin(); - auto ci2 = cr2ptr->begin(); - + //auto ci1 = cr1ptr->begin(); + CIndex ci1(cr1ptr); + ci1 = 0; + //auto ci2 = cr2ptr->begin(); + CIndex ci2(cr2ptr); + ci2 = 0; + EXPECT_EQ(ci1.max(), 16u); EXPECT_EQ(ci2.max(), 12u);