diff --git a/src/include/functional_multi_array.h b/src/include/functional_multi_array.h index 68afbca..1f7202c 100644 --- a/src/include/functional_multi_array.h +++ b/src/include/functional_multi_array.h @@ -18,8 +18,9 @@ namespace MultiArrayTools std::vector vv(i->range()->size()); for(Index j = (*i); j.pos() != j.max(); ++j){ vv[j.pos()] = j.meta(); - } - return MultiArray( i->range(), std::move( vv ) ); + VCHECK(j.meta()); + } + return MultiArray( i->range(), vv ); } }; @@ -33,14 +34,65 @@ namespace MultiArrayTools return ConstSlice( i->range(), i->metaPtr() ); } }; - + template auto mkMAObject(const std::shared_ptr& i) - -> decltype(ToMAObject::mk(i)) + -> std::shared_ptr::mk(i))> { - return ToMAObject::mk(i); + return std::make_shared::mk(i))> + (ToMAObject::mk(i)); } + /* + template + struct ToOpObject + { + template + static auto mk(const std::shared_ptr& ind) + -> MetaOperationRoot + { + typedef typename Index::RangeType RangeType; + MultiRangeFactory mrf(ind->range()); + auto mr = std::dynamic_pointer_cast( mrf.create() ); + typedef typename MultiRange::IndexType::MetaType value_type; + ContainerIndex ci(mr,0); + return MetaOperationRoot(ci); + } + }; + + template <> + struct ToOpObject + { + template + static auto mk(const std::shared_ptr& ind) + -> ConstOperationRoot + { + return ConstOperationRoot( mkMAObject(ind), ind); + } + }; + */ + template + struct ToOpObject + { + template + static auto mk(const std::shared_ptr& ind) + -> ConstOperationRoot + { + return ConstOperationRoot( mkMAObject(ind), ind); + } + }; + + + template + auto mkOpObject(const std::shared_ptr& i) + -> decltype(ToOpObject::mk(i)) + { + return ToOpObject::mk(i); + } template class FunctionalMultiArray : public MultiArrayBase @@ -78,8 +130,9 @@ namespace MultiArrayTools // EVALUTAION CLASS ??!!!! auto exec(const std::shared_ptr&... inds) const - -> decltype( mkOperation( mFunc, ConstOperationRoot( mkMAObject( inds ), inds) ... ) ); - + // -> decltype( mkOperation( mFunc, ConstOperationRoot( mkMAObject( inds ), inds) ... ) ); + -> decltype( mkOperation( mFunc, mkOpObject(inds) ... ) ); + virtual ConstOperationRoot operator()(const std::shared_ptr&... inds) const override; @@ -184,7 +237,7 @@ namespace MultiArrayTools return ConstOperationRoot( *mMaPtr, inds... ); } - + /* template auto FunctionalMultiArray:: exec(const std::shared_ptr&... inds) const @@ -192,8 +245,16 @@ namespace MultiArrayTools { return mkOperation( mFunc, ConstOperationRoot( mkMAObject( inds ), inds ) ... ); } + */ + + template + auto FunctionalMultiArray:: + exec(const std::shared_ptr&... inds) const + -> decltype( mkOperation( mFunc, mkOpObject(inds) ... ) ) + { + return mkOperation( mFunc, mkOpObject(inds) ... ); + } - } // namespace MultiArrayTools #endif diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index d7fdfd6..fac81ce 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -141,6 +141,9 @@ namespace MultiArrayTools ConstOperationRoot(const MultiArrayBase& ma, const std::shared_ptr&... indices); + ConstOperationRoot(std::shared_ptr > maptr, + const std::shared_ptr&... indices); + ConstOperationRoot(const T* data, const IndexType& ind); template @@ -156,8 +159,40 @@ namespace MultiArrayTools //MultiArrayBase const& mArrayRef; const T* mDataPtr; IndexType mIndex; + std::shared_ptr > mMaPtr; }; - + + template + class MetaOperationRoot : public OperationTemplate, + MetaOperationRoot > + { + public: + + typedef ContainerIndex, + typename Ranges::IndexType...> IndexType; + typedef typename IndexType::MetaType value_type; + typedef OperationBase > OT; + typedef ContainerRange CRange; + + static constexpr size_t SIZE = 1; + + MetaOperationRoot(const IndexType& ind); + + template + inline value_type get(ET pos) const; + + MExt rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype + + template + Expr loop(Expr exp) const; + + private: + + //MultiArrayBase const& mArrayRef; + //const T* mDataPtr; + IndexType mIndex; + }; + template class OperationRoot : public OperationTemplate > { @@ -466,6 +501,18 @@ namespace MultiArrayTools const std::shared_ptr&... indices) : mDataPtr(ma.data()), mIndex( ma.begin() ) + { + //VCHECK(ma.data()); + mIndex(indices...); + } + + template + ConstOperationRoot:: + ConstOperationRoot(std::shared_ptr > maptr, + const std::shared_ptr&... indices) : + mDataPtr(maptr->data()), + mIndex(maptr->begin()), + mMaPtr(maptr) { mIndex(indices...); } @@ -480,6 +527,9 @@ namespace MultiArrayTools template inline T ConstOperationRoot::get(ET pos) const { + //VCHECK(pos.val()); + //VCHECK(mDataPtr); + //VCHECK(mDataPtr[pos.val()]) return mDataPtr[pos.val()]; } @@ -497,7 +547,42 @@ namespace MultiArrayTools { return exp; } - + + /**************************** + * MetaOperationRoot * + ****************************/ + + template + MetaOperationRoot:: + MetaOperationRoot(const IndexType& ind) : + mIndex( ind ) { } + + template + template + inline typename MetaOperationRoot::value_type + MetaOperationRoot::get(ET pos) const + { + //VCHECK(pos.val()); + //VCHECK(mDataPtr); + //VCHECK(mDataPtr[pos.val()]) + return mIndex.meta(pos.val()); + } + + template + MExt MetaOperationRoot::rootSteps(std::intptr_t iPtrNum) const + { + return MExt(getStepSize( mIndex, iPtrNum )); + //return MExt(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); + } + + + template + template + Expr MetaOperationRoot::loop(Expr exp) const + { + return exp; + } + /*********************** * OperationRoot * ***********************/ diff --git a/src/include/ranges/range_types/classic_range.h b/src/include/ranges/range_types/classic_range.h index 9b8cb55..ba07956 100644 --- a/src/include/ranges/range_types/classic_range.h +++ b/src/include/ranges/range_types/classic_range.h @@ -35,20 +35,20 @@ namespace MultiArrayTools typedef SingleRange RangeType; typedef size_t MetaType; - virtual size_t size() const override; - virtual size_t dim() const override; + virtual size_t size() const final; + virtual size_t dim() const final; - virtual SpaceType spaceType() const override; + virtual SpaceType spaceType() const final; - virtual std::string stringMeta(size_t pos) const override; - virtual std::vector data() const override; + virtual std::string stringMeta(size_t pos) const final; + virtual std::vector data() const final; size_t get(size_t pos) const; size_t getMeta(size_t metaPos) const; - virtual IndexType begin() const override; - virtual IndexType end() const override; - //virtual std::shared_ptr index() const override; + virtual IndexType begin() const final; + virtual IndexType end() const final; + //virtual std::shared_ptr index() const final; friend SingleRangeFactory; diff --git a/src/include/ranges/range_types/null_range.h b/src/include/ranges/range_types/null_range.h index d0a83b9..a4e5882 100644 --- a/src/include/ranges/range_types/null_range.h +++ b/src/include/ranges/range_types/null_range.h @@ -42,20 +42,20 @@ namespace MultiArrayTools typedef SingleRange RangeType; typedef size_t MetaType; - virtual size_t size() const override; - virtual size_t dim() const override; + virtual size_t size() const final; + virtual size_t dim() const final; - virtual std::string stringMeta(size_t pos) const override; - virtual std::vector data() const override; + virtual std::string stringMeta(size_t pos) const final; + virtual std::vector data() const final; - virtual SpaceType spaceType() const override; + virtual SpaceType spaceType() const final; size_t get(size_t pos) const; size_t getMeta(size_t metapos) const; - virtual IndexType begin() const override; - virtual IndexType end() const override; - //virtual std::shared_ptr index() const override; + virtual IndexType begin() const final; + virtual IndexType end() const final; + //virtual std::shared_ptr index() const final; friend SingleRangeFactory; diff --git a/src/include/ranges/range_types/space_range.h b/src/include/ranges/range_types/space_range.h index 8758a0d..5d4878d 100644 --- a/src/include/ranges/range_types/space_range.h +++ b/src/include/ranges/range_types/space_range.h @@ -34,19 +34,19 @@ namespace MultiArrayTools typedef SingleRange RangeType; typedef int MetaType; - virtual size_t size() const override; - virtual size_t dim() const override; + virtual size_t size() const final; + virtual size_t dim() const final; - virtual std::string stringMeta(size_t pos) const override; - virtual std::vector data() const override; + virtual std::string stringMeta(size_t pos) const final; + virtual std::vector data() const final; - virtual SpaceType spaceType() const override; + virtual SpaceType spaceType() const final; int get(size_t pos) const; size_t getMeta(int metaPos) const; - virtual IndexType begin() const override; - virtual IndexType end() const override; + virtual IndexType begin() const final; + virtual IndexType end() const final; friend SingleRangeFactory; diff --git a/src/include/ranges/range_types/spin_range.h b/src/include/ranges/range_types/spin_range.h index 80031cd..b1f3e8c 100644 --- a/src/include/ranges/range_types/spin_range.h +++ b/src/include/ranges/range_types/spin_range.h @@ -35,20 +35,20 @@ namespace MultiArrayTools typedef SingleRange RangeType; typedef size_t MetaType; - virtual size_t size() const override; - virtual size_t dim() const override; + virtual size_t size() const final; + virtual size_t dim() const final; - virtual std::string stringMeta(size_t pos) const override; - virtual std::vector data() const override; + virtual std::string stringMeta(size_t pos) const final; + virtual std::vector data() const final; - virtual SpaceType spaceType() const override; + virtual SpaceType spaceType() const final; size_t get(size_t pos) const; size_t getMeta(size_t metaPos) const; - virtual IndexType begin() const override; - virtual IndexType end() const override; - //virtual std::shared_ptr index() const override; + virtual IndexType begin() const final; + virtual IndexType end() const final; + //virtual std::shared_ptr index() const final; friend SingleRangeFactory; diff --git a/src/include/ranges/single_range.h b/src/include/ranges/single_range.h index df3dce6..9dca047 100644 --- a/src/include/ranges/single_range.h +++ b/src/include/ranges/single_range.h @@ -80,6 +80,7 @@ namespace MultiArrayTools -> For,Expr,ForType::HIDDEN>; private: + std::shared_ptr mExplicitRangePtr; const U* mMetaPtr; }; @@ -106,19 +107,19 @@ namespace MultiArrayTools typedef U MetaType; //typedef typename RangeInterface >::IndexType IndexType; - virtual size_t size() const override; - virtual size_t dim() const override; + virtual size_t size() const final; + virtual size_t dim() const final; - virtual SpaceType spaceType() const override; + virtual SpaceType spaceType() const final; - virtual std::string stringMeta(size_t pos) const override; - virtual std::vector data() const override; + virtual std::string stringMeta(size_t pos) const final; + virtual std::vector data() const final; const U& get(size_t pos) const; size_t getMeta(const U& metaPos) const; - virtual IndexType begin() const override; - virtual IndexType end() const override; + virtual IndexType begin() const final; + virtual IndexType end() const final; friend SingleRangeFactory; @@ -184,6 +185,7 @@ namespace MultiArrayTools template SingleIndex::SingleIndex(const std::shared_ptr >& range) : IndexInterface,U>(range, 0), + mExplicitRangePtr(std::dynamic_pointer_cast(IB::mRangePtr)), mMetaPtr(MetaPtrHandle::RangeType::HASMETACONT>::set ( dynamic_cast(IB::mRangePtr.get() ) ) ) {} @@ -238,8 +240,7 @@ namespace MultiArrayTools U SingleIndex::meta() const { return MetaPtrHandle::RangeType::HASMETACONT>::getMeta - ( mMetaPtr, IB::mPos, - std::dynamic_pointer_cast const>( IB::mRangePtr ) ); + ( mMetaPtr, IB::mPos, mExplicitRangePtr ); } template diff --git a/src/tests/op_unit_test.cc b/src/tests/op_unit_test.cc index ea69ee3..7bb1e43 100644 --- a/src/tests/op_unit_test.cc +++ b/src/tests/op_unit_test.cc @@ -531,6 +531,23 @@ namespace { EXPECT_EQ( xround( res.at(mkt(mkt('3','b'),'B')) ), xround(2.911 + 4.790 - 2.210) ); } + TEST_F(OpTest_MDim, ExecOpAnon) + { + MultiArray ma1(mr1ptr, v3); + MultiArray maa + = *std::dynamic_pointer_cast>( ma1.anonymous() ); + MultiArray maa2( maa.template getRangePtr<0>() ); + + auto ar = maa.template getRangePtr<0>(); + auto i1 = MAT::getIndex( ar ); + + maa2(i1) = maa(i1) * maa(i1); + EXPECT_EQ( xround( maa2.at(0) ), xround( v3[0]*v3[0] ) ); + for((*i1) = 0; i1->pos() != i1->max(); ++(*i1) ){ + EXPECT_EQ( xround( maa2.at(i1->meta()) ), xround( maa.at(i1->meta()) * maa.at(i1->meta()) ) ); + } + } + template struct Monopole {