diff --git a/src/include/array/aindex.cc.h b/src/include/array/aindex.cc.h index 13d40c1..cfd7d7d 100644 --- a/src/include/array/aindex.cc.h +++ b/src/include/array/aindex.cc.h @@ -3,7 +3,6 @@ #define __cxz_aindex_cc_h__ #include "aindex.h" -#include "statics/static_for.h" namespace CNORXZ { diff --git a/src/include/statics/static_for.h b/src/include/statics/static_for.h deleted file mode 100644 index 63ff959..0000000 --- a/src/include/statics/static_for.h +++ /dev/null @@ -1,173 +0,0 @@ - -#ifndef __cxz_static_for_h__ -#define __cxz_static_for_h__ - -#include - -namespace CNORXZ -{ - template - inline auto sfor(Incr incr, F f) - { - constexpr auto idx = std::integral_constant{}; - constexpr auto idxm = std::integral_constant{}; - - const bool cond = f(idxm); - if constexpr(incr(idx) != END){ - if(cond){ - sfor(incr,f); - } - } - return cond; - } - - template - inline auto sforx(Incr incr, F f, Cond cond) - { - constexpr auto idx = std::integral_constant{}; - constexpr auto idxm = std::integral_constant{}; - - if constexpr(incr(idx) != END){ - if(cond(idx)){ - return sforx(incr,f,cond); - } - else { - return f(idxm); - } - } - else { - return f(idxm); - } - } - - template - inline auto sfor(Incr incr, F f, Conc conc) - { - constexpr auto idx = std::integral_constant{}; - constexpr auto idxm = std::integral_constant{}; - //static_assert(abs(idx.value - END) >= abs(incr(idx) - END), - // "this turns out to be a static endless loop"); - auto tmp = f(idxm); - if constexpr(incr(idx) == END){ - return tmp; - } - else { - return conc(tmp, sfor(incr,f,conc)); - } - } - - template - inline auto sfor(Incr incr, F f, Conc conc, const Arg& arg) - { - constexpr auto idx = std::integral_constant{}; - constexpr auto idxm = std::integral_constant{}; - //static_assert(abs(idx.value - END) >= abs(incr(idx) - END), - // "this turns out to be a static endless loop"); - auto tmp = f(idxm); - if constexpr(incr(idx) == END){ - return conc(tmp, arg); - } - else { - return conc(tmp, sfor(incr,f,conc,arg)); - } - } - - template - inline auto unpack(Incr incr, F f, Create create, const Args&... args) - { - constexpr auto idx = std::integral_constant{}; - constexpr auto idxm = std::integral_constant{}; - //static_assert(abs(idx.value - END) >= abs(incr(idx) - END), - // "this turns out to be a static endless loop"); - if constexpr(BEG == END){ - return create(args...); - } - else { - auto tmp = f(idxm); - return unpack(incr, f, create, args..., tmp); - } - } - -} - -#define MA_INC [&](auto i) constexpr { return i+1; } -#define MA_DEC [&](auto i) constexpr { return i-1; } -#define MA_ZCONC [&](auto a, auto b) { return 0; } - -namespace CNORXZ -{ - template - inline auto sfor_p(F f) - { - return sfor(MA_INC,f); - } - - template - inline auto sfor_m(F f) - { - return sfor(MA_DEC,f); - } - - template - inline auto sforx_p(F f, Cond cond) - { - return sforx(MA_INC,f,cond); - } - - template - inline auto sforx_m(F f, Cond cond) - { - return sforx(MA_DEC,f,cond); - } - - template - inline auto sfor_p(F f, Conc conc) - { - return sfor(MA_INC,f,conc); - } - - template - inline auto sfor_pn(F f) - { - return sfor_p(f,MA_ZCONC); - } - - template - inline auto sfor_m(F f, Conc conc) - { - return sfor(MA_DEC,f,conc); - } - - template - inline auto sfor_mn(F f) - { - return sfor_m(f,MA_ZCONC); - } - - template - inline auto sfor_p(F f, Conc conc, const Arg& arg) - { - return sfor(MA_INC,f,conc,arg); - } - - template - inline auto sfor_pn(F f, const Arg& arg) - { - return sfor_p(f,MA_ZCONC,arg); - } - - template - inline auto sfor_m(F f, Conc conc, const Arg& arg) - { - return sfor(MA_DEC,f,conc,arg); - } - - template - inline auto sfor_mn(F f, const Arg& arg) - { - return sfor_m(f,MA_ZCONC,arg); - } - -} - -#endif diff --git a/src/include/statics/traits.h b/src/include/statics/traits.h deleted file mode 100644 index aac875e..0000000 --- a/src/include/statics/traits.h +++ /dev/null @@ -1,26 +0,0 @@ - -#include "base_def.h" - -namespace CNORXZ -{ - - template - struct IsArray - { - static constexpr bool VALUE = false; - }; - -#define add_array_trait(name) template struct IsArray<##name> { \ - static constexpr bool VALUE = true; \ - } - - add_array_trait(DArrayBase); - add_array_trait(MDArrayBase); - add_array_trait(DArray); - //add_array_trait(FunctionalArray); - //add_array_trait(Slice); - //add_array_trait(ConstSlice); - -#undef add_array_trait - -} diff --git a/src/include/utils/helper_tools.cc.h b/src/include/utils/helper_tools.cc.h deleted file mode 100644 index c2dfb19..0000000 --- a/src/include/utils/helper_tools.cc.h +++ /dev/null @@ -1,398 +0,0 @@ - -#include "helper_tools.h" - -namespace CNORXZ -{ - template - std::ostream& operator<<(std::ostream& out, const std::tuple& tp) - { - sfor_pn<0,sizeof...(T)-1>( [&](auto i){ out << std::get(tp) << ", "; return 0; } ); - out << std::get(tp); - return out; - } - - template - auto getIndex(std::shared_ptr range) - -> std::shared_ptr - { - return std::make_shared(range); - } - - template - auto getIndex() - -> std::shared_ptr - { - static_assert( RangeType::defaultable, "Range not defaultable" ); - static auto f = RangeType::factory(); - static auto r = std::dynamic_pointer_cast( f.create() ); - return std::make_shared(r); - } - - template - auto mkMulti(std::shared_ptr... ranges) - -> std::shared_ptr > - { - MultiRangeFactory mrf( ranges... ); - return std::dynamic_pointer_cast >( mrf.create() ); - } - - namespace - { - template - struct IndexToRangeTuple - { - template - static inline void set(std::tuple...>& out, - const std::tuple...>& indices) - { - std::get(out) = std::get(indices)->range(); - IndexToRangeTuple::set(out,indices); - } - }; - - template <> - struct IndexToRangeTuple<0> - { - template - static inline void set(std::tuple...>& out, - const std::tuple...>& indices) - { - std::get<0>(out) = std::get<0>(indices)->range(); - } - }; - } - - template - auto indexToRangeTuple(const std::tuple...>& indices) - -> std::tuple...> - { - std::tuple...> out; - IndexToRangeTuple::set(out, indices); - return out; - } - - template - auto mkMIndex(std::shared_ptr... indices) - -> decltype( getIndex( mkMulti( indices->range()... ) ) ) - { - auto mi = getIndex( mkMulti( indices->range()... ) ); - (*mi)( indices... ); - return mi; - } - - template - auto mkMIndex(const std::tuple...>& indices) - -> decltype( getIndex( mkMulti( indexToRangeTuple(indices) ) ) ) - { - auto mi = getIndex( mkMulti( indexToRangeTuple(indices) ) ); - (*mi)( indices ); - return mi; - } - - - template - auto mkIndexW(const std::shared_ptr& ind) - -> std::shared_ptr - { - return std::make_shared>(ind); - } - - template - auto mkGenMapR(const std::tuple& f, std::shared_ptr... ranges) - -> std::shared_ptr,Op,STYPE,RangeTypes...> > - { - GenMapRangeFactory,Op,STYPE,RangeTypes...> mrf(f, ranges... ); - return createExplicit( mrf ); - } - - template - auto mkGenMapRwith(const std::shared_ptr& outr, const std::tuple& f, - std::shared_ptr... ranges) - -> std::shared_ptr > - { - GenMapRangeFactory mrf(outr, f, ranges... ); - return createExplicit( mrf ); - } - - template - auto mkGenMapI(const std::tuple& f, std::shared_ptr... indices) - -> decltype( getIndex( mkGenMapR( f, indices->range()... ) ) ) - { - auto mi = getIndex( mkGenMapR( f, indices->range()... ) ); - (*mi)(indices...); - return mi; - } - - template - auto mkMapR(const std::tuple& f, std::shared_ptr... ranges) - -> decltype( mkGenMapR(f, ranges... ) ) - { - return mkGenMapR(f, ranges... ); - } - - template - auto mkMapRwith(const std::shared_ptr& outr, const std::tuple& f, - std::shared_ptr... ranges) - -> decltype( mkGenMapRwith(outr, f, ranges... ) ) - { - return mkGenMapRwith(outr, f, ranges... ); - } - - template - auto mkMapR(const std::shared_ptr& func, const std::shared_ptr&... is) - -> decltype( mkMapR( mkMapOp( func, is... ), is->range()... ) ) - { - return mkMapR( mkMapOp( func, is... ), is->range()... ); - } - - template - auto mkMapRwith(const std::shared_ptr& outr, const std::shared_ptr& func, const std::shared_ptr&... is) - -> decltype( mkMapRwith(outr, mkMapOp( func, is... ), is->range()... ) ) - { - return mkMapRwith(outr, mkMapOp( func, is... ), is->range()... ); - } - - template - auto mkMapI(const std::tuple& f, std::shared_ptr... indices) - -> decltype( mkGenMapI(f, indices... ) ) - { - return mkGenMapI(f, indices... ); - } - - template - auto mkMulti(std::tuple...> rangesTuple) - -> std::shared_ptr> - { - MultiRangeFactory mrf( rangesTuple ); - return std::dynamic_pointer_cast >( mrf.create() ); - } - - template - auto createExplicit(RangeFactory& rf) - -> std::shared_ptr - { - return std::dynamic_pointer_cast( rf.create() ); - } - - template - auto createExplicit(std::shared_ptr rfp) - -> std::shared_ptr - { - return std::dynamic_pointer_cast( rfp->create() ); - } - - template - auto createRange(const vector& cvec) - -> std::shared_ptr - { - const char* dp = cvec.data(); - auto ff = createRangeFactory(&dp); - auto rbptr = ff->create(); - assert(rbptr->spaceType() == Range::STYPE); - // CATCH CAST ERROR HERE !!! - return std::dynamic_pointer_cast( rbptr ); - } - - inline auto createRange(const vector* cvec, int metaType, size_t size) - -> std::shared_ptr - { - auto f = createSingleRangeFactory(cvec, metaType, size); - return f->create(); - } - - inline auto createRangeA(const vector* cvec, int metaType, size_t size) - -> std::shared_ptr - { - AnonymousRangeFactory arf(createRange(cvec, metaType, size)); - return createExplicit(arf); - } - - inline auto cvecMetaCast(const std::shared_ptr,SpaceType::ANY>>& r, int metaType) - -> std::shared_ptr - { - return createRange(&r->get(0), metaType, r->size()); - } - - inline auto cvecMetaCastA(const std::shared_ptr,SpaceType::ANY>>& r, int metaType) - -> std::shared_ptr - { - return createRangeA(&r->get(0), metaType, r->size()); - } - - template - auto createRangeE(Args&&... args) - -> std::shared_ptr - { - typename Range::FType f(args...); - return createExplicit(f); - } - - template - auto rptr(const MArray& ma) - -> decltype(ma.template getRangePtr()) - { - return ma.template getRangePtr(); - } - - - template - auto dynamic(const MArray& ma, bool slice) - -> std::shared_ptr> - { - DynamicRangeFactory drf(ma.range()->space()); - if(slice){ - return std::make_shared> - ( std::dynamic_pointer_cast( drf.create() ), - ma.data() ); - } - else { - return std::make_shared> - ( std::dynamic_pointer_cast( drf.create() ), - ma.vdata() ); - } - } - - template - auto mdynamic(MArray& ma, bool slice) - -> std::shared_ptr> - { - DynamicRangeFactory drf(ma.range()->space()); - if(slice){ - return std::make_shared> - ( std::dynamic_pointer_cast( drf.create() ), - ma.data() ); - } - else { - return std::make_shared> - ( std::dynamic_pointer_cast( drf.create() ), - ma.vdata() ); - } - } - - namespace - { - template - struct CopyRanges - { - template - static inline void exec(const Space1& space1, Space2& space2) - { - std::get(space2) = std::get(space1); - CopyRanges::exec(space1,space2); - } - }; - - template <> - struct CopyRanges<0> - { - template - static inline void exec(const Space1& space1, Space2& space2) - { - std::get<0>(space2) = std::get<0>(space1); - } - }; - } - - template - auto anonToDynView(const ArrayBase& ma) - -> ConstSlice - { - constexpr size_t LAST = sizeof...(RangeTypes)+1; - DynamicRangeFactory drf(rptr(ma)->orig()); - std::tuple,std::shared_ptr..., - std::shared_ptr> mNSpace; - CopyRanges::exec(ma.range()->space(),mNSpace); - std::get(mNSpace) = createExplicit( drf ); - return ConstSlice(mNSpace, ma.data()); - } - - template - auto anonToDynView(MutableArrayBase& ma) - -> Slice - { - constexpr size_t LAST = sizeof...(RangeTypes)+1; - DynamicRangeFactory drf(rptr(ma)->orig()); - std::tuple,std::shared_ptr..., - std::shared_ptr> mNSpace; - CopyRanges::exec(ma.range()->space(),mNSpace); - std::get(mNSpace) = createExplicit( drf ); - return Slice(mNSpace, ma.data()); - } - - template - auto dynToAnonMove(Array&& ma) - -> Array - { - constexpr size_t LAST = sizeof...(RangeTypes)+1; - AnonymousRangeFactory arf(rptr(ma)->orig()); - std::tuple,std::shared_ptr..., - std::shared_ptr> mNSpace; - CopyRanges::exec(ma.range()->space(),mNSpace); - std::get(mNSpace) = createExplicit( arf ); - return ma.format(mNSpace); - } - - template - auto anonToDynView(const ArrayBase& ma) - -> ConstSlice - { - DynamicRangeFactory drf(rptr<0>(ma)->orig()); - auto mNSpace = std::make_tuple( createExplicit( drf ) ); - return ConstSlice(mNSpace, ma.data()); - } - - template - auto anonToDynView(MutableArrayBase& ma) - -> Slice - { - DynamicRangeFactory drf(rptr<0>(ma)->orig()); - auto mNSpace = std::make_tuple( createExplicit( drf ) ); - return Slice(mNSpace, ma.data()); - } - - template - auto dynToAnonMove(Array&& ma) - -> Array - { - AnonymousRangeFactory arf(rptr<0>(ma)->orig()); - auto mNSpace = std::make_tuple( createExplicit( arf ) ); - return ma.format(mNSpace); - } - - template - auto metaSlice(const std::shared_ptr& r) - -> ConstSlice - { - ClassicRF crf(r->size()); - return ConstSlice( createExplicit(crf), &r->get(0) ); - } - - template - auto metaSlice(const std::shared_ptr& r, const std::shared_ptr& ro) - -> ConstSlice - { - return ConstSlice( ro, &r->get(0) ); - } - - template - auto mkArray(const std::shared_ptr&... rs) - -> Array - { - return Array(rs...); - } - - template - auto mkArray(const std::shared_ptr&... rs, const T& val) - -> Array - { - return Array(rs..., val); - } - - template - auto mkArrayPtr(const std::shared_ptr&... rs) - -> std::shared_ptr> - { - return std::make_shared>(rs...); - } - -} diff --git a/src/include/utils/helper_tools.h b/src/include/utils/helper_tools.h deleted file mode 100644 index 403ef70..0000000 --- a/src/include/utils/helper_tools.h +++ /dev/null @@ -1,238 +0,0 @@ - -#ifndef __cxz_helper_tools_h__ -#define __cxz_helper_tools_h__ - -#include "base_def.h" -#include "slice.h" -#include -#include "map_range.h" -#include -#include "xpr/iloop.h" - -namespace CNORXZ -{ - - template - std::ostream& operator<<(std::ostream& out, const std::tuple& tp); - - template - auto getIndex(std::shared_ptr range) - -> std::shared_ptr; - - // only if 'RangeType' is defaultable and unique (Singleton) - template - auto getIndex() -> std::shared_ptr; - - template - auto mkMulti(std::shared_ptr... ranges) - -> std::shared_ptr >; - - template - using MapORType = SingleRange; - - template - auto mkGenMapR(const std::tuple& f, std::shared_ptr... ranges) - -> std::shared_ptr,Op,STYPE,RangeTypes...> >; - - template - auto mkGenMapRwith(const std::shared_ptr& outr, const std::tuple& f, - std::shared_ptr... ranges) - -> std::shared_ptr >; - - template - auto mkGenMapI(const std::tuple& f, std::shared_ptr... indices) - -> decltype( getIndex( mkGenMapR( f, indices->range()... ) ) ); - - template - auto mkMapR(const std::tuple& f, std::shared_ptr... ranges) - -> decltype( mkGenMapR(f, ranges... ) ); - - template - auto mkMapRwith(const std::shared_ptr& outr, const std::tuple& f, std::shared_ptr... ranges) - -> decltype( mkGenMapRwith(outr, f, ranges... ) ); - - template - auto mkMapR(const std::shared_ptr& func, const std::shared_ptr&... is) - -> decltype( mkMapR( mkMapOp( func, is... ), is->range()... ) ); - - template - auto mkMapRwith(const std::shared_ptr& outr, const std::shared_ptr& func, const std::shared_ptr&... is) - -> decltype( mkMapRwith(outr, mkMapOp( func, is... ), is->range()... ) ); - - template - auto mkMapI(const std::tuple& f, std::shared_ptr... indices) - -> decltype( mkGenMapI(f, indices... ) ); - - template - auto indexToRangeTuple(const std::tuple...>& indices) - -> std::tuple...>; - - template - auto mkMulti(std::tuple...> rangesTuple) - -> std::shared_ptr>; - - template - auto mkMIndex(std::shared_ptr... indices) - -> decltype( getIndex( mkMulti( indices.range()... ) ) ); - - template - auto mkMIndex(const std::tuple...>& indices) - -> decltype( getIndex( mkMulti( indexToRangeTuple(indices) ) ) ); - - template - auto mkIndexW(const std::shared_ptr& ind) - -> std::shared_ptr; - - - template - auto createExplicit(RangeFactory& rf) - -> std::shared_ptr; - - template - auto createExplicit(std::shared_ptr rfp) - -> std::shared_ptr; - - template - auto createRange(const vector& cvec) - -> std::shared_ptr; - - inline auto createRange(const vector* cvec, int metaType, size_t size) - -> std::shared_ptr; - - inline auto createRangeA(const vector* cvec, int metaType, size_t size) - -> std::shared_ptr; - - template - auto createRangeE(Args&&... args) - -> std::shared_ptr; - - template - auto rptr(const MArray& ma) - -> decltype(ma.template getRangePtr()); - - template - auto get(const std::shared_ptr& i) - -> decltype(i->template getPtr()) - { - return i->template getPtr(); - } - - template - auto dynamic(const MArray& ma, bool slice = false) - -> std::shared_ptr>; - - template - auto mdynamic(MArray& ma, bool slice) - -> std::shared_ptr>; - - template - auto anonToDynView(const ArrayBase& ma) - -> ConstSlice; - - template - auto anonToDynView(MutableArrayBase& ma) - -> Slice; - - template - auto dynToAnonMove(Array&& ma) - -> Array; - - template - auto anonToDynView(const ArrayBase& ma) - -> ConstSlice; - - template - auto anonToDynView(MutableArrayBase& ma) - -> Slice; - - template - auto dynToAnonMove(Array&& ma) - -> Array; - - template - auto metaSlice(const std::shared_ptr& r) - -> ConstSlice; - - template - auto metaSlice(const std::shared_ptr& r, const std::shared_ptr& ro) - -> ConstSlice; - - template - auto mkArray(const std::shared_ptr&... rs) - -> Array; - - template - auto mkArrayPtr(const std::shared_ptr&... rs) - -> std::shared_ptr>; - - template - auto mkArray(const std::shared_ptr&... rs, const T& val) - -> Array; - - template - auto mkILoop(const OpTp& opTp, const IndTp& indTp, const VarTp& varTp, const LTp& lTp, - const std::array::value>& umpos, - const std::array::value>& setzero) - -> CNORXZInternal::ILoop - { - return CNORXZInternal::ILoop(opTp, indTp, varTp, lTp, umpos, setzero); - } - - template - auto mkPILoop(const CF& cf) - -> CNORXZInternal::PILoop - { - return CNORXZInternal::PILoop(cf); - } - - template - inline void For(const std::shared_ptr& ind, const std::function& ll) - { - for((*ind) = 0; ind->pos() != ind->max(); ++(*ind)){ - ll(); - } - } - - // parallel: - template - inline void PFor(const std::shared_ptr& ind, - const std::function&)>& ll) - { - const int max = static_cast(ind->max()); - int i = 0; -#pragma omp parallel shared(ind,ll) private(i) - { -#pragma omp for nowait - for(i = 0; i < max; i++) { - auto ii = getIndex( ind->range() ); - ((*ii) = i)(); - ll(ii); - } - } - } - - - template - inline auto mkOp(const std::shared_ptr& i) - -> decltype(std::declval,typename Index::RangeType> > - ().exec(i)) - { - FunctionalArray, - typename Index::RangeType> fma(i->range()); - return fma.exec(i); - } - - template - struct Func - { - static inline std::shared_ptr> mk(const std::function& ll) - { - return std::make_shared>(ll); - } - }; -} - - -#endif