diff --git a/CMakeLists.txt b/CMakeLists.txt index a66ce5c..77f8ffb 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 -funroll-loops -ftree-vectorize") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -g -Wpedantic -Ofast -mavx2 -funroll-loops -fopenmp") enable_testing() diff --git a/src/include/allocator.h b/src/include/allocator.h new file mode 100644 index 0000000..2cfdd2c --- /dev/null +++ b/src/include/allocator.h @@ -0,0 +1,74 @@ + +#ifndef __ma_allocator__ +#define __ma_allocator__ + +#include +#include +#include +#include +#include +#include + +namespace MultiArrayHelper +{ + + template + struct Allocator + { + typedef T value_type; + static constexpr size_t type_size = sizeof(value_type); + static constexpr size_t N = 32; + + Allocator() = default; + + template + Allocator(const Allocator& x) {} + + T* allocate(size_t n) + { + //constexpr size_t NN = N*type_size; + const size_t nn = n*type_size; + if(n > static_cast(-1-N)) throw std::bad_alloc(); + auto p = static_cast(std::malloc(nn + N)); + if(not p) throw std::bad_alloc(); + auto ip = reinterpret_cast(p); + auto diff = N - (ip % N); + p += diff; + //auto ipx = reinterpret_cast(p); + //std::cout << "ixp: " << ipx << std::endl; + //std::cout << "ixp %: " << ipx % N << std::endl; + auto ps = reinterpret_cast(p); + ps[-1] = diff; + return reinterpret_cast(p); + } + + void deallocate(T* p, size_t n) + { + auto ps = reinterpret_cast(p); + std::free(reinterpret_cast(p)-ps[-1]); + } + }; + + template + bool operator==(const Allocator& a, const Allocator& b) + { + return true; + } + + template + bool operator!=(const Allocator& a, const Allocator& b) + { + return false; + } + + +} // namespace MultiArrayHelper + +namespace MultiArrayTools +{ + template + using vector = std::vector>; + +} // namespace MultiArrayTools + +#endif diff --git a/src/include/allocator.h~ b/src/include/allocator.h~ new file mode 100644 index 0000000..9636d7a --- /dev/null +++ b/src/include/allocator.h~ @@ -0,0 +1,62 @@ + +#ifndef __ma_allocator__ +#define __ma_allocator__ + +#include +#include +#include + +namespace MultiArrayHelper +{ + + template + struct Allocator + { + typedef T value_type; + static constexpr type_size = sizeof(value_type); + + Allocator() = default; + + template + Allocator(const Allocator& x) {} + + T* allocate(size_t n) + { + //constexpr size_t NN = N*type_size; + const size_t nn = n*type_size; + if(n > static_cast(-1-NN)) throw std::bad_alloc(); + auto p = static_cast(std::malloc(nn + N)); + if(not p) throw std::bad_alloc(); + auto ip = static_cast(p); + mDiff = N - (ip % N); + p += mDiff; + return static_cast(p); + } + + void deacllocate(T* p, size_t n) + { + std::free(p-mDiff); + } + + private: + std::intptr_t mDiff; + }; + + template + bool operator==(const Allocator& a, const Allocator& b) + { + return true; + } + + template + bool operator!=(const Allocator& a, const Allocator& b) + { + return false; + } + + template + using vector = vector; + +} // namespace MultiArrayHelper + +#endif diff --git a/src/include/conversions.h b/src/include/conversions.h index 87d1a1e..60a3b53 100644 --- a/src/include/conversions.h +++ b/src/include/conversions.h @@ -36,29 +36,87 @@ namespace MultiArrayTools namespace { template - using SC = ConversionSizes::OrigSize::template FromTo; + using SC = typename ConversionSizes::OrigSize::template FromTo; template - using SCR = SC; + using SCR = SC; template - using SCRR = GenSingleRange; - } - - template - Slice> tcast(MultiArray& ma) - { - return Slice> - ( ma.range()->space(), reinterpret_cast( ma.data() ) ); - } - - template - ConstSlice> tcast(const MultiArray& ma) - { - return ConstSlice> - ( ma.range()->space(), reinterpret_cast( ma.data() ) ); + using SCRR = GenSingleRange::SIZE>; } + template + struct SubTuple + { + template + static inline auto mk(const RTP& rtp, const Ranges&... rs) + -> decltype(SubTuple::mk(rtp, std::get(rtp), rs...)) + { + return SubTuple::mk(rtp, std::get(rtp), rs...); + } + }; + + template <> + struct SubTuple<0> + { + template + static inline auto mk(const RTP& rtp, const Ranges&... rs) + -> decltype(std::make_tuple(std::get<0>(rtp), rs...)) + { + return std::make_tuple(std::get<0>(rtp), rs...); + } + }; + + template + using LastR = typename std::tuple_element>::type; + + template + auto rtcast(const std::tuple...>& rtp) + -> decltype(std::tuple_cat(SubTuple::mk(rtp), + std::make_tuple( std::dynamic_pointer_cast>> + ( SCRR>::factory().create() ) ) )) + { + return std::tuple_cat(SubTuple::mk(rtp), + std::make_tuple( std::dynamic_pointer_cast>> + ( SCRR>::factory().create() ) ) ); + } + + template + inline Slice rangeTpToSlice( const std::tuple...>& rtp, T* data ) + { + return Slice(rtp, data); + } + + template + inline ConstSlice rangeTpToSlice( const std::tuple...>& rtp, const T* data ) + { + return ConstSlice(rtp, data); + } + + template + auto tcast(MultiArray& ma) + -> decltype(rangeTpToSlice + ( rtcast( ma.range()->space() ), + reinterpret_cast( ma.data() ) )) + { + // VCHECK(reinterpret_cast(ma.data()) % 32); + //VCHECK(reinterpret_cast(reinterpret_cast(ma.data())) % 32); + return rangeTpToSlice + ( rtcast( ma.range()->space() ), + reinterpret_cast( ma.data() ) ); + } + + template + auto tcast(const MultiArray& ma) + -> decltype(rangeTpToSlice + ( rtcast( ma.range()->space() ), + reinterpret_cast( ma.data() ) )) + { + //VCHECK(reinterpret_cast(ma.data()) % 32); + //VCHECK(reinterpret_cast(reinterpret_cast(ma.data())) % 32); + return rangeTpToSlice + ( rtcast( ma.range()->space() ), + reinterpret_cast( ma.data() ) ); + } } - #endif diff --git a/src/include/functional_multi_array.h b/src/include/functional_multi_array.h index 7f4c50b..2e10629 100644 --- a/src/include/functional_multi_array.h +++ b/src/include/functional_multi_array.h @@ -15,7 +15,7 @@ namespace MultiArrayTools static auto mk(const std::shared_ptr& i) -> MultiArray { - std::vector vv(i->range()->size()); + vector vv(i->range()->size()); for(Index j = (*i); j.pos() != j.max(); ++j){ vv[j.pos()] = j.meta(); } diff --git a/src/include/helper_tools.cc.h b/src/include/helper_tools.cc.h index fc09571..28750a3 100644 --- a/src/include/helper_tools.cc.h +++ b/src/include/helper_tools.cc.h @@ -109,7 +109,7 @@ namespace MultiArrayTools } template - auto createRange(const std::vector& cvec) + auto createRange(const vector& cvec) -> std::shared_ptr { const char* dp = cvec.data(); diff --git a/src/include/helper_tools.h b/src/include/helper_tools.h index 1eaa9a6..aa35dd1 100644 --- a/src/include/helper_tools.h +++ b/src/include/helper_tools.h @@ -61,7 +61,7 @@ namespace MultiArrayTools -> std::shared_ptr; template - auto createRange(const std::vector& cvec) + auto createRange(const vector& cvec) -> std::shared_ptr; template diff --git a/src/include/map_range.cc.h b/src/include/map_range.cc.h index c4841d3..2f661a6 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -347,7 +347,7 @@ namespace MultiArrayTools } } if(not check){ - std::vector pv(sizeof...(Ranges)); + vector pv(sizeof...(Ranges)); RPackNum::RangesToVec(ptp, pv); pv.push_back( reinterpret_cast ( &std::dynamic_pointer_cast( mProd )->mMapf ) ); @@ -376,8 +376,8 @@ namespace MultiArrayTools mult[mapf[ii]]++; } - std::vector outmeta(mult.size()); - std::vector outmult(mult.size()); + vector outmeta(mult.size()); + vector outmult(mult.size()); size_t cnt = 0; for(auto& x: mult){ @@ -404,12 +404,12 @@ namespace MultiArrayTools for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) { max = mapf[ii]+1 > max ? mapf[ii]+1 : max; } - std::vector mult(max,0); + vector mult(max,0); for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) { mult[mapf[ii]]++; } - std::vector outmult(mult.size()); + vector outmult(mult.size()); size_t cnt = 0; for(auto& x: mult){ @@ -505,10 +505,10 @@ namespace MultiArrayTools } template - std::vector GenMapRange::data() const + vector GenMapRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; //out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); diff --git a/src/include/map_range.h b/src/include/map_range.h index 61c7d43..0406c7c 100644 --- a/src/include/map_range.h +++ b/src/include/map_range.h @@ -259,7 +259,7 @@ namespace MultiArrayTools virtual DataHeader dataHeader() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; const Space& space() const; diff --git a/src/include/map_range_factory_product_map.h b/src/include/map_range_factory_product_map.h index 992a822..d02d7c0 100644 --- a/src/include/map_range_factory_product_map.h +++ b/src/include/map_range_factory_product_map.h @@ -18,7 +18,7 @@ namespace MultiArrayTools friend class GenMapRangeFactory; private: - static std::map,std::vector > mAleadyCreated; + static std::map,vector > mAleadyCreated; }; } diff --git a/src/include/mbase_def.h b/src/include/mbase_def.h index 72a8b7f..2c53cb2 100644 --- a/src/include/mbase_def.h +++ b/src/include/mbase_def.h @@ -3,6 +3,7 @@ #define __mbase_def_h__ #include "ranges/rbase_def.h" +#include "allocator.h" namespace MultiArrayTools { diff --git a/src/include/multi_array.cc.h b/src/include/multi_array.cc.h index 55af2c7..1395490 100644 --- a/src/include/multi_array.cc.h +++ b/src/include/multi_array.cc.h @@ -7,7 +7,7 @@ namespace MultiArrayTools Scalar scalar(const T& in) { NullRF nrf; - return Scalar( std::dynamic_pointer_cast( nrf.create() ), std::vector( { in } ) ); + return Scalar( std::dynamic_pointer_cast( nrf.create() ), vector( { in } ) ); } /******************* @@ -24,7 +24,7 @@ namespace MultiArrayTools template MultiArray::MultiArray(const typename CRange::Space& space, - std::vector&& vec) : + vector&& vec) : MutableMultiArrayBase(space), mCont(vec) { @@ -52,7 +52,7 @@ namespace MultiArrayTools } template - MultiArray::MultiArray(const std::shared_ptr&... ranges, const std::vector& vec) : + MultiArray::MultiArray(const std::shared_ptr&... ranges, const vector& vec) : MutableMultiArrayBase(ranges...), mCont(vec) { @@ -63,7 +63,7 @@ namespace MultiArrayTools } template - MultiArray::MultiArray(const std::shared_ptr&... ranges, std::vector&& vec) : + MultiArray::MultiArray(const std::shared_ptr&... ranges, vector&& vec) : MutableMultiArrayBase(ranges...), mCont(vec) { diff --git a/src/include/multi_array.h b/src/include/multi_array.h index 18ec445..aaa54ff 100644 --- a/src/include/multi_array.h +++ b/src/include/multi_array.h @@ -24,7 +24,6 @@ namespace MultiArrayTools return ma; } }; - template class MultiArray : public MutableMultiArrayBase @@ -41,15 +40,15 @@ namespace MultiArrayTools DEFAULT_MEMBERS(MultiArray); MultiArray(const std::shared_ptr&... ranges); MultiArray(const std::shared_ptr&... ranges, const T& val); - MultiArray(const std::shared_ptr&... ranges, const std::vector& vec); - MultiArray(const std::shared_ptr&... ranges, std::vector&& vec); + MultiArray(const std::shared_ptr&... ranges, const vector& vec); + MultiArray(const std::shared_ptr&... ranges, vector&& vec); MultiArray(const typename CRange::Space& space); - MultiArray(const typename CRange::Space& space, std::vector&& vec); + MultiArray(const typename CRange::Space& space, vector&& vec); MultiArray(MultiArray&& ama, SIZET... sizes); // Only if ALL ranges have default extensions: - //MultiArray(const std::vector& vec); - //MultiArray(std::vector&& vec); + //MultiArray(const vector& vec); + //MultiArray(vector&& vec); // template // MultiArray(const MultiArray,Range3> in); @@ -76,8 +75,8 @@ namespace MultiArrayTools virtual const T* data() const override; virtual T* data() override; - virtual std::vector& vdata() { return mCont; } - virtual const std::vector& vdata() const { return mCont; } + virtual vector& vdata() { return mCont; } + virtual const vector& vdata() const { return mCont; } virtual std::shared_ptr > anonymous(bool slice = false) const override; virtual std::shared_ptr > anonymousMove() override; @@ -99,7 +98,7 @@ namespace MultiArrayTools private: - std::vector mCont; + vector mCont; }; template @@ -119,7 +118,7 @@ namespace MultiArrayTools const size_t smas = sma.size(); const size_t mas = ma.size(); auto cr = ma.range()->cat(sma.range()); - std::vector ov; + vector ov; ov.reserve(mas * smas); for(auto& x: ma){ diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index 0099258..78ad36c 100644 --- a/src/include/ranges/anonymous_range.h +++ b/src/include/ranges/anonymous_range.h @@ -36,7 +36,7 @@ namespace MultiArrayTools template AnonymousRangeFactory(std::shared_ptr... origs); - AnonymousRangeFactory(const std::vector>& origs); + AnonymousRangeFactory(const vector>& origs); template void append(std::shared_ptr r); @@ -45,9 +45,9 @@ namespace MultiArrayTools private: - std::shared_ptr checkIfCreated(const std::vector >& pvec); + std::shared_ptr checkIfCreated(const vector >& pvec); - static std::map,std::vector > mAleadyCreated; + static std::map,vector > mAleadyCreated; bool mProductCreated = false; }; @@ -81,7 +81,7 @@ namespace MultiArrayTools virtual DataHeader dataHeader() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; std::shared_ptr sub(size_t num) const; @@ -91,10 +91,10 @@ namespace MultiArrayTools template std::shared_ptr > scast(SIZET... sizes) const; // save cast - const std::vector >& orig() const; + const vector >& orig() const; std::shared_ptr sreplace(const std::shared_ptr in, size_t num) const; - std::shared_ptr sreplace(const std::vector>& in, size_t num) const; + std::shared_ptr sreplace(const vector>& in, size_t num) const; bool isEmpty() const; @@ -114,12 +114,12 @@ namespace MultiArrayTools template GenSingleRange(std::shared_ptr... origs); - GenSingleRange(const std::vector>& origs); + GenSingleRange(const vector>& origs); size_t mSize = 1; bool mEmpty = true; - std::vector > mOrig; + vector > mOrig; }; } @@ -172,7 +172,7 @@ namespace MultiArrayHelper template <> inline void resolveSetRange(std::shared_ptr& rp, - const std::vector >& orig, + const vector >& orig, size_t origpos, size_t size) { AnonymousRangeFactory arf; @@ -184,7 +184,7 @@ namespace MultiArrayHelper } template <> - inline void setRangeToVec(std::vector >& v, + inline void setRangeToVec(vector >& v, std::shared_ptr r) { if(not r->isEmpty()){ diff --git a/src/include/ranges/dynamic_meta.h b/src/include/ranges/dynamic_meta.h index 5f054e8..29346f7 100644 --- a/src/include/ranges/dynamic_meta.h +++ b/src/include/ranges/dynamic_meta.h @@ -5,6 +5,8 @@ #include #include +#include "allocator.h" + namespace MultiArrayTools { @@ -14,7 +16,7 @@ namespace MultiArrayTools struct DynamicMetaSetter { template - static inline void set(const std::tuple& in, std::vector& meta) + static inline void set(const std::tuple& in, vector& meta) { typedef typename std::tuple_element>::type elemtype; meta[N].first = reinterpret_cast( &std::get(in) ); @@ -27,7 +29,7 @@ namespace MultiArrayTools struct DynamicMetaSetter<0> { template - static inline void set(const std::tuple& in, std::vector& meta) + static inline void set(const std::tuple& in, vector& meta) { typedef typename std::tuple_element<0,std::tuple>::type elemtype; meta[0].first = reinterpret_cast( &std::get<0>(in) ); @@ -39,7 +41,7 @@ namespace MultiArrayTools class DynamicMetaT { private: - std::vector mMeta; + vector mMeta; public: DynamicMetaT() = default; diff --git a/src/include/ranges/dynamic_range.cc.h b/src/include/ranges/dynamic_range.cc.h index 254b5c5..69a7980 100644 --- a/src/include/ranges/dynamic_range.cc.h +++ b/src/include/ranges/dynamic_range.cc.h @@ -72,7 +72,7 @@ namespace MultiArrayTools } template - DynamicRangeFactory::DynamicRangeFactory(const std::vector>& origs) + DynamicRangeFactory::DynamicRangeFactory(const vector>& origs) { mProd = std::shared_ptr( new DynamicRange( origs ) ); } @@ -99,10 +99,10 @@ namespace MultiArrayTools // INSTANCIATE IF NEEDED!! template - std::map,std::vector > DynamicRangeFactory::mAleadyCreated; + std::map,vector > DynamicRangeFactory::mAleadyCreated; template - std::shared_ptr DynamicRangeFactory::checkIfCreated(const std::vector >& pvec) + std::shared_ptr DynamicRangeFactory::checkIfCreated(const vector >& pvec) { std::shared_ptr out; bool check = false; @@ -122,7 +122,7 @@ namespace MultiArrayTools } } if(not check){ - std::vector app(pvec.size()); + vector app(pvec.size()); for(size_t i = 0; i != app.size(); ++i){ app[i] = reinterpret_cast( pvec[i].get() ); } @@ -223,7 +223,7 @@ namespace MultiArrayTools } template - DynamicIndex& DynamicIndex::operator()(const std::vector>>& ivec) + DynamicIndex& DynamicIndex::operator()(const vector>>& ivec) { assert(mIVec.size() == ivec.size()); for(size_t i = 0; i != mIVec.size(); ++i){ @@ -237,7 +237,7 @@ namespace MultiArrayTools template DynamicIndex& DynamicIndex::operator()(const std::shared_ptr&... is) { - std::vector>> tmp = + vector>> tmp = { std::make_shared>(is)... }; assert(mIVec.size() == tmp.size()); @@ -489,10 +489,10 @@ namespace MultiArrayTools } template - std::vector DynamicRange::data() const + vector DynamicRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); for(auto& x: mOrig){ @@ -571,7 +571,7 @@ namespace MultiArrayTools } template - DynamicRange::DynamicRange(const std::vector>& origs) : + DynamicRange::DynamicRange(const vector>& origs) : RangeInterface>(), mOrig(origs) { @@ -602,7 +602,7 @@ namespace MultiArrayTools } template - const std::vector >& DynamicRange::orig() const + const vector >& DynamicRange::orig() const { return mOrig; } diff --git a/src/include/ranges/dynamic_range.h b/src/include/ranges/dynamic_range.h index 4388eb0..61e3525 100644 --- a/src/include/ranges/dynamic_range.h +++ b/src/include/ranges/dynamic_range.h @@ -172,7 +172,7 @@ namespace MultiArrayTools class DynamicIndex : public IndexInterface,DynamicMetaT> { private: - typedef std::vector>,size_t>> IVecT; + typedef vector>,size_t>> IVecT; IVecT mIVec; @@ -197,7 +197,7 @@ namespace MultiArrayTools DynamicIndex& operator--(); DynamicIndex& operator()(const IVecT& ivec); - DynamicIndex& operator()(const std::vector>>& ivec); + DynamicIndex& operator()(const vector>>& ivec); template DynamicIndex& operator()(const std::shared_ptr&... is); @@ -259,7 +259,7 @@ namespace MultiArrayTools template DynamicRangeFactory(std::shared_ptr... origs); - DynamicRangeFactory(const std::vector>& origs); + DynamicRangeFactory(const vector>& origs); template void append(std::shared_ptr r); @@ -268,9 +268,9 @@ namespace MultiArrayTools private: - std::shared_ptr checkIfCreated(const std::vector >& pvec); + std::shared_ptr checkIfCreated(const vector >& pvec); - static std::map,std::vector > mAleadyCreated; + static std::map,vector > mAleadyCreated; bool mProductCreated = false; }; @@ -299,12 +299,12 @@ namespace MultiArrayTools template DynamicRange(std::shared_ptr... origs); - DynamicRange(const std::vector>& origs); + DynamicRange(const vector>& origs); size_t mSize = 1; bool mEmpty = true; - std::vector > mOrig; + vector > mOrig; public: virtual size_t size() const final; @@ -320,7 +320,7 @@ namespace MultiArrayTools virtual DataHeader dataHeader() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; std::shared_ptr sub(size_t num) const; @@ -330,7 +330,7 @@ namespace MultiArrayTools template std::shared_ptr > scast(SIZET... sizes) const; // save cast - const std::vector >& orig() const; + const vector >& orig() const; void sreplace(const std::shared_ptr in, size_t num); @@ -352,7 +352,7 @@ namespace MultiArrayHelper template inline void resolveSetRange(std::shared_ptr>& rp, - const std::vector >& orig, + const vector >& orig, size_t origpos, size_t size) { DynamicRangeFactory arf; @@ -364,7 +364,7 @@ namespace MultiArrayHelper } template - inline void setRangeToVec(std::vector >& v, + inline void setRangeToVec(vector >& v, std::shared_ptr> r) { if(not r->isEmpty()){ diff --git a/src/include/ranges/multi_range.h b/src/include/ranges/multi_range.h index 9f6ae4e..dcf0eb5 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -201,7 +201,7 @@ namespace MultiArrayTools virtual DataHeader dataHeader() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; const Space& space() const; @@ -519,7 +519,7 @@ namespace MultiArrayTools } } if(not check){ - std::vector pv(sizeof...(Ranges)); + vector pv(sizeof...(Ranges)); RPackNum::RangesToVec(ptp, pv); MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv; out = mProd; @@ -590,10 +590,10 @@ namespace MultiArrayTools } template - std::vector MultiRange::data() const + vector MultiRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; //out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); diff --git a/src/include/ranges/multi_range_factory_product_map.h b/src/include/ranges/multi_range_factory_product_map.h index c6b10df..e9dcb38 100644 --- a/src/include/ranges/multi_range_factory_product_map.h +++ b/src/include/ranges/multi_range_factory_product_map.h @@ -17,7 +17,7 @@ namespace MultiArrayTools friend class MultiRangeFactory; private: - static std::map,std::vector > mAleadyCreated; + static std::map,vector > mAleadyCreated; }; } diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index fb5605b..846070e 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -81,7 +81,7 @@ namespace MultiArrayTools std::intptr_t id() const; virtual std::string stringMeta(size_t pos) const = 0; - virtual std::vector data() const = 0; // usefull when writing to files, etc... + virtual vector data() const = 0; // usefull when writing to files, etc... virtual SpaceType spaceType() const = 0; virtual DataHeader dataHeader() const = 0; diff --git a/src/include/ranges/range_types/classic_range.h b/src/include/ranges/range_types/classic_range.h index f9b4ed6..ee4ae3c 100644 --- a/src/include/ranges/range_types/classic_range.h +++ b/src/include/ranges/range_types/classic_range.h @@ -43,7 +43,7 @@ namespace MultiArrayTools virtual DataHeader dataHeader() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; size_t get(size_t pos) const; size_t getMeta(size_t metaPos) const; diff --git a/src/include/ranges/range_types/null_range.h b/src/include/ranges/range_types/null_range.h index 994bb29..a7db938 100644 --- a/src/include/ranges/range_types/null_range.h +++ b/src/include/ranges/range_types/null_range.h @@ -47,7 +47,7 @@ namespace MultiArrayTools virtual size_t dim() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; virtual SpaceType spaceType() const final; virtual DataHeader dataHeader() const final; diff --git a/src/include/ranges/range_types/space_range.h b/src/include/ranges/range_types/space_range.h index 46d660a..8235ff4 100644 --- a/src/include/ranges/range_types/space_range.h +++ b/src/include/ranges/range_types/space_range.h @@ -39,7 +39,7 @@ namespace MultiArrayTools virtual size_t dim() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; virtual SpaceType spaceType() const final; virtual DataHeader dataHeader() const final; diff --git a/src/include/ranges/range_types/spin_range.h b/src/include/ranges/range_types/spin_range.h index 97992b5..d720f94 100644 --- a/src/include/ranges/range_types/spin_range.h +++ b/src/include/ranges/range_types/spin_range.h @@ -40,7 +40,7 @@ namespace MultiArrayTools virtual size_t dim() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; virtual SpaceType spaceType() const final; virtual DataHeader dataHeader() const final; diff --git a/src/include/ranges/rbase_def.h b/src/include/ranges/rbase_def.h index 64ccc45..41c0a28 100644 --- a/src/include/ranges/rbase_def.h +++ b/src/include/ranges/rbase_def.h @@ -14,7 +14,7 @@ << " in " << __func__ << ": " << #a << " = " << a << std::endl; #endif - +#include "allocator.h" namespace MultiArrayTools { diff --git a/src/include/ranges/rpack_num.h b/src/include/ranges/rpack_num.h index a583455..7cabbe0 100644 --- a/src/include/ranges/rpack_num.h +++ b/src/include/ranges/rpack_num.h @@ -46,7 +46,7 @@ namespace MultiArrayHelper template - inline void resolveSetRange(std::shared_ptr& rp, const std::vector >& orig, + inline void resolveSetRange(std::shared_ptr& rp, const vector >& orig, size_t origpos, size_t size) { assert(size == 1); @@ -54,7 +54,7 @@ namespace MultiArrayHelper } template - inline void setRangeToVec(std::vector >& v, + inline void setRangeToVec(vector >& v, std::shared_ptr r) { v.insert(v.begin(), r); @@ -251,7 +251,7 @@ namespace MultiArrayHelper template static inline void RangesToVec(const std::tuple...>& rst, - std::vector >& v) + vector >& v) { setRangeToVec(v, std::get(rst)); RPackNum::RangesToVec(rst, v); @@ -259,7 +259,7 @@ namespace MultiArrayHelper template static inline void RangesToVec(const std::tuple...>& rst, - std::vector& v) + vector& v) { v[N] = reinterpret_cast( std::get(rst).get() ); RPackNum::RangesToVec(rst, v); @@ -324,7 +324,7 @@ namespace MultiArrayHelper } template - static inline void resolveRangeType(const std::vector >& orig, + static inline void resolveRangeType(const vector >& orig, RangeTuple& rtp, size_t off, size_t size, SIZET... sizes) { constexpr size_t tps = std::tuple_size::value; @@ -334,7 +334,7 @@ namespace MultiArrayHelper template static inline bool checkIfCreated(const std::tuple...>& p, - const std::vector& a) + const vector& a) { return reinterpret_cast( std::get(p).get() ) == a[N] and RPackNum::checkIfCreated(p,a); @@ -347,22 +347,22 @@ namespace MultiArrayHelper } template - static inline void fillRangeDataVec(std::vector& out, + static inline void fillRangeDataVec(vector& out, const std::tuple...>& tp) { - std::vector part = std::get(tp)->data(); + vector part = std::get(tp)->data(); out.insert(out.end(), part.begin(), part.end()); RPackNum::fillRangeDataVec(out, tp); } template - static inline bool compareSpaceTypes(const std::vector >& rbvec) + static inline bool compareSpaceTypes(const vector >& rbvec) { return rbvec[SIZE-N-1]->spaceType() == Range::STYPE and RPackNum::template compareSpaceTypes(rbvec); } template - static inline void setSpace(const std::vector >& rbvec, + static inline void setSpace(const vector >& rbvec, std::tuple...>& stp) { typedef typename std::remove_reference( stp ))>::type RType; @@ -529,14 +529,14 @@ namespace MultiArrayHelper template static inline void RangesToVec(const std::tuple...>& rst, - std::vector& v) + vector& v) { v[0] = reinterpret_cast( std::get<0>(rst).get() );; } template static inline void RangesToVec(const std::tuple...>& rst, - std::vector >& v) + vector >& v) { setRangeToVec(v, std::get<0>(rst)); } @@ -596,7 +596,7 @@ namespace MultiArrayHelper } template - static inline void resolveRangeType(const std::vector >& orig, + static inline void resolveRangeType(const vector >& orig, RangeTuple& rtp, size_t off, size_t size) { constexpr size_t tps = std::tuple_size::value; @@ -605,7 +605,7 @@ namespace MultiArrayHelper template static inline bool checkIfCreated(const std::tuple...>& p, - const std::vector& a) + const vector& a) { return reinterpret_cast( std::get<0>(p).get() ) == a[0]; } @@ -617,21 +617,21 @@ namespace MultiArrayHelper } template - static inline void fillRangeDataVec(std::vector& out, + static inline void fillRangeDataVec(vector& out, const std::tuple...>& tp) { - std::vector part = std::get(tp)->data(); + vector part = std::get(tp)->data(); out.insert(out.end(), part.begin(), part.end()); } template - static inline bool compareSpaceTypes(const std::vector >& rbvec) + static inline bool compareSpaceTypes(const vector >& rbvec) { return rbvec[SIZE-1]->spaceType() == Range::STYPE; } template - static inline void setSpace(const std::vector >& rbvec, + static inline void setSpace(const vector >& rbvec, std::tuple...>& stp) { typedef typename std::remove_reference( stp ))>::type RType; diff --git a/src/include/ranges/single_range.h b/src/include/ranges/single_range.h index 57d76f7..dd88c27 100644 --- a/src/include/ranges/single_range.h +++ b/src/include/ranges/single_range.h @@ -107,9 +107,8 @@ namespace MultiArrayTools typedef GenSingleRange oType; GenSingleRangeFactory() = delete; - GenSingleRangeFactory(const std::vector& space); + GenSingleRangeFactory(const vector& space); std::shared_ptr create(); - }; template @@ -125,7 +124,7 @@ namespace MultiArrayTools MetaMap& operator=(MetaMap&& in) = default; //MetaMap(const std::map& in) : mMap(in) {} - MetaMap(const std::vector& in) + MetaMap(const vector& in) { for(size_t i = 0; i != in.size(); ++i){ mMap[in[i]] = i; @@ -140,7 +139,7 @@ namespace MultiArrayTools class MetaMap > { private: - std::vector mMap; + vector mMap; int min1; int min2; int max1; @@ -156,7 +155,7 @@ namespace MultiArrayTools MetaMap& operator=(const MetaMap& in) = default; MetaMap& operator=(MetaMap&& in) = default; - MetaMap(const std::vector& in) : min1(in[0][0]), + MetaMap(const vector& in) : min1(in[0][0]), min2(in[0][1]), max1(in[0][0]), max2(in[0][1]) @@ -201,6 +200,20 @@ namespace MultiArrayTools static constexpr size_t SIZE = -1; }; + template + struct CheckDefault + { + static constexpr size_t ISDEFAULT = false; + static constexpr size_t HASMETACONT = true; + }; + + template <> + struct CheckDefault + { + static constexpr size_t ISDEFAULT = true; + static constexpr size_t HASMETACONT = false; + }; + template class GenSingleRange : public RangeInterface > { @@ -219,7 +232,7 @@ namespace MultiArrayTools virtual DataHeader dataHeader() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; bool isMeta(const U& metaPos) const; @@ -231,19 +244,26 @@ namespace MultiArrayTools friend GenSingleRangeFactory; - static constexpr bool defaultable = false; + static GenSingleRangeFactory factory() + { + static_assert( not CheckDefault::HASMETACONT, + "asked for default factory for meta data containing range" ); + return GenSingleRangeFactory(vector()); + } + + static constexpr bool defaultable = CheckDefault::ISDEFAULT; static constexpr size_t ISSTATIC = CheckStatic::ISSTATIC; static constexpr size_t SIZE = CheckStatic::SIZE; - static constexpr bool HASMETACONT = true; + static constexpr bool HASMETACONT = CheckDefault::HASMETACONT; protected: GenSingleRange() = delete; GenSingleRange(const GenSingleRange& in) = delete; - GenSingleRange(const std::vector& space); + GenSingleRange(const vector& space); - std::vector mSpace; + vector mSpace; //std::map mMSpace; MetaMap mMSpace; }; @@ -471,7 +491,7 @@ namespace MultiArrayTools ********************/ template - GenSingleRangeFactory::GenSingleRangeFactory(const std::vector& space) + GenSingleRangeFactory::GenSingleRangeFactory(const vector& space) { mProd = std::shared_ptr( new GenSingleRange( space ) ); } @@ -488,7 +508,7 @@ namespace MultiArrayTools ********************/ template - GenSingleRange::GenSingleRange(const std::vector& space) : + GenSingleRange::GenSingleRange(const vector& space) : RangeInterface >(), mSpace(space), mMSpace(mSpace) { @@ -509,10 +529,22 @@ namespace MultiArrayTools return mMSpace.at(metaPos); } + template + inline size_t getStatSizeOrDyn(size_t size) + { + return SIZE; + } + + template <> + inline size_t getStatSizeOrDyn<-1>(size_t size) + { + return size; + } + template size_t GenSingleRange::size() const { - return mSpace.size(); + return getStatSizeOrDyn(mSpace.size()); } template @@ -540,10 +572,10 @@ namespace MultiArrayTools } template - std::vector GenSingleRange::data() const + vector GenSingleRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); diff --git a/src/include/ranges/subrange.h b/src/include/ranges/subrange.h index 76e5fa2..d963549 100644 --- a/src/include/ranges/subrange.h +++ b/src/include/ranges/subrange.h @@ -100,7 +100,7 @@ namespace MultiArrayTools SubRangeFactory() = delete; SubRangeFactory(const std::shared_ptr& fullRange, - const std::vector& subset); + const vector& subset); std::shared_ptr create(); }; @@ -121,7 +121,7 @@ namespace MultiArrayTools virtual DataHeader dataHeader() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; bool isMeta(const MetaType& metaPos) const; @@ -132,7 +132,7 @@ namespace MultiArrayTools virtual IndexType end() const final; std::shared_ptr fullRange() const; - const std::vector& subset() const; + const vector& subset() const; std::shared_ptr> outRange() const; friend SubRangeFactory; @@ -147,10 +147,10 @@ namespace MultiArrayTools SubRange() = delete; SubRange(const SubRange& in) = delete; - SubRange(const std::shared_ptr& fullRange, const std::vector& subset); + SubRange(const std::shared_ptr& fullRange, const vector& subset); std::shared_ptr mFullRange; - std::vector mSubSet; + vector mSubSet; }; } // namespace MultiArrayTools @@ -350,7 +350,7 @@ namespace MultiArrayTools template SubRangeFactory::SubRangeFactory(const std::shared_ptr& fullRange, - const std::vector& subset) + const vector& subset) { mProd = std::shared_ptr( new SubRange( fullRange, subset ) ); } @@ -368,7 +368,7 @@ namespace MultiArrayTools template SubRange::SubRange(const std::shared_ptr& fullRange, - const std::vector& subset) : + const vector& subset) : RangeInterface>(), mFullRange(fullRange), mSubSet(subset) {} @@ -408,14 +408,14 @@ namespace MultiArrayTools } template - std::vector SubRange::data() const + vector SubRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); - std::vector subvec(mSubSet.size()); + vector subvec(mSubSet.size()); size_t i = 0; for(auto& x: mSubSet){ subvec[i++] = mFullRange->get(x); @@ -477,7 +477,7 @@ namespace MultiArrayTools } template - const std::vector& SubRange::subset() const + const vector& SubRange::subset() const { return mSubSet; } @@ -485,7 +485,7 @@ namespace MultiArrayTools template std::shared_ptr::MetaType,SpaceType::ANY>> SubRange::outRange() const { - std::vector ometa(mSubSet.size()); + vector ometa(mSubSet.size()); size_t i = 0; for(auto& x: mSubSet){ ometa[i++] = mFullRange->get(x); diff --git a/src/include/ranges/type_map.h b/src/include/ranges/type_map.h index fb3c608..1088afd 100644 --- a/src/include/ranges/type_map.h +++ b/src/include/ranges/type_map.h @@ -7,6 +7,8 @@ #include #include +#include "allocator.h" + namespace MultiArrayTools { @@ -23,7 +25,7 @@ namespace MultiArrayTools }; template - inline void stringCat(std::vector& out, const std::vector& in) + inline void stringCat(vector& out, const vector& in) { //for(auto& x: in) { std::cout << x << std::endl; } const char* scp = reinterpret_cast(in.data()); @@ -31,20 +33,20 @@ namespace MultiArrayTools } template - inline size_t metaSize(const std::vector& in) + inline size_t metaSize(const vector& in) { return in.size() * sizeof(T); } template - inline void metaCat(std::vector& vec, const char* begin, size_t size) + inline void metaCat(vector& vec, const char* begin, size_t size) { const T* tp = reinterpret_cast( begin ); vec.insert(vec.end(), tp, tp + size / sizeof(T)); } template <> - inline void stringCat(std::vector& out, const std::vector& in) + inline void stringCat(vector& out, const vector& in) { //for(auto& x: in) { std::cout << x << std::endl; } std::string tmp = ""; @@ -56,7 +58,7 @@ namespace MultiArrayTools } template <> - inline size_t metaSize(const std::vector& in) + inline size_t metaSize(const vector& in) { size_t out = 0; for(auto& x: in){ @@ -66,7 +68,7 @@ namespace MultiArrayTools } template <> - inline void metaCat(std::vector& vec, const char* begin, size_t size) + inline void metaCat(vector& vec, const char* begin, size_t size) { std::string tmp(begin, size); @@ -92,10 +94,10 @@ namespace MultiArrayTools include_type(float,4) include_type(double,5) include_type(std::string,6) - include_type(std::vector,101) - include_type(std::vector,102) - include_type(std::vector,105) - include_type(std::vector,106) + include_type(vector,101) + include_type(vector,102) + include_type(vector,105) + include_type(vector,106) include_type(std::array,201) include_type(std::array,202) include_type(std::array,301) diff --git a/src/include/ranges/value_range.h b/src/include/ranges/value_range.h index 146b010..93b9a23 100644 --- a/src/include/ranges/value_range.h +++ b/src/include/ranges/value_range.h @@ -112,7 +112,7 @@ namespace MultiArrayTools virtual DataHeader dataHeader() const final; virtual std::string stringMeta(size_t pos) const final; - virtual std::vector data() const final; + virtual vector data() const final; U get(size_t pos) const; @@ -361,11 +361,11 @@ namespace MultiArrayTools } template - std::vector ValueRange::data() const + vector ValueRange::data() const { assert(0); DataHeader h = dataHeader(); - std::vector out; + vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); diff --git a/src/include/ranges/x_to_string.h b/src/include/ranges/x_to_string.h index 8d00dd4..7dfbc6e 100644 --- a/src/include/ranges/x_to_string.h +++ b/src/include/ranges/x_to_string.h @@ -27,7 +27,7 @@ namespace MultiArrayHelper inline std::string xToString(const DynamicMetaT& x); template - inline std::string xToString(const std::vector& x); + inline std::string xToString(const vector& x); template inline std::string xToString(const std::array& x); @@ -90,7 +90,7 @@ namespace MultiArrayHelper } template - inline std::string xToString(const std::vector& x) + inline std::string xToString(const vector& x) { std::string out = "[ "; for(auto& y: x){ diff --git a/src/include/slice.cc.h b/src/include/slice.cc.h index b777fca..919161a 100644 --- a/src/include/slice.cc.h +++ b/src/include/slice.cc.h @@ -115,7 +115,16 @@ namespace MultiArrayTools Slice::Slice(const std::shared_ptr&... ranges, T* data) : MutableMultiArrayBase(ranges...), mData(data) {} - + + template + Slice::Slice(const std::tuple...>& ranges, + T* data) : + MutableMultiArrayBase(ranges), + mData(data) + { + MAB::mInit = true; + } + template const T& Slice::operator[](const IType& i) const { diff --git a/src/include/slice.h b/src/include/slice.h index e727a46..32daf22 100644 --- a/src/include/slice.h +++ b/src/include/slice.h @@ -66,6 +66,8 @@ namespace MultiArrayTools DEFAULT_MEMBERS(Slice); + Slice(const std::tuple...>& ranges, + T* data = nullptr); Slice(const std::shared_ptr&... ranges, T* data = nullptr); virtual const T& operator[](const IType& i) const final; diff --git a/src/include/type_operations.h b/src/include/type_operations.h index efa35c6..564b83b 100644 --- a/src/include/type_operations.h +++ b/src/include/type_operations.h @@ -70,77 +70,77 @@ namespace MultiArrayTools getter(size_t i) : mPos(i) {} - inline T operator()(const std::vector& in) + inline T operator()(const vector& in) { return in[mPos]; } }; template - std::vector& operator+=(std::vector& a, const std::vector& b) + vector& operator+=(vector& a, const vector& b) { std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus()); return a; } template - std::vector& operator-=(std::vector& a, const std::vector& b) + vector& operator-=(vector& a, const vector& b) { std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::minus()); return a; } template - std::vector& operator*=(std::vector& a, const std::vector& b) + vector& operator*=(vector& a, const vector& b) { std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::multiplies()); return a; } template - std::vector& operator/=(std::vector& a, const std::vector& b) + vector& operator/=(vector& a, const vector& b) { std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::divides()); return a; } template - std::vector operator+(std::vector& a, const std::vector& b) + vector operator+(vector& a, const vector& b) { - std::vector out(a.size()); + vector out(a.size()); std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::plus()); return out; } template - std::vector operator-(std::vector& a, const std::vector& b) + vector operator-(vector& a, const vector& b) { - std::vector out(a.size()); + vector out(a.size()); std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::minus()); return out; } template - std::vector operator*(std::vector& a, const std::vector& b) + vector operator*(vector& a, const vector& b) { - std::vector out(a.size()); + vector out(a.size()); std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::multiplies()); return out; } template - std::vector operator/(std::vector& a, const std::vector& b) + vector operator/(vector& a, const vector& b) { - std::vector out(a.size()); + vector out(a.size()); std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::divides()); return out; } template - class OperationTemplate,OperationClass> : public OperationBase,OperationClass> + class OperationTemplate,OperationClass> : public OperationBase,OperationClass> { public: - typedef OperationBase,OperationClass> OB; + typedef OperationBase,OperationClass> OB; auto operator[](size_t i) -> Operation,OperationClass> @@ -154,46 +154,55 @@ namespace MultiArrayTools friend OperationClass; }; - template - inline std::array operator+(std::array& a, const std::array& b) + typedef struct v256 { double _x[4]; } v256; + + template + inline void xadd(double* o, const double* a, const double* b) { - std::array out; - for(size_t i = 0; i != N; ++i){ - out[i] = a[i] + b[i]; + //#pragma omp simd aligned(o, a, b: 16) + for(int i = 0; i < N; i++) { + o[i] = a[i] + b[i]; + } + } + + inline v256 operator+(const v256& a, const v256& b) + { + alignas(32) v256 out; + xadd<4>( reinterpret_cast(&out), reinterpret_cast(&a), + reinterpret_cast(&b) ); + return out; + } + /* + inline v256 operator-(const v256& a, const v256& b) + { + alignas(32) v256 out; +#pragma omp simd aligned(outp, ap, bp: 32) + for(int i = 0; i < IN; ++i){ + outp[i] = ap[i] - bp[i]; } return out; } - template - inline std::array operator-(std::array& a, const std::array& b) + inline v256 operator*(const v256& a, const v256& b) { - std::array out; - for(size_t i = 0; i != N; ++i){ - out[i] = a[i] - b[i]; + alignas(32) v256 out; +#pragma omp simd aligned(outp, ap, bp: 32) + for(int i = 0; i < IN; ++i){ + outp[i] = ap[i] * bp[i]; } return out; } - - template - inline std::array operator*(std::array& a, const std::array& b) + + inline v256 operator/(const v256& a, const v256& b) { - std::array out; - for(size_t i = 0; i != N; ++i){ - out[i] = a[i] * b[i]; + alignas(32) v256 out; +#pragma omp simd aligned(outp, ap, bp: 32) + for(int i = 0; i < IN; ++i){ + outp[i] = ap[i] / bp[i]; } return out; } - - template - inline std::array operator/(std::array& a, const std::array& b) - { - std::array out; - for(size_t i = 0; i != N; ++i){ - out[i] = a[i] / b[i]; - } - return out; - } - + */ } // namespace MultiArrayTools diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index c854af3..3cda525 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -9,6 +9,7 @@ #include "xfor/for_utils.h" #include "xfor/exttype.h" +#include "allocator.h" #include #define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \ @@ -16,7 +17,7 @@ namespace MultiArrayHelper { - + using namespace MultiArrayTools; // 'HIDDEN FOR' CLASS for nested for loops in contractions a.s.o. // (NO COUNTING OF MASTER POSITION !!!!!) @@ -152,7 +153,7 @@ namespace MultiArrayHelper typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType; ExtType mExt; - const std::vector* mSubSet; + const vector* mSubSet; mutable ExtType mRootSteps; @@ -169,10 +170,10 @@ namespace MultiArrayHelper SubExpr(const std::shared_ptr& indPtr, std::intptr_t siptr, - const std::vector* subset, Expr expr); + const vector* subset, Expr expr); SubExpr(const IndexClass* indPtr, std::intptr_t siptr, - const std::vector* subset, Expr expr); + const vector* subset, Expr expr); inline void operator()(size_t mlast, DExt last) const override final; @@ -650,7 +651,7 @@ namespace MultiArrayHelper template SubExpr::SubExpr(const std::shared_ptr& indPtr, std::intptr_t siptr, - const std::vector* subset, Expr expr) : + const vector* subset, Expr expr) : mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr), mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast( mIndPtr )) ) ), @@ -661,7 +662,7 @@ namespace MultiArrayHelper template SubExpr::SubExpr(const IndexClass* indPtr, std::intptr_t siptr, - const std::vector* subset, Expr expr) : + const vector* subset, Expr expr) : mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr), mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast( mIndPtr )) ) ), diff --git a/src/lib/map_range_factory_product_map.cc b/src/lib/map_range_factory_product_map.cc index 563ec74..28fbe39 100644 --- a/src/lib/map_range_factory_product_map.cc +++ b/src/lib/map_range_factory_product_map.cc @@ -3,5 +3,5 @@ namespace MultiArrayTools { - std::map,std::vector > MapRangeFactoryProductMap::mAleadyCreated; + std::map,vector > MapRangeFactoryProductMap::mAleadyCreated; } diff --git a/src/lib/ranges/anonymous_range.cc b/src/lib/ranges/anonymous_range.cc index 4b5a337..ae3ecb7 100644 --- a/src/lib/ranges/anonymous_range.cc +++ b/src/lib/ranges/anonymous_range.cc @@ -13,14 +13,14 @@ namespace MultiArrayTools } - std::map,std::vector > AnonymousRangeFactory::mAleadyCreated; + std::map,vector > AnonymousRangeFactory::mAleadyCreated; - AnonymousRangeFactory::AnonymousRangeFactory(const std::vector>& origs) + AnonymousRangeFactory::AnonymousRangeFactory(const vector>& origs) { mProd = std::shared_ptr( new AnonymousRange( origs ) ); } - std::shared_ptr AnonymousRangeFactory::checkIfCreated(const std::vector >& pvec) + std::shared_ptr AnonymousRangeFactory::checkIfCreated(const vector >& pvec) { std::shared_ptr out; bool check = false; @@ -40,7 +40,7 @@ namespace MultiArrayTools } } if(not check){ - std::vector app(pvec.size()); + vector app(pvec.size()); for(size_t i = 0; i != app.size(); ++i){ app[i] = reinterpret_cast( pvec[i].get() ); } @@ -108,10 +108,10 @@ namespace MultiArrayTools return out; } - std::vector AnonymousRange::data() const + vector AnonymousRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); for(auto& x: mOrig){ @@ -168,7 +168,7 @@ namespace MultiArrayTools return std::dynamic_pointer_cast(arf.create()); } - std::shared_ptr AnonymousRange::sreplace(const std::vector>& in, size_t num) const + std::shared_ptr AnonymousRange::sreplace(const vector>& in, size_t num) const { size_t nsize = 1; for(auto& x: in){ @@ -191,12 +191,12 @@ namespace MultiArrayTools return std::dynamic_pointer_cast(arf.create()); } - const std::vector >& AnonymousRange::orig() const + const vector >& AnonymousRange::orig() const { return mOrig; } - GenSingleRange::GenSingleRange(const std::vector>& origs) : + GenSingleRange::GenSingleRange(const vector>& origs) : RangeInterface(), mOrig(origs) { diff --git a/src/lib/ranges/multi_range_factory_product_map.cc b/src/lib/ranges/multi_range_factory_product_map.cc index 30da2dc..226ce7b 100644 --- a/src/lib/ranges/multi_range_factory_product_map.cc +++ b/src/lib/ranges/multi_range_factory_product_map.cc @@ -3,5 +3,5 @@ namespace MultiArrayTools { - std::map,std::vector > MultiRangeFactoryProductMap::mAleadyCreated; + std::map,vector > MultiRangeFactoryProductMap::mAleadyCreated; } diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index bfe422e..6f1d5eb 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -15,7 +15,7 @@ namespace MultiArrayTools template using STP = std::tuple...>; - typedef std::vector > RVEC; + typedef vector > RVEC; template inline bool compareSpaceTypes(const RVEC& rvec) @@ -127,7 +127,7 @@ namespace MultiArrayTools assert(0); } #define register_type(x) else if(x == h.metaType) { \ - std::vector::type> vd;\ + vector::type> vd;\ metaCat(vd, *dp, h.metaSize); \ out = std::make_shared::type, \ SpaceType::ANY> >(vd); } diff --git a/src/lib/ranges/range_types/classic_range.cc b/src/lib/ranges/range_types/classic_range.cc index db147d9..7fbd227 100644 --- a/src/lib/ranges/range_types/classic_range.cc +++ b/src/lib/ranges/range_types/classic_range.cc @@ -58,10 +58,10 @@ namespace MultiArrayTools return std::to_string(get(pos)); } - std::vector GenSingleRange::data() const + vector GenSingleRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); diff --git a/src/lib/ranges/range_types/null_range.cc b/src/lib/ranges/range_types/null_range.cc index 46ac26b..107d4b0 100644 --- a/src/lib/ranges/range_types/null_range.cc +++ b/src/lib/ranges/range_types/null_range.cc @@ -81,10 +81,10 @@ namespace MultiArrayTools return std::to_string(get(pos)); } - std::vector GenSingleRange::data() const + vector GenSingleRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); diff --git a/src/lib/ranges/range_types/space_range.cc b/src/lib/ranges/range_types/space_range.cc index ae4758e..b867f2a 100644 --- a/src/lib/ranges/range_types/space_range.cc +++ b/src/lib/ranges/range_types/space_range.cc @@ -64,10 +64,10 @@ namespace MultiArrayTools return std::to_string(get(pos)); } - std::vector GenSingleRange::data() const + vector GenSingleRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); diff --git a/src/lib/ranges/range_types/spin_range.cc b/src/lib/ranges/range_types/spin_range.cc index 8ba73f4..191ae2f 100644 --- a/src/lib/ranges/range_types/spin_range.cc +++ b/src/lib/ranges/range_types/spin_range.cc @@ -61,10 +61,10 @@ namespace MultiArrayTools return std::to_string(get(pos)); } - std::vector GenSingleRange::data() const + vector GenSingleRange::data() const { DataHeader h = dataHeader(); - std::vector out; + vector out; out.reserve(h.metaSize + sizeof(DataHeader)); char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); diff --git a/src/tests/ma_unit_test.cc b/src/tests/ma_unit_test.cc index 705c748..20847ee 100644 --- a/src/tests/ma_unit_test.cc +++ b/src/tests/ma_unit_test.cc @@ -15,7 +15,7 @@ namespace { template void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) { - std::vector tmp = ilist; + vector tmp = ilist; auto nptr = std::make_shared( tmp ); fptr = nptr; } @@ -50,7 +50,7 @@ namespace { std::shared_ptr rfbptr; std::shared_ptr srptr; - std::vector vv = { 3.141, 2.718, 1.618, 0.693, 0.577 }; + vector vv = { 3.141, 2.718, 1.618, 0.693, 0.577 }; }; @@ -91,7 +91,7 @@ namespace { std::shared_ptr sr3ptr; std::shared_ptr sr4ptr; std::shared_ptr mrptr; - std::vector vv = { 2.917, 9.436, 0.373, 7.192, 7.315, 1.536, 4.892, 0.280, + vector vv = { 2.917, 9.436, 0.373, 7.192, 7.315, 1.536, 4.892, 0.280, 8.870, 4.790, 8.215, 5.063, 1.530, 3.084, 1.609, 4.847, 8.175, 0.112, 6.712, 6.408, 1.959, 0.331, 4.209, 2.951 }; }; @@ -114,7 +114,7 @@ namespace { TEST_F(MATest_1Dim, ForLoop) { - std::vector v2 = { 0.693 , 2.718, 3.141, 1.618, 9.98 }; + vector v2 = { 0.693 , 2.718, 3.141, 1.618, 9.98 }; MultiArray ma(srptr, std::move( v2 ) ); size_t cnt = 0; for(auto el: ma){ diff --git a/src/tests/op_perf_test.cc b/src/tests/op_perf_test.cc index 62accee..90af492 100644 --- a/src/tests/op_perf_test.cc +++ b/src/tests/op_perf_test.cc @@ -5,6 +5,7 @@ #include #include "multi_array_header.h" +#include "conversions.h" #include #include @@ -32,15 +33,15 @@ namespace { template void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) { - std::vector tmp = ilist; + vector tmp = ilist; auto nptr = std::make_shared( tmp ); fptr = nptr; } template - void swapFactory(std::shared_ptr& fptr, std::vector& ilist) + void swapFactory(std::shared_ptr& fptr, vector& ilist) { - std::vector tmp = ilist; + vector tmp = ilist; auto nptr = std::make_shared( tmp ); fptr = nptr; } @@ -78,14 +79,14 @@ namespace { OpTest_Performance() { - std::vector initvec1(vs1); - cv1.resize(vs1); + vector initvec1(vs1); + cv1.resize(vs1); for(size_t i = 0; i != vs1; ++i){ initvec1[i] = i; cv1[i] = sqrt( static_cast(i)*0.53 ); } - std::vector initvec2(vs2); + vector initvec2(vs2); cv2.resize(vs2*vs1); for(size_t i = 0; i != vs2; ++i){ initvec2[i] = i; @@ -112,14 +113,14 @@ namespace { //const size_t vs2 = 1000; const size_t vs1 = 4000; const size_t vs2 = 2500; - + std::shared_ptr rfbptr; std::shared_ptr sr1ptr; std::shared_ptr sr2ptr; std::shared_ptr mrptr; - std::vector cv1; - std::vector cv2; + vector cv1; + vector cv2; }; #endif class OpTest_Spin @@ -132,12 +133,12 @@ namespace { typedef SpinRF SRF; typedef SpinRange SR; typedef MultiRangeFactory SR8F; - typedef SR8F::oType SR8; - - static const size_t os = 30; - static const size_t is = 65536; - static const size_t s = is*os; - + typedef SR8F::oType SR8; + + static const size_t os = 300; + static const size_t is = 65536; + static const size_t s = is*os; + OpTest_Spin() { data.resize(is); @@ -152,11 +153,11 @@ namespace { cr = std::dynamic_pointer_cast(cf.create()); } - void contract(); + void contract(); private: - std::vector data; + vector data; std::shared_ptr sr; std::shared_ptr cr; }; @@ -172,26 +173,27 @@ namespace { auto beta = MAT::getIndex(); auto gamma = MAT::getIndex(); auto delta = MAT::getIndex(); - auto deltap = MAT::getIndex(); + //auto deltap = MAT::getIndex(); + auto deltap = MAT::getIndex>(); auto mix = MAT::mkMIndex( alpha, beta, gamma, jj ); 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) += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); - //} + tcast(res1)(ii ,delta, deltap) += tcast(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 << std::endl; - std::vector vres(4*4*os); + vector vres(4*4*os); for(size_t d = 0; d != 4; ++d){ for(size_t p = 0; p != 4; ++p){ const size_t tidx = d*4 + p; vres[tidx] = 0.; } - } + } std::clock_t begin2 = std::clock(); for(size_t j = 0; j != os; ++j) { for(size_t i = 0; i != os; ++i){ @@ -232,7 +234,7 @@ namespace { assert( xround(res1.at(mkts(0,3,2))) == xround(vres[14]) ); assert( xround(res1.at(mkts(0,3,3))) == xround(vres[15]) ); - std::cout << "std::vector - for loop time: " << static_cast( end2 - begin2 ) / CLOCKS_PER_SEC + std::cout << "vector - for loop time: " << static_cast( end2 - begin2 ) / CLOCKS_PER_SEC << std::endl; std::cout << "ratio: " << static_cast( end - begin ) / static_cast( end2 - begin2 ) << std::endl; } @@ -256,7 +258,7 @@ namespace { std::cout << "MultiArray time: " << static_cast( end - begin ) / CLOCKS_PER_SEC << std::endl; - std::vector res2(vs1*vs2); + vector res2(vs1*vs2); std::clock_t begin2 = std::clock(); for(size_t i = 0; i != vs2; ++i){ @@ -266,7 +268,7 @@ namespace { } std::clock_t end2 = std::clock(); - std::cout << "std::vector - for loop time: " << static_cast( end2 - begin2 ) / CLOCKS_PER_SEC + std::cout << "vector - for loop time: " << static_cast( end2 - begin2 ) / CLOCKS_PER_SEC << std::endl; std::cout << "ratio: " << static_cast( end - begin ) / static_cast( end2 - begin2 ) << std::endl; diff --git a/src/tests/op_unit_test.cc b/src/tests/op_unit_test.cc index 4bd8bfb..350f964 100644 --- a/src/tests/op_unit_test.cc +++ b/src/tests/op_unit_test.cc @@ -31,15 +31,15 @@ namespace { template void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) { - std::vector tmp = ilist; + vector tmp = ilist; auto nptr = std::make_shared( tmp ); fptr = nptr; } template - void swapFactory(std::shared_ptr& fptr, std::vector& ilist) + void swapFactory(std::shared_ptr& fptr, vector& ilist) { - std::vector tmp = ilist; + vector tmp = ilist; auto nptr = std::make_shared( tmp ); fptr = nptr; } @@ -106,8 +106,8 @@ namespace { std::shared_ptr rfbptr; std::shared_ptr srptr; - std::vector v1 = { 2.917, 9.436, 0.373, 7.192 }; - std::vector v2 = { 8.870, 4.790, 8.215, 5.063 }; + vector v1 = { 2.917, 9.436, 0.373, 7.192 }; + vector v2 = { 8.870, 4.790, 8.215, 5.063 }; }; class OpTest_MDim : public ::testing::Test @@ -151,11 +151,11 @@ namespace { std::shared_ptr sr4ptr; std::shared_ptr mr1ptr; std::shared_ptr mr2ptr; - std::vector v1 = { 2.917, 9.436, 0.373 }; - std::vector v2 = { 8.870, 4.790 }; - std::vector v3 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 }; - std::vector v4 = { 1.470, 2.210 }; - std::vector v5 = { 30.932, -33.693, -26.205, -15.504, 21.227, 17.829, + vector v1 = { 2.917, 9.436, 0.373 }; + vector v2 = { 8.870, 4.790 }; + vector v3 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 }; + vector v4 = { 1.470, 2.210 }; + vector v5 = { 30.932, -33.693, -26.205, -15.504, 21.227, 17.829, -14.364, -1.868, -25.703, 13.836, 23.563, 41.339 }; }; @@ -184,10 +184,10 @@ namespace { std::shared_ptr sr2ptr; std::shared_ptr sr3ptr; - std::vector v1 = { 2.917, 9.436, 0.373, 0.353, 4.005, 1.070, + vector v1 = { 2.917, 9.436, 0.373, 0.353, 4.005, 1.070, -14.364, -1.868, -25.703, 13.836, 23.563, 41.339 }; - std::vector v2 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 }; + vector v2 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 }; }; @@ -222,7 +222,7 @@ namespace { std::shared_ptr sr1ptr; std::shared_ptr sr2ptr; std::shared_ptr mpr1ptr; - std::vector v1 = { -31.71, -77.16, -18.81, + vector v1 = { -31.71, -77.16, -18.81, -67.06, 72.31, -54.48, -50.91, -11.62, -59.57, -42.53, 80.41, 6.35 }; @@ -241,14 +241,14 @@ namespace { OpTest_Performance() { - std::vector initvec1(vs1); + vector initvec1(vs1); cv1.resize(vs1); for(size_t i = 0; i != vs1; ++i){ initvec1[i] = i; cv1[i] = sqrt( static_cast(i)*0.53 ); } - std::vector initvec2(vs2); + vector initvec2(vs2); cv2.resize(vs2*vs1); for(size_t i = 0; i != vs2; ++i){ initvec2[i] = i; @@ -277,8 +277,8 @@ namespace { std::shared_ptr sr2ptr; std::shared_ptr mrptr; - std::vector cv1; - std::vector cv2; + vector cv1; + vector cv2; }; class OpTest_Spin : public ::testing::Test @@ -303,7 +303,7 @@ namespace { sr = std::dynamic_pointer_cast(f.create()); } - std::vector data; + vector data; std::shared_ptr sr; }; @@ -337,8 +337,8 @@ namespace { std::shared_ptr sr1ptr; std::shared_ptr sr2ptr; - std::vector mv1; - std::vector mv2; + vector mv1; + vector mv2; double vcontract(size_t i) { @@ -458,7 +458,7 @@ namespace { res2(delta, deltap).par() += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(alpha).c(beta).c(gamma); - std::vector vres(4*4); + vector vres(4*4); std::clock_t begin2 = std::clock(); for(size_t d = 0; d != 4; ++d){ @@ -517,7 +517,7 @@ namespace { EXPECT_EQ( xround(res2.at(mkts(3,2))), xround(vres[14]) ); EXPECT_EQ( xround(res2.at(mkts(3,3))), xround(vres[15]) ); - std::cout << "std::vector - for loop time: " << static_cast( end2 - begin2 ) / CLOCKS_PER_SEC + std::cout << "vector - for loop time: " << static_cast( end2 - begin2 ) / CLOCKS_PER_SEC << std::endl; std::cout << "ratio: " << static_cast( end - begin ) / static_cast( end2 - begin2 ) << std::endl; } @@ -543,7 +543,7 @@ namespace { MultiArray ma1(sr1ptr, sr2ptr, sr3ptr, v1); MultiArray ma2(sr3ptr, sr2ptr, v2); - SubRangeFactory subf(sr2ptr, std::vector({0,2})); + SubRangeFactory subf(sr2ptr, vector({0,2})); auto subptr = MAT::createExplicit(subf); MultiArray res(sr3ptr,sr1ptr,0.); diff --git a/src/tests/ranges/anonymous_unit_test.cc b/src/tests/ranges/anonymous_unit_test.cc index b12065e..cba81cb 100644 --- a/src/tests/ranges/anonymous_unit_test.cc +++ b/src/tests/ranges/anonymous_unit_test.cc @@ -18,7 +18,7 @@ namespace { template void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) { - std::vector tmp = ilist; + vector tmp = ilist; auto nptr = std::make_shared( tmp ); fptr = nptr; } @@ -160,7 +160,7 @@ namespace { TEST_F(AnonymousTest, ToString1) { - std::vector vv = sr1ptr->data(); + vector vv = sr1ptr->data(); const char* dp = vv.data(); auto ff = createRangeFactory(&dp); auto ss = std::dynamic_pointer_cast( ff->create() ); @@ -183,9 +183,9 @@ namespace { auto sr = std::dynamic_pointer_cast( srf.create() ); auto nr = std::dynamic_pointer_cast( nrf.create() ); - std::vector cv = cr->data(); - std::vector sv = sr->data(); - std::vector nv = nr->data(); + vector cv = cr->data(); + vector sv = sr->data(); + vector nv = nr->data(); const char* cp = cv.data(); const char* sp = sv.data(); const char* np = nv.data(); @@ -212,7 +212,7 @@ namespace { TEST_F(AnonymousTest, ToStringMulti) { - std::vector vv = m3rptr->data(); + vector vv = m3rptr->data(); const char* dp = vv.data(); auto ff2 = std::dynamic_pointer_cast( createRangeFactory(&dp) ); @@ -235,7 +235,7 @@ namespace { { AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr); auto ar = std::dynamic_pointer_cast( arf2.create() ); - std::vector vv = ar->data(); + vector vv = ar->data(); const char* dp = vv.data(); auto ff2 = std::dynamic_pointer_cast( createRangeFactory(&dp) ); diff --git a/src/tests/ranges/index_unit_test.cc b/src/tests/ranges/index_unit_test.cc index d4289f6..5da0265 100644 --- a/src/tests/ranges/index_unit_test.cc +++ b/src/tests/ranges/index_unit_test.cc @@ -17,7 +17,7 @@ namespace { template void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) { - std::vector tmp = ilist; + vector tmp = ilist; auto nptr = std::make_shared( tmp ); fptr = nptr; }