From f339778a59a3dcf786c96ea13c4041ee7a0d9027 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 12 Feb 2019 20:26:38 +0100 Subject: [PATCH] generalize single range (static size parameter, -> -1 if non-static size) --- CMakeLists.txt | 2 +- src/include/ranges/anonymous_range.h | 26 +- .../ranges/range_types/classic_range.h | 32 +- src/include/ranges/range_types/null_range.h | 34 +-- src/include/ranges/range_types/space_range.h | 32 +- src/include/ranges/range_types/spin_range.h | 32 +- src/include/ranges/rbase_def.h | 12 +- src/include/ranges/single_range.h | 273 ++++++++++-------- src/lib/ranges/anonymous_range.cc | 2 +- src/lib/ranges/range_types/classic_range.cc | 36 +-- src/lib/ranges/range_types/null_range.cc | 42 +-- src/lib/ranges/range_types/space_range.cc | 36 +-- src/lib/ranges/range_types/spin_range.cc | 38 +-- src/tests/op_perf_test.cc | 18 +- 14 files changed, 320 insertions(+), 295 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba65885..a66ce5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8) project(multi_array) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -O3 -g -march=native -fopenmp") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -O3 -g -march=native -fopenmp -funroll-loops -ftree-vectorize") enable_testing() diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index 4cfb980..0099258 100644 --- a/src/include/ranges/anonymous_range.h +++ b/src/include/ranges/anonymous_range.h @@ -14,12 +14,12 @@ namespace MultiArrayTools { - typedef SingleIndex AnonymousIndex; + typedef GenSingleIndex AnonymousIndex; //template //using SIZET = size_t; - typedef SingleRange AnonymousRange; + typedef GenSingleRange AnonymousRange; // NOT THREAD SAVE!! class AnonymousRangeFactory : public RangeFactoryBase @@ -53,7 +53,7 @@ namespace MultiArrayTools }; template <> - class SingleRange : public RangeInterface + class GenSingleRange : public RangeInterface { public: @@ -64,7 +64,7 @@ namespace MultiArrayTools typedef RangeBase RB; typedef typename RangeInterface::IndexType IndexType; - typedef SingleRange RangeType; + typedef GenSingleRange RangeType; typedef size_t MetaType; virtual size_t size() const final; @@ -105,16 +105,16 @@ namespace MultiArrayTools protected: - SingleRange() = default; - SingleRange(const AnonymousRange& in) = default; + GenSingleRange() = default; + GenSingleRange(const AnonymousRange& in) = default; template - SingleRange(const std::tuple...>& origs); + GenSingleRange(const std::tuple...>& origs); template - SingleRange(std::shared_ptr... origs); + GenSingleRange(std::shared_ptr... origs); - SingleRange(const std::vector>& origs); + GenSingleRange(const std::vector>& origs); size_t mSize = 1; bool mEmpty = true; @@ -203,7 +203,7 @@ namespace MultiArrayTools ***********************/ template - SingleRange::SingleRange(const std::tuple...>& origs) : + GenSingleRange::GenSingleRange(const std::tuple...>& origs) : RangeInterface() { RPackNum::RangesToVec( origs, mOrig ); @@ -214,7 +214,7 @@ namespace MultiArrayTools } template - SingleRange::SingleRange(std::shared_ptr... origs) : + GenSingleRange::GenSingleRange(std::shared_ptr... origs) : RangeInterface() { auto rst = std::make_tuple(origs...); @@ -226,13 +226,13 @@ namespace MultiArrayTools } template - std::shared_ptr SingleRange::fullsub(size_t num) const + std::shared_ptr GenSingleRange::fullsub(size_t num) const { return std::dynamic_pointer_cast( mOrig.at(num) ); } template - std::shared_ptr > SingleRange::scast(SIZET... sizes) const + std::shared_ptr > GenSingleRange::scast(SIZET... sizes) const { std::tuple...> rtp; RPackNum::resolveRangeType(mOrig, rtp, 0, sizes...); diff --git a/src/include/ranges/range_types/classic_range.h b/src/include/ranges/range_types/classic_range.h index 3a65fea..f9b4ed6 100644 --- a/src/include/ranges/range_types/classic_range.h +++ b/src/include/ranges/range_types/classic_range.h @@ -12,29 +12,29 @@ namespace MultiArrayTools { - typedef SingleIndex ClassicIndex; + typedef GenSingleIndex ClassicIndex; template <> - class SingleRangeFactory : public RangeFactoryBase + class GenSingleRangeFactory : public RangeFactoryBase { public: - typedef SingleRange oType; + typedef GenSingleRange oType; - SingleRangeFactory(size_t size = 0); + GenSingleRangeFactory(size_t size = 0); std::shared_ptr create(); }; template <> - class SingleRange : public RangeInterface + class GenSingleRange : public RangeInterface { public: typedef RangeBase RB; - typedef typename RangeInterface >::IndexType IndexType; - typedef SingleRange RangeType; + typedef typename RangeInterface >::IndexType IndexType; + typedef GenSingleRange RangeType; typedef size_t MetaType; - typedef SingleRangeFactory FType; + typedef GenSingleRangeFactory FType; virtual size_t size() const final; virtual size_t dim() const final; @@ -52,28 +52,28 @@ namespace MultiArrayTools virtual IndexType end() const final; //virtual std::shared_ptr index() const final; - friend SingleRangeFactory; + friend GenSingleRangeFactory; static constexpr bool defaultable = true; static constexpr size_t ISSTATIC = 0; static constexpr size_t SIZE = -1; static constexpr bool HASMETACONT = false; - static SingleRangeFactory factory(size_t size = 0) - { return SingleRangeFactory(size); } + static GenSingleRangeFactory factory(size_t size = 0) + { return GenSingleRangeFactory(size); } protected: size_t mSize = 0; - SingleRange() = default; - SingleRange(const SingleRange& in) = delete; + GenSingleRange() = default; + GenSingleRange(const GenSingleRange& in) = delete; - SingleRange(size_t size); + GenSingleRange(size_t size); }; - typedef SingleRange ClassicRange; - typedef SingleRangeFactory ClassicRF; + typedef GenSingleRange ClassicRange; + typedef GenSingleRangeFactory ClassicRF; } diff --git a/src/include/ranges/range_types/null_range.h b/src/include/ranges/range_types/null_range.h index 968c0c0..994bb29 100644 --- a/src/include/ranges/range_types/null_range.h +++ b/src/include/ranges/range_types/null_range.h @@ -12,19 +12,19 @@ include_range_type(NUL,-2) namespace MultiArrayTools { - typedef SingleIndex NullIndex; + typedef GenSingleIndex NullIndex; - std::shared_ptr > nullr(); + std::shared_ptr > nullr(); std::shared_ptr nulli(); template <> - class SingleRangeFactory : public RangeFactoryBase + class GenSingleRangeFactory : public RangeFactoryBase { public: - typedef SingleRange oType; + typedef GenSingleRange oType; - SingleRangeFactory(); + GenSingleRangeFactory(); std::shared_ptr create(); friend std::shared_ptr nullr(); @@ -34,14 +34,14 @@ namespace MultiArrayTools }; template <> - class SingleRange : public RangeInterface + class GenSingleRange : public RangeInterface { public: typedef RangeBase RB; - typedef typename RangeInterface >::IndexType IndexType; - typedef SingleRange RangeType; + typedef typename RangeInterface >::IndexType IndexType; + typedef GenSingleRange RangeType; typedef size_t MetaType; - typedef SingleRangeFactory FType; + typedef GenSingleRangeFactory FType; virtual size_t size() const final; virtual size_t dim() const final; @@ -59,7 +59,7 @@ namespace MultiArrayTools virtual IndexType end() const final; //virtual std::shared_ptr index() const final; - friend SingleRangeFactory; + friend GenSingleRangeFactory; static constexpr bool defaultable = true; @@ -67,19 +67,19 @@ namespace MultiArrayTools static constexpr size_t SIZE = 1; static constexpr bool HASMETACONT = false; - static SingleRangeFactory factory() - { return SingleRangeFactory(); } + static GenSingleRangeFactory factory() + { return GenSingleRangeFactory(); } protected: - SingleRange() = default; - SingleRange(const SingleRange& in) = delete; + GenSingleRange() = default; + GenSingleRange(const GenSingleRange& in) = delete; - //SingleRange(size_t spinNum); + //GenSingleRange(size_t spinNum); }; - typedef SingleRange NullRange; - typedef SingleRangeFactory NullRF; + typedef GenSingleRange NullRange; + typedef GenSingleRangeFactory NullRF; std::shared_ptr mkNUL(const char* dp, size_t size); diff --git a/src/include/ranges/range_types/space_range.h b/src/include/ranges/range_types/space_range.h index 238afb5..46d660a 100644 --- a/src/include/ranges/range_types/space_range.h +++ b/src/include/ranges/range_types/space_range.h @@ -11,29 +11,29 @@ include_range_type(PSPACE,3) // Periodic 1dim space namespace MultiArrayTools { // Periodic 1dim space - typedef SingleIndex XSpaceIndex; + typedef GenSingleIndex XSpaceIndex; template <> - class SingleRangeFactory : public RangeFactoryBase + class GenSingleRangeFactory : public RangeFactoryBase { public: - typedef SingleRange oType; + typedef GenSingleRange oType; - SingleRangeFactory(size_t size = 0); + GenSingleRangeFactory(size_t size = 0); std::shared_ptr create(); }; template <> - class SingleRange : public RangeInterface + class GenSingleRange : public RangeInterface { public: typedef RangeBase RB; - typedef typename RangeInterface >::IndexType IndexType; - typedef SingleRange RangeType; + typedef typename RangeInterface >::IndexType IndexType; + typedef GenSingleRange RangeType; typedef int MetaType; - typedef SingleRangeFactory FType; + typedef GenSingleRangeFactory FType; virtual size_t size() const final; virtual size_t dim() const final; @@ -50,28 +50,28 @@ namespace MultiArrayTools virtual IndexType begin() const final; virtual IndexType end() const final; - friend SingleRangeFactory; + friend GenSingleRangeFactory; static constexpr bool defaultable = true; static constexpr size_t ISSTATIC = 0; static constexpr size_t SIZE = -1; static constexpr bool HASMETACONT = false; - static SingleRangeFactory factory(size_t size = 0) - { return SingleRangeFactory(size); } + static GenSingleRangeFactory factory(size_t size = 0) + { return GenSingleRangeFactory(size); } protected: size_t mSize = 0; - SingleRange() = default; - SingleRange(const SingleRange& in) = delete; + GenSingleRange() = default; + GenSingleRange(const GenSingleRange& in) = delete; - SingleRange(size_t size); + GenSingleRange(size_t size); }; - typedef SingleRange PSpaceRange; - typedef SingleRangeFactory PSpaceRF; + typedef GenSingleRange PSpaceRange; + typedef GenSingleRangeFactory PSpaceRF; std::shared_ptr mkPSPACE(const char* dp, size_t size); diff --git a/src/include/ranges/range_types/spin_range.h b/src/include/ranges/range_types/spin_range.h index 32c8dff..97992b5 100644 --- a/src/include/ranges/range_types/spin_range.h +++ b/src/include/ranges/range_types/spin_range.h @@ -12,29 +12,29 @@ include_range_type(SPIN,2) namespace MultiArrayTools { - typedef SingleIndex SpinIndex; + typedef GenSingleIndex SpinIndex; template <> - class SingleRangeFactory : public RangeFactoryBase + class GenSingleRangeFactory : public RangeFactoryBase { public: - typedef SingleRange oType; + typedef GenSingleRange oType; - SingleRangeFactory(); + GenSingleRangeFactory(); std::shared_ptr create(); }; template <> - class SingleRange : public RangeInterface + class GenSingleRange : public RangeInterface { public: typedef RangeBase RB; - typedef typename RangeInterface >::IndexType IndexType; - typedef SingleRange RangeType; + typedef typename RangeInterface >::IndexType IndexType; + typedef GenSingleRange RangeType; typedef size_t MetaType; - typedef SingleRangeFactory FType; + typedef GenSingleRangeFactory FType; virtual size_t size() const final; virtual size_t dim() const final; @@ -52,7 +52,7 @@ namespace MultiArrayTools virtual IndexType end() const final; //virtual std::shared_ptr index() const final; - friend SingleRangeFactory; + friend GenSingleRangeFactory; static constexpr bool defaultable = true; static constexpr size_t mSpinNum = 4; @@ -61,19 +61,19 @@ namespace MultiArrayTools static constexpr size_t SIZE = mSpinNum; static constexpr bool HASMETACONT = false; - static SingleRangeFactory factory() - { return SingleRangeFactory(); } + static GenSingleRangeFactory factory() + { return GenSingleRangeFactory(); } protected: - SingleRange() = default; - SingleRange(const SingleRange& in) = delete; + GenSingleRange() = default; + GenSingleRange(const GenSingleRange& in) = delete; - //SingleRange(size_t spinNum); + //GenSingleRange(size_t spinNum); }; - typedef SingleRange SpinRange; - typedef SingleRangeFactory SpinRF; + typedef GenSingleRange SpinRange; + typedef GenSingleRangeFactory SpinRF; std::shared_ptr mkSPIN(const char* dp, size_t size); } diff --git a/src/include/ranges/rbase_def.h b/src/include/ranges/rbase_def.h index 3cffe08..64ccc45 100644 --- a/src/include/ranges/rbase_def.h +++ b/src/include/ranges/rbase_def.h @@ -44,16 +44,16 @@ namespace MultiArrayTools class IndexInterface; // single_range.h - template - class SingleRange; + template + class GenSingleRange; // single_range.h - template - class SingleRangeFactory; + template + class GenSingleRangeFactory; // single_range.h - template - class SingleIndex; + template + class GenSingleIndex; // subrange.h template diff --git a/src/include/ranges/single_range.h b/src/include/ranges/single_range.h index 1affcaf..57d76f7 100644 --- a/src/include/ranges/single_range.h +++ b/src/include/ranges/single_range.h @@ -28,19 +28,19 @@ namespace MultiArrayTools } - template - class SingleIndex : public IndexInterface,U> + template + class GenSingleIndex : public IndexInterface,U> { public: - typedef IndexInterface,U> IB; + typedef IndexInterface,U> IB; typedef U MetaType; - typedef SingleRange RangeType; - typedef SingleIndex IType; + typedef GenSingleRange RangeType; + typedef GenSingleIndex IType; - //DEFAULT_MEMBERS_X(SingleIndex); + //DEFAULT_MEMBERS_X(GenSingleIndex); - SingleIndex(const std::shared_ptr >& range); + GenSingleIndex(const std::shared_ptr >& range); static constexpr IndexType sType() { return IndexType::SINGLE; } static constexpr size_t totalDim() { return 1; } @@ -53,9 +53,9 @@ namespace MultiArrayTools IndexType type() const; - SingleIndex& operator=(size_t pos); - SingleIndex& operator++(); - SingleIndex& operator--(); + GenSingleIndex& operator=(size_t pos); + GenSingleIndex& operator++(); + GenSingleIndex& operator--(); int pp(std::intptr_t idxPtrNum); int mm(std::intptr_t idxPtrNum); @@ -63,7 +63,7 @@ namespace MultiArrayTools std::string stringMeta() const; U meta() const; const U* metaPtr() const; - SingleIndex& at(const U& metaPos); + GenSingleIndex& at(const U& metaPos); size_t posAt(const U& metaPos) const; bool isMeta(const U& metaPos) const; @@ -84,30 +84,30 @@ namespace MultiArrayTools template auto ifor(size_t step, Expr ex) const - -> For,Expr>; + -> For,Expr>; template auto iforh(size_t step, Expr ex) const - -> For,Expr,ForType::HIDDEN>; + -> For,Expr,ForType::HIDDEN>; template auto pifor(size_t step, Expr ex) const - -> PFor,Expr>; + -> PFor,Expr>; private: std::shared_ptr mExplicitRangePtr; const U* mMetaPtr; }; - template - class SingleRangeFactory : public RangeFactoryBase + template + class GenSingleRangeFactory : public RangeFactoryBase { public: - typedef SingleRange oType; + typedef GenSingleRange oType; - SingleRangeFactory() = delete; - SingleRangeFactory(const std::vector& space); + GenSingleRangeFactory() = delete; + GenSingleRangeFactory(const std::vector& space); std::shared_ptr create(); }; @@ -186,17 +186,31 @@ namespace MultiArrayTools } }; - - template - class SingleRange : public RangeInterface > + + template + struct CheckStatic + { + static constexpr size_t ISSTATIC = true; + static constexpr size_t SIZE = S; + }; + + template <> + struct CheckStatic<-1> + { + static constexpr size_t ISSTATIC = false; + static constexpr size_t SIZE = -1; + }; + + template + class GenSingleRange : public RangeInterface > { public: typedef RangeBase RB; - typedef SingleIndex IndexType; - typedef SingleRange RangeType; + typedef GenSingleIndex IndexType; + typedef GenSingleRange RangeType; typedef U MetaType; - typedef SingleRangeFactory FType; - //typedef typename RangeInterface >::IndexType IndexType; + typedef GenSingleRangeFactory FType; + //typedef typename RangeInterface >::IndexType IndexType; virtual size_t size() const final; virtual size_t dim() const final; @@ -215,25 +229,34 @@ namespace MultiArrayTools virtual IndexType begin() const final; virtual IndexType end() const final; - friend SingleRangeFactory; + friend GenSingleRangeFactory; static constexpr bool defaultable = false; - static constexpr size_t ISSTATIC = 0; - static constexpr size_t SIZE = -1; + static constexpr size_t ISSTATIC = CheckStatic::ISSTATIC; + static constexpr size_t SIZE = CheckStatic::SIZE; static constexpr bool HASMETACONT = true; protected: - SingleRange() = delete; - SingleRange(const SingleRange& in) = delete; + GenSingleRange() = delete; + GenSingleRange(const GenSingleRange& in) = delete; - SingleRange(const std::vector& space); + GenSingleRange(const std::vector& space); std::vector mSpace; //std::map mMSpace; MetaMap mMSpace; }; + template + using SingleRange = GenSingleRange; + + template + using SingleIndex = GenSingleIndex; + + template + using SingleRangeFactory = GenSingleRangeFactory; + } /* ========================= * @@ -243,7 +266,7 @@ namespace MultiArrayTools namespace MultiArrayTools { /****************** - * SingleIndex * + * GenSingleIndex * ******************/ template @@ -278,134 +301,134 @@ namespace MultiArrayTools } }; - template - SingleIndex::SingleIndex(const std::shared_ptr >& range) : - IndexInterface,U>(range, 0), + template + GenSingleIndex::GenSingleIndex(const std::shared_ptr >& range) : + IndexInterface,U>(range, 0), mExplicitRangePtr(std::dynamic_pointer_cast(IB::mRangePtr)), - mMetaPtr(MetaPtrHandle::RangeType::HASMETACONT>::set + mMetaPtr(MetaPtrHandle::RangeType::HASMETACONT>::set ( dynamic_cast(IB::mRangePtr.get() ) ) ) {} - template - IndexType SingleIndex::type() const + template + IndexType GenSingleIndex::type() const { return IndexType::SINGLE; } - template - SingleIndex& SingleIndex::operator=(size_t pos) + template + GenSingleIndex& GenSingleIndex::operator=(size_t pos) { IB::mPos = pos; return *this; } - template - SingleIndex& SingleIndex::operator++() + template + GenSingleIndex& GenSingleIndex::operator++() { ++IB::mPos; return *this; } - template - SingleIndex& SingleIndex::operator--() + template + GenSingleIndex& GenSingleIndex::operator--() { --IB::mPos; return *this; } - template - int SingleIndex::pp(std::intptr_t idxPtrNum) + template + int GenSingleIndex::pp(std::intptr_t idxPtrNum) { ++(*this); return 1; } - template - int SingleIndex::mm(std::intptr_t idxPtrNum) + template + int GenSingleIndex::mm(std::intptr_t idxPtrNum) { --(*this); return 1; } - template - std::string SingleIndex::stringMeta() const + template + std::string GenSingleIndex::stringMeta() const { - return std::dynamic_pointer_cast const>( IB::mRangePtr )->stringMeta(IB::mPos); + return std::dynamic_pointer_cast const>( IB::mRangePtr )->stringMeta(IB::mPos); } - template - U SingleIndex::meta() const + template + U GenSingleIndex::meta() const { - return MetaPtrHandle::RangeType::HASMETACONT>::getMeta + return MetaPtrHandle::RangeType::HASMETACONT>::getMeta ( mMetaPtr, IB::mPos, mExplicitRangePtr ); } - template - const U* SingleIndex::metaPtr() const + template + const U* GenSingleIndex::metaPtr() const { return mMetaPtr; } - template - bool SingleIndex::isMeta(const U& metaPos) const + template + bool GenSingleIndex::isMeta(const U& metaPos) const { return mExplicitRangePtr->isMeta(metaPos); } - template - SingleIndex& SingleIndex::at(const U& metaPos) + template + GenSingleIndex& GenSingleIndex::at(const U& metaPos) { - (*this) = std::dynamic_pointer_cast const>( IB::mRangePtr )->getMeta( metaPos ); + (*this) = std::dynamic_pointer_cast const>( IB::mRangePtr )->getMeta( metaPos ); return *this; } - template - size_t SingleIndex::posAt(const U& metaPos) const + template + size_t GenSingleIndex::posAt(const U& metaPos) const { - return std::dynamic_pointer_cast const>( IB::mRangePtr )->getMeta( metaPos ); + return std::dynamic_pointer_cast const>( IB::mRangePtr )->getMeta( metaPos ); } - template - size_t SingleIndex::dim() // = 1 + template + size_t GenSingleIndex::dim() // = 1 { return 1; } - template - bool SingleIndex::last() + template + bool GenSingleIndex::last() { return IB::mPos == IB::mMax - 1; } - template - bool SingleIndex::first() + template + bool GenSingleIndex::first() { return IB::mPos == 0; } - template - std::shared_ptr::RangeType> SingleIndex::range() + template + std::shared_ptr::RangeType> GenSingleIndex::range() { return mExplicitRangePtr; } - template + template template - void SingleIndex::getPtr() {} + void GenSingleIndex::getPtr() {} - template - size_t SingleIndex::getStepSize(size_t n) + template + size_t GenSingleIndex::getStepSize(size_t n) { return 1; } - template - std::string SingleIndex::id() const + template + std::string GenSingleIndex::id() const { return std::string("sin") + std::to_string(IB::mId); } - template - void SingleIndex::print(size_t offset) + template + void GenSingleIndex::print(size_t offset) { if(offset == 0){ std::cout << " === " << std::endl; @@ -415,31 +438,31 @@ namespace MultiArrayTools << "](" << IB::mRangePtr << "): " << meta() << std::endl; } - template + template template - auto SingleIndex::ifor(size_t step, Expr ex) const - -> For,Expr> + auto GenSingleIndex::ifor(size_t step, Expr ex) const + -> For,Expr> { //static const size_t LAYER = typename Expr::LAYER; - return For,Expr>(this, step, ex); + return For,Expr>(this, step, ex); } - template + template template - auto SingleIndex::iforh(size_t step, Expr ex) const - -> For,Expr,ForType::HIDDEN> + auto GenSingleIndex::iforh(size_t step, Expr ex) const + -> For,Expr,ForType::HIDDEN> { //static const size_t LAYER = typename Expr::LAYER; - return For,Expr,ForType::HIDDEN>(this, step, ex); + return For,Expr,ForType::HIDDEN>(this, step, ex); } - template + template template - auto SingleIndex::pifor(size_t step, Expr ex) const - -> PFor,Expr> + auto GenSingleIndex::pifor(size_t step, Expr ex) const + -> PFor,Expr> { //static const size_t LAYER = typename Expr::LAYER; - return PFor,Expr>(this, step, ex); + return PFor,Expr>(this, step, ex); } @@ -447,14 +470,14 @@ namespace MultiArrayTools * SingleRange * ********************/ - template - SingleRangeFactory::SingleRangeFactory(const std::vector& space) + template + GenSingleRangeFactory::GenSingleRangeFactory(const std::vector& space) { - mProd = std::shared_ptr( new SingleRange( space ) ); + mProd = std::shared_ptr( new GenSingleRange( space ) ); } - template - std::shared_ptr SingleRangeFactory::create() + template + std::shared_ptr GenSingleRangeFactory::create() { setSelf(); return mProd; @@ -464,9 +487,9 @@ namespace MultiArrayTools * SingleRange * ********************/ - template - SingleRange::SingleRange(const std::vector& space) : - RangeInterface >(), + template + GenSingleRange::GenSingleRange(const std::vector& space) : + RangeInterface >(), mSpace(space), mMSpace(mSpace) { //for(size_t i = 0; i != mSpace.size(); ++i){ @@ -474,50 +497,50 @@ namespace MultiArrayTools //} } - template - const U& SingleRange::get(size_t pos) const + template + const U& GenSingleRange::get(size_t pos) const { return mSpace[pos]; } - template - size_t SingleRange::getMeta(const U& metaPos) const + template + size_t GenSingleRange::getMeta(const U& metaPos) const { return mMSpace.at(metaPos); } - template - size_t SingleRange::size() const + template + size_t GenSingleRange::size() const { return mSpace.size(); } - template - size_t SingleRange::dim() const + template + size_t GenSingleRange::dim() const { return 1; } - template - bool SingleRange::isMeta(const U& metaPos) const + template + bool GenSingleRange::isMeta(const U& metaPos) const { return mMSpace.count(metaPos) != 0; } - template - SpaceType SingleRange::spaceType() const + template + SpaceType GenSingleRange::spaceType() const { return TYPE; } - template - std::string SingleRange::stringMeta(size_t pos) const + template + std::string GenSingleRange::stringMeta(size_t pos) const { return xToString(get(pos)); } - template - std::vector SingleRange::data() const + template + std::vector GenSingleRange::data() const { DataHeader h = dataHeader(); std::vector out; @@ -530,8 +553,8 @@ namespace MultiArrayTools return out; } - template - DataHeader SingleRange::dataHeader() const + template + DataHeader GenSingleRange::dataHeader() const { DataHeader h; h.spaceType = static_cast( TYPE ); @@ -541,19 +564,19 @@ namespace MultiArrayTools return h; } - template - typename SingleRange::IndexType SingleRange::begin() const + template + typename GenSingleRange::IndexType GenSingleRange::begin() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = 0; return i; } - template - typename SingleRange::IndexType SingleRange::end() const + template + typename GenSingleRange::IndexType GenSingleRange::end() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = size(); return i; diff --git a/src/lib/ranges/anonymous_range.cc b/src/lib/ranges/anonymous_range.cc index 3849270..4b5a337 100644 --- a/src/lib/ranges/anonymous_range.cc +++ b/src/lib/ranges/anonymous_range.cc @@ -196,7 +196,7 @@ namespace MultiArrayTools return mOrig; } - SingleRange::SingleRange(const std::vector>& origs) : + GenSingleRange::GenSingleRange(const std::vector>& origs) : RangeInterface(), mOrig(origs) { diff --git a/src/lib/ranges/range_types/classic_range.cc b/src/lib/ranges/range_types/classic_range.cc index 9cdba7d..db147d9 100644 --- a/src/lib/ranges/range_types/classic_range.cc +++ b/src/lib/ranges/range_types/classic_range.cc @@ -5,60 +5,60 @@ namespace MultiArrayTools { /******************** - * SingleRange * + * GenSingleRange * ********************/ - SingleRangeFactory::SingleRangeFactory(size_t size) + GenSingleRangeFactory::GenSingleRangeFactory(size_t size) { // Quasi Singleton if(not mProd){ - mProd = std::shared_ptr( new SingleRange(size) ); + mProd = std::shared_ptr( new GenSingleRange(size) ); setSelf(); } } - std::shared_ptr SingleRangeFactory::create() + std::shared_ptr GenSingleRangeFactory::create() { return mProd; } /******************** - * SingleRange * + * GenSingleRange * ********************/ - SingleRange::SingleRange(size_t size) : mSize(size) {} + GenSingleRange::GenSingleRange(size_t size) : mSize(size) {} - size_t SingleRange::get(size_t pos) const + size_t GenSingleRange::get(size_t pos) const { return pos; } - size_t SingleRange::getMeta(size_t metaPos) const + size_t GenSingleRange::getMeta(size_t metaPos) const { return metaPos; } - size_t SingleRange::size() const + size_t GenSingleRange::size() const { return mSize; } - size_t SingleRange::dim() const + size_t GenSingleRange::dim() const { return 1; } - SpaceType SingleRange::spaceType() const + SpaceType GenSingleRange::spaceType() const { return SpaceType::NONE; } - std::string SingleRange::stringMeta(size_t pos) const + std::string GenSingleRange::stringMeta(size_t pos) const { return std::to_string(get(pos)); } - std::vector SingleRange::data() const + std::vector GenSingleRange::data() const { DataHeader h = dataHeader(); std::vector out; @@ -70,7 +70,7 @@ namespace MultiArrayTools return out; } - DataHeader SingleRange::dataHeader() const + DataHeader GenSingleRange::dataHeader() const { DataHeader h; h.spaceType = static_cast( SpaceType::NONE ); @@ -80,17 +80,17 @@ namespace MultiArrayTools } - typename SingleRange::IndexType SingleRange::begin() const + typename GenSingleRange::IndexType GenSingleRange::begin() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = 0; return i; } - typename SingleRange::IndexType SingleRange::end() const + typename GenSingleRange::IndexType GenSingleRange::end() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = size(); return i; diff --git a/src/lib/ranges/range_types/null_range.cc b/src/lib/ranges/range_types/null_range.cc index d42ebb5..46ac26b 100644 --- a/src/lib/ranges/range_types/null_range.cc +++ b/src/lib/ranges/range_types/null_range.cc @@ -10,11 +10,11 @@ namespace MultiArrayTools } /******************** - * SingleRange * + * GenSingleRange * ********************/ - std::shared_ptr> - SingleRangeFactory::mRInstance = nullptr; + std::shared_ptr> + GenSingleRangeFactory::mRInstance = nullptr; std::shared_ptr nullr() { @@ -28,12 +28,12 @@ namespace MultiArrayTools return std::make_shared(nullr()); } - SingleRangeFactory::SingleRangeFactory() + GenSingleRangeFactory::GenSingleRangeFactory() { // Singleton if(not mRInstance){ if(not mProd){ - mProd = std::shared_ptr( new SingleRange() ); + mProd = std::shared_ptr( new GenSingleRange() ); setSelf(); } mRInstance = std::dynamic_pointer_cast( mProd ); @@ -42,46 +42,46 @@ namespace MultiArrayTools } } - std::shared_ptr SingleRangeFactory::create() + std::shared_ptr GenSingleRangeFactory::create() { return mProd; } /******************** - * SingleRange * + * GenSingleRange * ********************/ - size_t SingleRange::get(size_t pos) const + size_t GenSingleRange::get(size_t pos) const { return 0; } - size_t SingleRange::getMeta(size_t metapos) const + size_t GenSingleRange::getMeta(size_t metapos) const { return 0; } - size_t SingleRange::size() const + size_t GenSingleRange::size() const { return 1; } - size_t SingleRange::dim() const + size_t GenSingleRange::dim() const { return 1; } - SpaceType SingleRange::spaceType() const + SpaceType GenSingleRange::spaceType() const { return SpaceType::NUL; } - std::string SingleRange::stringMeta(size_t pos) const + std::string GenSingleRange::stringMeta(size_t pos) const { return std::to_string(get(pos)); } - std::vector SingleRange::data() const + std::vector GenSingleRange::data() const { DataHeader h = dataHeader(); std::vector out; @@ -91,7 +91,7 @@ namespace MultiArrayTools return out; } - DataHeader SingleRange::dataHeader() const + DataHeader GenSingleRange::dataHeader() const { DataHeader h; h.spaceType = static_cast( SpaceType::NUL ); @@ -100,17 +100,17 @@ namespace MultiArrayTools return h; } - typename SingleRange::IndexType SingleRange::begin() const + typename GenSingleRange::IndexType GenSingleRange::begin() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = 0; return i; } - typename SingleRange::IndexType SingleRange::end() const + typename GenSingleRange::IndexType GenSingleRange::end() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = size(); return i; @@ -118,12 +118,12 @@ namespace MultiArrayTools // put this in the interface class !!! /* - std::shared_ptr SingleRange::index() const + std::shared_ptr GenSingleRange::index() const { typedef IndexWrapper IW; return std::make_shared ( std::make_shared - ( std::dynamic_pointer_cast > + ( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ) ); } */ diff --git a/src/lib/ranges/range_types/space_range.cc b/src/lib/ranges/range_types/space_range.cc index e4ca7f3..ae4758e 100644 --- a/src/lib/ranges/range_types/space_range.cc +++ b/src/lib/ranges/range_types/space_range.cc @@ -11,60 +11,60 @@ namespace MultiArrayTools } /******************** - * SingleRange * + * GenSingleRange * ********************/ - SingleRangeFactory::SingleRangeFactory(size_t size) + GenSingleRangeFactory::GenSingleRangeFactory(size_t size) { // Quasi Singleton if(not mProd){ - mProd = std::shared_ptr( new SingleRange(size) ); + mProd = std::shared_ptr( new GenSingleRange(size) ); setSelf(); } } - std::shared_ptr SingleRangeFactory::create() + std::shared_ptr GenSingleRangeFactory::create() { return mProd; } /******************** - * SingleRange * + * GenSingleRange * ********************/ - SingleRange::SingleRange(size_t size) : mSize(size) { } + GenSingleRange::GenSingleRange(size_t size) : mSize(size) { } - int SingleRange::get(size_t pos) const + int GenSingleRange::get(size_t pos) const { return pos > mSize / 2 ? pos - mSize : pos; } - size_t SingleRange::getMeta(int metaPos) const + size_t GenSingleRange::getMeta(int metaPos) const { return metaPos < 0 ? metaPos + mSize : metaPos; } - size_t SingleRange::size() const + size_t GenSingleRange::size() const { return mSize; } - size_t SingleRange::dim() const + size_t GenSingleRange::dim() const { return 1; } - SpaceType SingleRange::spaceType() const + SpaceType GenSingleRange::spaceType() const { return SpaceType::PSPACE; } - std::string SingleRange::stringMeta(size_t pos) const + std::string GenSingleRange::stringMeta(size_t pos) const { return std::to_string(get(pos)); } - std::vector SingleRange::data() const + std::vector GenSingleRange::data() const { DataHeader h = dataHeader(); std::vector out; @@ -76,7 +76,7 @@ namespace MultiArrayTools return out; } - DataHeader SingleRange::dataHeader() const + DataHeader GenSingleRange::dataHeader() const { DataHeader h; h.spaceType = static_cast( SpaceType::PSPACE ); @@ -85,17 +85,17 @@ namespace MultiArrayTools return h; } - typename SingleRange::IndexType SingleRange::begin() const + typename GenSingleRange::IndexType GenSingleRange::begin() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = 0; return i; } - typename SingleRange::IndexType SingleRange::end() const + typename GenSingleRange::IndexType GenSingleRange::end() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = size(); return i; diff --git a/src/lib/ranges/range_types/spin_range.cc b/src/lib/ranges/range_types/spin_range.cc index b391481..8ba73f4 100644 --- a/src/lib/ranges/range_types/spin_range.cc +++ b/src/lib/ranges/range_types/spin_range.cc @@ -10,58 +10,58 @@ namespace MultiArrayTools } /******************** - * SingleRange * + * GenSingleRange * ********************/ - SingleRangeFactory::SingleRangeFactory() + GenSingleRangeFactory::GenSingleRangeFactory() { // Quasi Singleton if(not mProd){ - mProd = std::shared_ptr( new SingleRange() ); + mProd = std::shared_ptr( new GenSingleRange() ); setSelf(); } } - std::shared_ptr SingleRangeFactory::create() + std::shared_ptr GenSingleRangeFactory::create() { return mProd; } /******************** - * SingleRange * + * GenSingleRange * ********************/ - size_t SingleRange::get(size_t pos) const + size_t GenSingleRange::get(size_t pos) const { return pos; } - size_t SingleRange::getMeta(size_t metaPos) const + size_t GenSingleRange::getMeta(size_t metaPos) const { return metaPos; } - size_t SingleRange::size() const + size_t GenSingleRange::size() const { return mSpinNum; } - size_t SingleRange::dim() const + size_t GenSingleRange::dim() const { return 1; } - SpaceType SingleRange::spaceType() const + SpaceType GenSingleRange::spaceType() const { return SpaceType::SPIN; } - std::string SingleRange::stringMeta(size_t pos) const + std::string GenSingleRange::stringMeta(size_t pos) const { return std::to_string(get(pos)); } - std::vector SingleRange::data() const + std::vector GenSingleRange::data() const { DataHeader h = dataHeader(); std::vector out; @@ -71,7 +71,7 @@ namespace MultiArrayTools return out; } - DataHeader SingleRange::dataHeader() const + DataHeader GenSingleRange::dataHeader() const { DataHeader h; h.spaceType = static_cast( SpaceType::SPIN ); @@ -80,17 +80,17 @@ namespace MultiArrayTools return h; } - typename SingleRange::IndexType SingleRange::begin() const + typename GenSingleRange::IndexType GenSingleRange::begin() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = 0; return i; } - typename SingleRange::IndexType SingleRange::end() const + typename GenSingleRange::IndexType GenSingleRange::end() const { - SingleIndex i( std::dynamic_pointer_cast > + GenSingleIndex i( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ); i = size(); return i; @@ -98,12 +98,12 @@ namespace MultiArrayTools // put this in the interface class !!! /* - std::shared_ptr SingleRange::index() const + std::shared_ptr GenSingleRange::index() const { typedef IndexWrapper IW; return std::make_shared ( std::make_shared - ( std::dynamic_pointer_cast > + ( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ) ); } */ diff --git a/src/tests/op_perf_test.cc b/src/tests/op_perf_test.cc index 4c623ec..62accee 100644 --- a/src/tests/op_perf_test.cc +++ b/src/tests/op_perf_test.cc @@ -134,13 +134,14 @@ namespace { typedef MultiRangeFactory SR8F; typedef SR8F::oType SR8; - static const size_t os = 3000; - static const size_t s = 65536*os; - + static const size_t os = 30; + static const size_t is = 65536; + static const size_t s = is*os; + OpTest_Spin() { - data.resize(s); - for(size_t i = 0; i != s; ++i){ + data.resize(is); + for(size_t i = 0; i != is; ++i){ double arg = static_cast( i - s ) - 0.1; data[i] = sin(arg); //VCHECK(data[i]); @@ -162,7 +163,7 @@ namespace { void OpTest_Spin::contract() { - MultiArray ma( cr, sr, sr, sr, sr, sr, sr, sr, sr, data); + MultiArray ma( sr, sr, sr, sr, sr, sr, sr, sr, data); MultiArray res1( cr, sr, sr ); auto ii = MAT::getIndex(cr); @@ -177,7 +178,8 @@ namespace { std::clock_t begin = std::clock(); //for(size_t i = 0; i != os; ++i){ - res1(ii ,delta, deltap).par() += ma(ii, delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); + //res1(ii ,delta, deltap).par() += ma(ii, delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); + res1(ii ,delta, deltap) += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); //} std::clock_t end = std::clock(); std::cout << "MultiArray time: " << static_cast( end - begin ) / CLOCKS_PER_SEC @@ -199,7 +201,7 @@ namespace { for(size_t d = 0; d != 4; ++d){ for(size_t p = 0; p != 4; ++p){ const size_t tidx = i*4*4 + d*4 + p; - const size_t sidx = i*65536 + d*4*4*4*4*4*4*4 + a*5*4*4*4*4*4 + b*5*4*4*4 + c*5*4 + p; + const size_t sidx = /*i*65536 +*/ d*4*4*4*4*4*4*4 + a*5*4*4*4*4*4 + b*5*4*4*4 + c*5*4 + p; vres[tidx] += data[sidx]; } }