diff --git a/CMakeLists.txt b/CMakeLists.txt index ba65885..805c8e3 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 -g -Wpedantic -Ofast -march=native -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 new file mode 100644 index 0000000..60a3b53 --- /dev/null +++ b/src/include/conversions.h @@ -0,0 +1,122 @@ + +#ifndef __ma_conversions_h__ +#define __ma_conversions_h__ + +#include "multi_array.h" +#include "slice.h" + +namespace MultiArrayTools +{ + + namespace ConversionSizes + { + template + struct OrigSize + { + template + struct FromTo + { + static void check() { static_assert( not N % (sizeof(T) / sizeof(C)), "conversion does not fit" ); } + static constexpr size_t SIZE = N * sizeof(T) / sizeof(C); + }; + }; + + template <> + struct OrigSize<-1> + { + template + struct FromTo + { + static void check() {} + static constexpr size_t SIZE = -1; + }; + }; + } + + namespace + { + template + using SC = typename ConversionSizes::OrigSize::template FromTo; + + template + using SCR = SC; + + template + 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..939657c 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -29,7 +29,7 @@ namespace MultiArrayTools template inline void OpExpr::operator()(size_t mlast, - ExtType last) const + ExtType last) { constexpr size_t NEXT = Op::SIZE; const ExtType nxpos = last; @@ -42,7 +42,7 @@ namespace MultiArrayTools } template - inline void OpExpr::operator()(size_t mlast) const + inline void OpExpr::operator()(size_t mlast) { const ExtType last; constexpr size_t NEXT = Op::SIZE; @@ -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..129dd10 100644 --- a/src/include/map_range.h +++ b/src/include/map_range.h @@ -66,8 +66,8 @@ namespace MultiArrayTools OpExpr(const MapF& mapf, const IndexPack& ipack, const std::shared_ptr& oind, size_t step, Expr ex); - inline void operator()(size_t mlast, ExtType last) const; - inline void operator()(size_t mlast = 0) const; + inline void operator()(size_t mlast, ExtType last); + inline void operator()(size_t mlast = 0); auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; @@ -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 f6fcbdf..0549101 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/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 221ee33..fb42803 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -120,18 +120,25 @@ namespace MultiArrayTools /***************************************** * OperationMaster::AssignmentExpr * *****************************************/ - + /* template OperationMaster::AssignmentExpr:: AssignmentExpr(OperationMaster& m, const OpClass& sec) : mM(m), mSec(sec) {} - + */ + template + OperationMaster::AssignmentExpr:: + AssignmentExpr(T* dataPtr, const OpClass& sec) : + mSec(sec), mDataPtr(dataPtr) {} + template inline void OperationMaster::AssignmentExpr:: - operator()(size_t start, ExtType last) const + operator()(size_t start, ExtType last) { //VCHECK(mSec.template get(last)); - mM.set(start, mSec.template get(last) ); + //mM.set(start, mSec.template get(last) ); + mDataPtr[start] = mSec.template get(last); + //AOp::sapply(mDataPtr[start], mSec.template get(last)); } template @@ -141,7 +148,30 @@ namespace MultiArrayTools { return mSec.rootSteps(iPtrNum); } + + template + OperationMaster::AddExpr:: + AddExpr(T* dataPtr, const OpClass& sec) : + mSec(sec), mDataPtr(dataPtr) {} + template + inline void OperationMaster::AddExpr:: + operator()(size_t start, ExtType last) + { + //VCHECK(mSec.template get(last)); + //mM.set(start, mSec.template get(last) ); + mDataPtr[start] += mSec.template get(last); + //AOp::sapply(mDataPtr[start], mSec.template get(last)); + } + + template + typename OperationMaster::AddExpr::ExtType + OperationMaster::AddExpr:: + rootSteps(std::intptr_t iPtrNum) const + { + return mSec.rootSteps(iPtrNum); + } + /************************* * OperationMaster * @@ -170,15 +200,17 @@ namespace MultiArrayTools template void OperationMaster::performAssignment(std::intptr_t blockIndexNum) { + /* AssignmentExpr ae(*this, mSecond); // Expression to be executed within loop if(mDoParallel){ - const auto ploop = mIndex.pifor( 1, mSecond.loop(ae) ); + auto ploop = mIndex.pifor( 1, mSecond.loop(ae) ); ploop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions } else { - const auto loop = mIndex.ifor( 1, mSecond.loop(ae) ); + auto loop = mIndex.ifor( 1, mSecond.loop(ae) ); loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions } + */ } template @@ -197,11 +229,12 @@ namespace MultiArrayTools ConstOperationRoot(const MultiArrayBase& ma, const std::shared_ptr&... indices) : mDataPtr(ma.data()), + mOrigDataPtr(ma.data()), mIndex( ma.begin() ) { //VCHECK(ma.data()); mIndex(indices...); - mOff = mIndex.pos(); + //mOff = mIndex.pos(); } template @@ -209,35 +242,37 @@ namespace MultiArrayTools ConstOperationRoot(std::shared_ptr > maptr, const std::shared_ptr&... indices) : mDataPtr(maptr->data()), + mOrigDataPtr(maptr->data()), mIndex(maptr->begin()), mMaPtr(maptr) { mIndex(indices...); - mOff = mIndex.pos(); + //mOff = mIndex.pos(); } template ConstOperationRoot:: ConstOperationRoot(const T* data, const IndexType& ind) : mDataPtr(data), + mOrigDataPtr(data), mIndex( ind ) { - mOff = mIndex.pos(); + //mOff = mIndex.pos(); } template template - inline T ConstOperationRoot::get(ET pos) const + inline const T& ConstOperationRoot::get(ET pos) const { - return mDataPtr[pos.val()+mOff]; + return mDataPtr[pos.val()/*+mOff*/]; } template template - inline const ConstOperationRoot& ConstOperationRoot::set(ET pos) const + inline ConstOperationRoot& ConstOperationRoot::set(ET pos) { mIndex = pos.val(); - mOff = mIndex.pos(); + mDataPtr = mOrigDataPtr + mIndex.pos(); return *this; } @@ -278,7 +313,7 @@ namespace MultiArrayTools template template - inline const StaticCast& StaticCast::set(ET pos) const + inline StaticCast& StaticCast::set(ET pos) { mOp.set(pos); return *this; @@ -322,7 +357,7 @@ namespace MultiArrayTools template template - inline const MetaOperationRoot& MetaOperationRoot::set(ET pos) const + inline MetaOperationRoot& MetaOperationRoot::set(ET pos) { assert(0); //(*mIndex) = pos.val(); @@ -353,38 +388,65 @@ namespace MultiArrayTools OperationRoot(MutableMultiArrayBase& ma, const std::shared_ptr&... indices) : mDataPtr(ma.data()), + mOrigDataPtr(ma.data()), mIndex( ma.begin() ) { mIndex(indices...); - mOff = mIndex.pos(); + //mOff = mIndex.pos(); } template OperationRoot:: OperationRoot(T* data, const IndexType& ind) : mDataPtr(data), + mOrigDataPtr(data), mIndex( ind ) { - mOff = mIndex.pos(); + //mOff = mIndex.pos(); } template template - OperationMaster,OpClass,Ranges...> OperationRoot::operator=(const OpClass& in) + OperationRoot& OperationRoot::operator=(const OpClass& in) + //OperationMaster,OpClass,Ranges...> OperationRoot::operator=(const OpClass& in) { - return OperationMaster,OpClass,Ranges...>(mDataPtr, in, mIndex, mDoParallel); + typename OperationMaster,OpClass,Ranges...>::AssignmentExpr ae(mDataPtr, in); + // Expression to be executed within loop + if(mDoParallel){ + auto ploop = mIndex.pifor( 1, in.loop(ae) ); + ploop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions + } + else { + auto loop = mIndex.ifor( 1, in.loop(ae) ); + loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions + } + return *this; + //return OperationMaster,OpClass,Ranges...>(mDataPtr, in, mIndex, mDoParallel); } template template - OperationMaster,OpClass,Ranges...> OperationRoot::operator+=(const OpClass& in) + OperationRoot& OperationRoot::operator+=(const OpClass& in) + //OperationMaster,OpClass,Ranges...> OperationRoot::operator+=(const OpClass& in) { - return OperationMaster,OpClass,Ranges...>(mDataPtr, in, mIndex, mDoParallel); + typename OperationMaster,OpClass,Ranges...>::AddExpr ae(mDataPtr, in); + // Expression to be executed within loop + if(mDoParallel){ + auto ploop = mIndex.pifor( 1, in.loop(ae) ); + ploop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions + } + else { + auto loop = mIndex.ifor( 1, in.loop(ae) ); + loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions + } + return *this; + //return OperationMaster,OpClass,Ranges...>(mDataPtr, in, mIndex, mDoParallel); } template - OperationMaster,OperationRoot,Ranges...> - OperationRoot::operator=(const OperationRoot& in) + OperationRoot& OperationRoot::operator=(const OperationRoot& in) + //OperationMaster,OperationRoot,Ranges...> + //OperationRoot::operator=(const OperationRoot& in) { return operator= >(in); } @@ -398,17 +460,17 @@ namespace MultiArrayTools template template - inline T OperationRoot::get(ET pos) const + inline T& OperationRoot::get(ET pos) const { - return mDataPtr[pos.val()+mOff]; + return mDataPtr[pos.val()/*+mOff*/]; } template template - inline const OperationRoot& OperationRoot::set(ET pos) const + inline OperationRoot& OperationRoot::set(ET pos) { mIndex = pos.val(); - mOff = mIndex.pos(); + mDataPtr = mOrigDataPtr + mIndex.pos(); return *this; } @@ -429,7 +491,8 @@ namespace MultiArrayTools template T* OperationRoot::data() const { - return mDataPtr + mIndex().pos(); + auto i = mIndex; + return mDataPtr + i().pos(); } template @@ -452,14 +515,14 @@ namespace MultiArrayTools template template - inline T OperationValue::get(ET pos) const + inline const T& OperationValue::get(ET pos) const { return mVal; } template template - inline const OperationValue& OperationValue::set(ET pos) const + inline OperationValue& OperationValue::set(ET pos) { return *this; } @@ -509,7 +572,7 @@ namespace MultiArrayTools template template - inline const Operation& Operation::set(ET pos) const + inline Operation& Operation::set(ET pos) { PackNum::setOpPos(mOps,pos); return *this; @@ -543,14 +606,15 @@ namespace MultiArrayTools // forward loop !!!! template template - inline T Contraction::get(ET pos) const + inline auto Contraction::get(ET pos) const + -> decltype(mOp.template get(pos)) { return mOp.template get(pos); } template template - inline const Contraction& Contraction::set(ET pos) const + inline Contraction& Contraction::set(ET pos) { mOp.set(pos); return *this; @@ -597,7 +661,7 @@ namespace MultiArrayTools template template - inline const SliceContraction& SliceContraction::set(ET pos) const + inline SliceContraction& SliceContraction::set(ET pos) { mOp.set(pos); return *this; diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index c8f1734..92e96fb 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -95,9 +95,9 @@ namespace MultiArrayTools template struct SelfIdentity { - static inline T apply(const T& a, const T& b) + static inline T& sapply(T& a, T b) { - return b; + return a = b; } }; @@ -111,27 +111,57 @@ namespace MultiArrayTools private: AssignmentExpr() = default; - OperationMaster& mM; - const OpClass& mSec; - + //OperationMaster mM; + OpClass mSec; + T* mDataPtr; + public: static constexpr size_t LAYER = 0; static constexpr size_t SIZE = OpClass::SIZE; typedef decltype(mSec.rootSteps()) ExtType; - AssignmentExpr(OperationMaster& m, const OpClass& sec); + //AssignmentExpr(OperationMaster& m, const OpClass& sec); + AssignmentExpr(T* dataPtr, const OpClass& sec); AssignmentExpr(const AssignmentExpr& in) = default; AssignmentExpr(AssignmentExpr&& in) = default; - inline void operator()(size_t start = 0) const; - inline void operator()(size_t start, ExtType last) const; + inline void operator()(size_t start = 0); + inline void operator()(size_t start, ExtType last); auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; }; - + + class AddExpr + { + private: + AddExpr() = default; + + //OperationMaster mM; + OpClass mSec; + T* mDataPtr; + + public: + + static constexpr size_t LAYER = 0; + static constexpr size_t SIZE = OpClass::SIZE; + typedef decltype(mSec.rootSteps()) ExtType; + + //AssignmentExpr(OperationMaster& m, const OpClass& sec); + AddExpr(T* dataPtr, const OpClass& sec); + + AddExpr(const AddExpr& in) = default; + AddExpr(AddExpr&& in) = default; + + inline void operator()(size_t start = 0); + inline void operator()(size_t start, ExtType last); + + auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; + + }; + typedef T value_type; //typedef OperationBase OB; typedef ContainerRange CRange; @@ -144,7 +174,7 @@ namespace MultiArrayTools OperationMaster(T* data, const OpClass& second, IndexType& index, bool doParallel = false); - inline void set(size_t pos, T val) { mDataPtr[pos] = AOp::apply(mDataPtr[pos],val); } + inline void set(size_t pos, T val) { AOp::sapply(mDataPtr[pos],val); } //inline void add(size_t pos, T val) { mDataPtr[pos] += val; } inline T get(size_t pos) const; @@ -171,6 +201,7 @@ namespace MultiArrayTools typedef ContainerIndex IndexType; static constexpr size_t SIZE = 1; + static constexpr bool CONT = true; ConstOperationRoot(const MultiArrayBase& ma, const std::shared_ptr&... indices); @@ -181,10 +212,10 @@ namespace MultiArrayTools ConstOperationRoot(const T* data, const IndexType& ind); template - inline T get(ET pos) const; + inline const T& get(ET pos) const; template - inline const ConstOperationRoot& set(ET pos) const; + inline ConstOperationRoot& set(ET pos); MExt rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype @@ -197,8 +228,9 @@ namespace MultiArrayTools //MultiArrayBase const& mArrayRef; const T* mDataPtr; - mutable IndexType mIndex; - mutable size_t mOff = 0; + const T* mOrigDataPtr; + IndexType mIndex; + //size_t mOff = 0; std::shared_ptr > mMaPtr; // never remove this ptr, otherwise we lose temporary container instances! }; @@ -206,7 +238,7 @@ namespace MultiArrayTools class StaticCast : public OperationTemplate > { private: - const Op& mOp; + Op mOp; public: @@ -216,6 +248,7 @@ namespace MultiArrayTools typedef typename Op::IndexType IndexType; static constexpr size_t SIZE = Op::SIZE; + static constexpr bool CONT = false; StaticCast(const Op& op); @@ -223,7 +256,7 @@ namespace MultiArrayTools inline T get(ET pos) const; template - inline const StaticCast& set(ET pos) const; + inline StaticCast& set(ET pos); auto rootSteps(std::intptr_t iPtrNum = 0) const -> decltype(mOp.rootSteps(iPtrNum)); @@ -250,14 +283,15 @@ namespace MultiArrayTools typedef OperationBase > OT; static constexpr size_t SIZE = 1; - + static constexpr bool CONT = false; + MetaOperationRoot(const std::shared_ptr& ind); template inline value_type get(ET pos) const; template - inline const MetaOperationRoot& set(ET pos) const; + inline MetaOperationRoot& set(ET pos); MExt rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype @@ -283,12 +317,13 @@ namespace MultiArrayTools typedef ContainerIndex IndexType; static constexpr size_t SIZE = 1; + static constexpr bool CONT = true; OperationRoot(MutableMultiArrayBase& ma, const std::shared_ptr&... indices); OperationRoot(T* data, const IndexType& ind); - + /* template OperationMaster,OpClass,Ranges...> operator=(const OpClass& in); @@ -296,14 +331,23 @@ namespace MultiArrayTools OperationMaster,OpClass,Ranges...> operator+=(const OpClass& in); OperationMaster,OperationRoot,Ranges...> operator=(const OperationRoot& in); + */ + template + OperationRoot& operator=(const OpClass& in); + + template + OperationRoot& operator+=(const OpClass& in); + + OperationRoot& operator=(const OperationRoot& in); + OperationRoot& par(); template - inline T get(ET pos) const; + inline T& get(ET pos) const; template - inline const OperationRoot& set(ET pos) const; + inline OperationRoot& set(ET pos); MExt rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype @@ -320,8 +364,9 @@ namespace MultiArrayTools //MutableMultiArrayBase& mArrayRef; T* mDataPtr; - mutable IndexType mIndex; - mutable size_t mOff = 0; + T* mOrigDataPtr; + IndexType mIndex; + //size_t mOff = 0; bool mDoParallel = false; }; @@ -335,14 +380,15 @@ namespace MultiArrayTools typedef ContainerIndex IndexType; static constexpr size_t SIZE = 1; + static constexpr bool CONT = true; OperationValue(const T& val); template - inline T get(ET pos) const; + inline const T& get(ET pos) const; template - inline const OperationValue& set(ET pos) const; + inline OperationValue& set(ET pos); MExt rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype @@ -404,6 +450,7 @@ namespace MultiArrayTools static constexpr size_t SIZE = RootSum::SIZE; static constexpr bool FISSTATIC = OpFunction::FISSTATIC; + static constexpr bool CONT = false; private: std::tuple mOps; @@ -419,7 +466,7 @@ namespace MultiArrayTools inline T get(ET pos) const; template - inline const Operation& set(ET pos) const; + inline Operation& set(ET pos); auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype -> decltype(PackNum::mkSteps(iPtrNum, mOps)); @@ -463,7 +510,6 @@ namespace MultiArrayTools return OpMaker::mkOperation(f, ops...); } - template class Contraction : public OperationTemplate > @@ -474,10 +520,11 @@ namespace MultiArrayTools typedef OperationBase > OT; static constexpr size_t SIZE = Op::SIZE; - + static constexpr bool CONT = Op::CONT; + private: - const Op& mOp; + Op mOp; std::shared_ptr mInd; public: @@ -486,10 +533,11 @@ namespace MultiArrayTools Contraction(const Op& op, std::shared_ptr ind); template - inline T get(ET pos) const; + inline auto get(ET pos) const + -> decltype(mOp.template get(pos)); template - inline const Contraction& set(ET pos) const; + inline Contraction& set(ET pos); auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype -> decltype(mOp.rootSteps(iPtrNum)); @@ -510,10 +558,11 @@ namespace MultiArrayTools typedef OperationTemplate > OT; static constexpr size_t SIZE = Op::SIZE; - + static constexpr bool CONT = false; + private: - const Op& mOp; + mutable Op mOp; mutable std::shared_ptr > mCont; mutable OperationRoot mTarOp; @@ -526,7 +575,7 @@ namespace MultiArrayTools inline const value_type& get(ET pos) const; template - inline const SliceContraction& set(ET pos) const; + inline SliceContraction& set(ET pos); auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype -> decltype(mOp.rootSteps(iPtrNum)); diff --git a/src/include/pack_num.h b/src/include/pack_num.h index d9bf56e..d369b17 100644 --- a/src/include/pack_num.h +++ b/src/include/pack_num.h @@ -71,7 +71,7 @@ namespace MultiArrayHelper } template - static inline T mkOpExpr(std::shared_ptr f, const ETuple& pos, const OpTuple& ops, const Args&... args) + static inline T mkOpExpr(std::shared_ptr f, const ETuple& pos, const OpTuple& ops, Args... args) { typedef typename std::remove_reference(ops))>::type NextOpType; static_assert(LAST > NextOpType::SIZE, "inconsistent array positions"); @@ -116,7 +116,7 @@ namespace MultiArrayHelper } template - static inline void setOpPos(const OpTuple& ot, const ETuple& et) + static inline void setOpPos(OpTuple& ot, const ETuple& et) { typedef typename std::remove_reference(ot))>::type NextOpType; static_assert(LAST > NextOpType::SIZE, "inconsistent array positions"); @@ -203,7 +203,7 @@ namespace MultiArrayHelper } template - static inline void setOpPos(const OpTuple& ot, const ETuple& et) + static inline void setOpPos(OpTuple& ot, const ETuple& et) { typedef typename std::remove_reference(et))>::type NextOpType; static_assert(LAST > NextOpType::SIZE, "inconsistent array positions"); diff --git a/src/include/ranges/anonymous_range.h b/src/include/ranges/anonymous_range.h index 4cfb980..78ad36c 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 @@ -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,15 +45,15 @@ 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; }; 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; @@ -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; @@ -105,21 +105,21 @@ 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 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()){ @@ -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/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 3a65fea..ee4ae3c 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; @@ -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; @@ -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..a7db938 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,20 +34,20 @@ 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; 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; @@ -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..8235ff4 100644 --- a/src/include/ranges/range_types/space_range.h +++ b/src/include/ranges/range_types/space_range.h @@ -11,35 +11,35 @@ 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; 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; @@ -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..d720f94 100644 --- a/src/include/ranges/range_types/spin_range.h +++ b/src/include/ranges/range_types/spin_range.h @@ -12,35 +12,35 @@ 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; 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; @@ -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..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 { @@ -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/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 1affcaf..dd88c27 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,32 +84,31 @@ 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 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]) @@ -186,17 +185,45 @@ namespace MultiArrayTools } }; + + 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 + 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 SingleRange : public RangeInterface > + 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; @@ -205,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; @@ -215,25 +242,41 @@ 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 bool HASMETACONT = true; + 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 = CheckDefault::HASMETACONT; protected: - SingleRange() = delete; - SingleRange(const SingleRange& in) = delete; + GenSingleRange() = delete; + GenSingleRange(const GenSingleRange& in) = delete; - SingleRange(const std::vector& space); + GenSingleRange(const vector& space); - std::vector mSpace; + vector mSpace; //std::map mMSpace; MetaMap mMSpace; }; + template + using SingleRange = GenSingleRange; + + template + using SingleIndex = GenSingleIndex; + + template + using SingleRangeFactory = GenSingleRangeFactory; + } /* ========================= * @@ -243,7 +286,7 @@ namespace MultiArrayTools namespace MultiArrayTools { /****************** - * SingleIndex * + * GenSingleIndex * ******************/ template @@ -278,134 +321,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 +458,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 +490,14 @@ namespace MultiArrayTools * SingleRange * ********************/ - template - SingleRangeFactory::SingleRangeFactory(const std::vector& space) + template + GenSingleRangeFactory::GenSingleRangeFactory(const 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 +507,9 @@ namespace MultiArrayTools * SingleRange * ********************/ - template - SingleRange::SingleRange(const std::vector& space) : - RangeInterface >(), + template + GenSingleRange::GenSingleRange(const vector& space) : + RangeInterface >(), mSpace(space), mMSpace(mSpace) { //for(size_t i = 0; i != mSpace.size(); ++i){ @@ -474,53 +517,65 @@ 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 + inline size_t getStatSizeOrDyn(size_t size) { - return mSpace.size(); + return SIZE; } - template - size_t SingleRange::dim() const + template <> + inline size_t getStatSizeOrDyn<-1>(size_t size) + { + return size; + } + + template + size_t GenSingleRange::size() const + { + return getStatSizeOrDyn(mSpace.size()); + } + + 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 + 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)); @@ -530,8 +585,8 @@ namespace MultiArrayTools return out; } - template - DataHeader SingleRange::dataHeader() const + template + DataHeader GenSingleRange::dataHeader() const { DataHeader h; h.spaceType = static_cast( TYPE ); @@ -541,19 +596,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/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 fa4d263..cab044a 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 6870dac..d40d68e 100644 --- a/src/include/type_operations.h +++ b/src/include/type_operations.h @@ -70,24 +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 + vector& operator-=(vector& a, const vector& b) + { + std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::minus()); + return a; + } + + template + vector& operator*=(vector& a, const vector& b) + { + std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::multiplies()); + return a; + } + + template + vector& operator/=(vector& a, const vector& b) + { + std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::divides()); + return a; + } + + template + vector operator+(vector& a, const vector& b) + { + vector out(a.size()); + std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::plus()); + return out; + } + + template + vector operator-(vector& a, const vector& b) + { + vector out(a.size()); + std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::minus()); + return out; + } + + template + vector operator*(vector& a, const vector& b) + { + vector out(a.size()); + std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::multiplies()); + return out; + } + + template + vector operator/(vector& a, const vector& b) + { + 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> @@ -101,28 +154,74 @@ namespace MultiArrayTools friend OperationClass; }; - inline std::array& operator+=(std::array& a, const std::array& b) + struct v256 { - std::get<0>(a) += std::get<0>(b); - std::get<1>(a) += std::get<1>(b); - return a; + alignas(32) double _x[4]; + }; + + template + inline void xadd(double* o, const double* a, const double* b) + { +#pragma omp simd aligned(o, a, b: 32) + for(int i = 0; i < N; i++) { + o[i] = a[i] + b[i]; + } + } + + template + inline void xsadd(double* o, const double* a) + { +#pragma omp simd aligned(o, a: 32) + for(int i = 0; i < N; i++) { + o[i] += a[i]; + } + } + + inline v256 operator+(const v256& a, const v256& b) + { + v256 o; + xadd<4>( o._x, a._x, b._x ); + return o; + } + + inline v256& operator+=(v256& o, const v256& a) + { + //xsadd<4>( reinterpret_cast(&o), reinterpret_cast(&a) ); + xsadd<4>( o._x, a._x ); + return o; + } +/* + inline v256 operator-(const v256& a, const v256& b) + { + 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; + } + + inline v256 operator*(const v256& a, const v256& b) + { + 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; } - inline std::array& operator+=(std::array& a, const std::array& b) + inline v256 operator/(const v256& a, const v256& b) { - std::get<0>(a) += std::get<0>(b); - std::get<1>(a) += std::get<1>(b); - std::get<2>(a) += std::get<2>(b); - return a; + 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; } + */ - inline std::tuple& operator+=(std::tuple& a, const std::tuple& b) - { - std::get<0>(a) += std::get<0>(b); - std::get<1>(a) += std::get<1>(b); - std::get<2>(a) += std::get<2>(b); - return a; - } } // namespace MultiArrayTools diff --git a/src/include/xfor/exttype.h b/src/include/xfor/exttype.h index 65718b3..ffaccf2 100644 --- a/src/include/xfor/exttype.h +++ b/src/include/xfor/exttype.h @@ -36,7 +36,7 @@ namespace MultiArrayHelper template inline MExt(const std::array& arr); - inline size_t val() const; + inline const size_t& val() const; inline const X& next() const; inline MExt operator+(const MExt& in) const; @@ -76,7 +76,7 @@ namespace MultiArrayHelper template inline MExt(const std::array& arr); - inline size_t val() const; + inline const size_t& val() const; inline size_t next() const { return 0; } inline MExt operator+(const MExt& in) const; @@ -151,7 +151,7 @@ namespace MultiArrayHelper mExt(y.val()), mNext(y.next(), z) {} template - inline size_t MExt::val() const + inline const size_t& MExt::val() const { return mExt; } @@ -196,7 +196,7 @@ namespace MultiArrayHelper mExt(std::get(arr)) {} //template <> - inline size_t MExt::val() const + inline const size_t& MExt::val() const { return mExt; } diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index c854af3..7af5458 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 !!!!!) @@ -34,8 +35,8 @@ namespace MultiArrayHelper ExpressionBase& operator=(const ExpressionBase& in) = default; ExpressionBase& operator=(ExpressionBase&& in) = default; - virtual void operator()(size_t mlast, DExt last) const = 0; - virtual void operator()(size_t mlast = 0) const = 0; + virtual void operator()(size_t mlast, DExt last) = 0; + virtual void operator()(size_t mlast = 0) = 0; virtual DExt dRootSteps(std::intptr_t iPtrNum = 0) const = 0; virtual DExt dExtension() const = 0; @@ -126,9 +127,9 @@ namespace MultiArrayHelper Expr expr); - inline void operator()(size_t mlast, DExt last) const override final; - inline void operator()(size_t mlast, ExtType last) const; - inline void operator()(size_t mlast = 0) const override final; + inline void operator()(size_t mlast, DExt last) override final; + inline void operator()(size_t mlast, ExtType last); + inline void operator()(size_t mlast = 0) override final; DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; DExt dExtension() const override final; @@ -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,15 +170,15 @@ 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; - inline void operator()(size_t mlast, ExtType last) const; - inline void operator()(size_t mlast = 0) const override final; + inline void operator()(size_t mlast, DExt last) override final; + inline void operator()(size_t mlast, ExtType last) ; + inline void operator()(size_t mlast = 0) override final; DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; DExt dExtension() const override final; @@ -223,9 +224,9 @@ namespace MultiArrayHelper For(const IndexClass* indPtr, size_t step, Expr expr); - inline void operator()(size_t mlast, DExt last) const override final; - inline void operator()(size_t mlast, ExtType last) const; - inline void operator()(size_t mlast = 0) const override final; + inline void operator()(size_t mlast, DExt last) override final; + inline void operator()(size_t mlast, ExtType last) ; + inline void operator()(size_t mlast = 0) override final; PFor parallel() const; @@ -271,9 +272,9 @@ namespace MultiArrayHelper PFor(const IndexClass* indPtr, size_t step, Expr expr); - inline void operator()(size_t mlast, DExt last) const override final; - inline void operator()(size_t mlast, ExtType last) const; - inline void operator()(size_t mlast = 0) const override final; + inline void operator()(size_t mlast, DExt last) override final; + inline void operator()(size_t mlast, ExtType last) ; + inline void operator()(size_t mlast = 0) override final; DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; DExt dExtension() const override final; @@ -310,8 +311,8 @@ namespace MultiArrayHelper template DynamicExpression(Expr ex) : mNext( std::make_shared(ex) ) {} - inline void operator()(size_t mlast, DExt last) const override final; - inline void operator()(size_t mlast = 0) const override final; + inline void operator()(size_t mlast, DExt last) override final; + inline void operator()(size_t mlast = 0) override final; inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; inline DExt dExtension() const override final; @@ -344,9 +345,9 @@ namespace MultiArrayHelper ExpressionHolder(DynamicExpression expr); - inline void operator()(size_t mlast, DExt last) const override final; - inline void operator()(size_t mlast, ExtType last) const; - inline void operator()(size_t mlast = 0) const override final; + inline void operator()(size_t mlast, DExt last) override final; + inline void operator()(size_t mlast, ExtType last) ; + inline void operator()(size_t mlast = 0) override final; DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; DExt dExtension() const override final; @@ -390,14 +391,14 @@ namespace MultiArrayHelper } template - inline void For::operator()(size_t mlast, DExt last) const + inline void For::operator()(size_t mlast, DExt last) { operator()(mlast, *reinterpret_cast(last.first)); } template inline void For::operator()(size_t mlast, - ExtType last) const + ExtType last) { typedef typename IndexClass::RangeType RangeType; for(size_t pos = 0u; pos != ForBound::template bound(mMax); ++pos){ @@ -410,7 +411,7 @@ namespace MultiArrayHelper } template - inline void For::operator()(size_t mlast) const + inline void For::operator()(size_t mlast) { typedef typename IndexClass::RangeType RangeType; const ExtType last; @@ -483,14 +484,14 @@ namespace MultiArrayHelper } template - inline void PFor::operator()(size_t mlast, DExt last) const + inline void PFor::operator()(size_t mlast, DExt last) { operator()(mlast, *reinterpret_cast(last.first)); } template inline void PFor::operator()(size_t mlast, - ExtType last) const + ExtType last) { CHECK; typedef typename IndexClass::RangeType RangeType; @@ -510,7 +511,7 @@ namespace MultiArrayHelper } template - inline void PFor::operator()(size_t mlast) const + inline void PFor::operator()(size_t mlast) { CHECK; typedef typename IndexClass::RangeType RangeType; @@ -587,14 +588,14 @@ namespace MultiArrayHelper } template - inline void SingleExpression::operator()(size_t mlast, DExt last) const + inline void SingleExpression::operator()(size_t mlast, DExt last) { operator()(mlast, *reinterpret_cast(last.first)); } template inline void SingleExpression::operator()(size_t mlast, - ExtType last) const + ExtType last) { //typedef typename IndexClass::RangeType RangeType; const size_t pos = mIndPtr->pos(); @@ -604,7 +605,7 @@ namespace MultiArrayHelper } template - inline void SingleExpression::operator()(size_t mlast) const + inline void SingleExpression::operator()(size_t mlast) { //typedef typename IndexClass::RangeType RangeType; const ExtType last; @@ -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 )) ) ), @@ -671,14 +672,14 @@ namespace MultiArrayHelper } template - inline void SubExpr::operator()(size_t mlast, DExt last) const + inline void SubExpr::operator()(size_t mlast, DExt last) { operator()(mlast, *reinterpret_cast(last.first)); } template inline void SubExpr::operator()(size_t mlast, - ExtType last) const + ExtType last) { const size_t pos = (*mSubSet)[last.val()]; const size_t mnpos = mlast; @@ -687,7 +688,7 @@ namespace MultiArrayHelper } template - inline void SubExpr::operator()(size_t mlast) const + inline void SubExpr::operator()(size_t mlast) { const ExtType last; const size_t pos = (*mSubSet)[last.val()]; @@ -730,12 +731,12 @@ namespace MultiArrayHelper * DynamicExpression * ***************************/ - inline void DynamicExpression::operator()(size_t mlast, DExt last) const + inline void DynamicExpression::operator()(size_t mlast, DExt last) { (*mNext)(mlast,last); } - inline void DynamicExpression::operator()(size_t mlast) const + inline void DynamicExpression::operator()(size_t mlast) { (*mNext)(mlast); } @@ -758,13 +759,13 @@ namespace MultiArrayHelper ExpressionHolder::ExpressionHolder(DynamicExpression expr) : mExpr(expr) {} template - inline void ExpressionHolder::operator()(size_t mlast, DExt last) const + inline void ExpressionHolder::operator()(size_t mlast, DExt last) { mExpr(mlast,last); } template - inline void ExpressionHolder::operator()(size_t mlast, ExtType last) const + inline void ExpressionHolder::operator()(size_t mlast, ExtType last) { mExpr(mlast, std::make_pair @@ -773,7 +774,7 @@ namespace MultiArrayHelper } template - inline void ExpressionHolder::operator()(size_t mlast) const + inline void ExpressionHolder::operator()(size_t mlast) { mExpr(mlast); } 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 3849270..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; } - SingleRange::SingleRange(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 9cdba7d..7fbd227 100644 --- a/src/lib/ranges/range_types/classic_range.cc +++ b/src/lib/ranges/range_types/classic_range.cc @@ -5,63 +5,63 @@ 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 + 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)); @@ -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..107d4b0 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,56 +42,56 @@ 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 + 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)); 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..b867f2a 100644 --- a/src/lib/ranges/range_types/space_range.cc +++ b/src/lib/ranges/range_types/space_range.cc @@ -11,63 +11,63 @@ 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 + 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)); @@ -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..191ae2f 100644 --- a/src/lib/ranges/range_types/spin_range.cc +++ b/src/lib/ranges/range_types/spin_range.cc @@ -10,68 +10,68 @@ 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 + 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)); 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/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 4c623ec..131db7e 100644 --- a/src/tests/op_perf_test.cc +++ b/src/tests/op_perf_test.cc @@ -5,9 +5,11 @@ #include #include "multi_array_header.h" +#include "conversions.h" #include #include +#include #define ONLY_SPIN @@ -32,15 +34,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 +80,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 +114,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,15 +134,16 @@ namespace { typedef SpinRF SRF; typedef SpinRange SR; typedef MultiRangeFactory SR8F; - typedef SR8F::oType SR8; - - static const size_t os = 3000; - static const size_t s = 65536*os; + typedef SR8F::oType SR8; + + static const size_t os = 3000; + 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]); @@ -151,18 +154,18 @@ 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; }; 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); @@ -171,36 +174,35 @@ 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 ); + auto mix = MAT::mkMIndex( jj, alpha, beta, gamma ); - 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); - //} - 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){ - for(size_t a = 0; a != 4; ++a){ - for(size_t b = 0; b != 4; ++b){ - for(size_t c = 0; c != 4; ++c){ - 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; - vres[tidx] += data[sidx]; + } + auto begin2 = std::chrono::system_clock::now(); + double* vrptr = vres.data(); + double* dptr = data.data(); + for(size_t i = 0; i != os; ++i){ + for(size_t d = 0; d != 4; ++d){ + for(size_t j = 0; j != os; ++j) { + for(size_t a = 0; a != 4; ++a){ + for(size_t b = 0; b != 4; ++b){ + for(size_t c = 0; c != 4; ++c){ + const size_t tidx = i*4*4 + d*4; + 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; + double* xvrptr = vrptr + tidx; + double* xdptr = dptr + sidx; +#pragma omp simd aligned(xvrptr, xdptr: 32) + for(int p = 0; p < 4; p++){ + xvrptr[p] += xdptr[p]; } } } @@ -208,8 +210,20 @@ namespace { } } } - std::clock_t end2 = std::clock(); + auto end2 = std::chrono::system_clock::now(); + std::cout << "vector - for loop time: " << std::chrono::duration(end2-begin2).count() + << std::endl; + + auto begin = std::chrono::system_clock::now(); + //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); + tcast(res1)(ii ,delta, deltap).par() += tcast(ma)(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix); + //} + auto end = std::chrono::system_clock::now(); + std::cout << "MultiArray time: " << std::chrono::duration(end-begin).count() + << std::endl; + assert( xround(res1.at(mkts(0,0,0))) == xround(vres[0]) ); assert( xround(res1.at(mkts(0,0,1))) == xround(vres[1]) ); assert( xround(res1.at(mkts(0,0,2))) == xround(vres[2]) ); @@ -230,9 +244,9 @@ 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::endl; - std::cout << "ratio: " << static_cast( end - begin ) / static_cast( end2 - begin2 ) << std::endl; + std::cout << "ratio: " + << std::chrono::duration(end-begin).count() / std::chrono::duration(end2-begin2).count() + << std::endl; } #ifndef ONLY_SPIN void OpTest_Performance::PCheck() @@ -254,7 +268,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){ @@ -264,7 +278,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; }