diff --git a/src/include/helper_tools.cc.h b/src/include/helper_tools.cc.h index e7b6268..3e9b4b7 100644 --- a/src/include/helper_tools.cc.h +++ b/src/include/helper_tools.cc.h @@ -6,7 +6,8 @@ namespace MultiArrayTools template std::ostream& operator<<(std::ostream& out, const std::tuple& tp) { - PackNum::printTuple(out, tp); + MA_SFOR(i,0,sizeof...(T)-1,i+1, out << std::get(tp) << ", ";); + out << std::get(tp); return out; } diff --git a/src/include/helper_tools.h b/src/include/helper_tools.h index 77fac38..e8906df 100644 --- a/src/include/helper_tools.h +++ b/src/include/helper_tools.h @@ -5,7 +5,6 @@ #include "base_def.h" #include "slice.h" #include -#include "pack_num.h" #include "map_range.h" #include #include "xfor/iloop.h" diff --git a/src/include/multi_array.cc.h b/src/include/multi_array.cc.h index bff9f42..130a038 100644 --- a/src/include/multi_array.cc.h +++ b/src/include/multi_array.cc.h @@ -1,5 +1,6 @@ #include "multi_array.h" +#include "statics/static_for.h" namespace MultiArrayTools { @@ -246,11 +247,12 @@ namespace MultiArrayTools (*this) = in; } else { - assert( PackNum::checkIfSameInstance( MAB::mRange->space(), in.mRange->space() ) ); + MA_SCFOR2(i,0,sizeof...(SRanges),i+1, + std::get(MAB::mRange->space()).get() == std::get(in.mRange->space()).get(), + operator&&); for(size_t i = 0; i != mCont.size(); ++i){ mCont[i] += in.mCont[i]; } - //std::transform(mCont.begin(), mCont.end(), in.mCont.begin(), mCont.begin(), std::plus()); } return *this; } @@ -262,7 +264,9 @@ namespace MultiArrayTools (*this) = in; } else { - assert( PackNum::checkIfSameInstance( MAB::mRange->space(), in.mRange->space() ) ); + MA_SCFOR2(i,0,sizeof...(SRanges),i+1, + std::get(MAB::mRange->space()).get() == std::get(in.mRange->space()).get(), + operator&&); for(size_t i = 0; i != mCont.size(); ++i){ mCont[i] -= in.mCont[i]; } diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 683b170..2bbf4ca 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -14,7 +14,6 @@ #include "mbase_def.h" #include "ranges/rheader.h" -#include "pack_num.h" #include "arith.h" #include "xfor/xfor.h" diff --git a/src/include/pack_num.h b/src/include/pack_num.h deleted file mode 100644 index 9a5613a..0000000 --- a/src/include/pack_num.h +++ /dev/null @@ -1,225 +0,0 @@ -// -*- C++ -*- - -#ifndef __pack_num_h__ -#define __pack_num_h__ - -#include -//#include -#include -#include - -#include "base_def.h" -#include "xfor/exttype.h" - -namespace MultiArrayHelper -{ - template - struct PackNum - { - template - static auto mkElemOperation(const MA& ma, const ITuple& ituple, IPtrs... iptrs) - -> decltype(PackNum::mkElemOperation(ma, ituple, std::get(ituple), iptrs...)) - { - return PackNum::mkElemOperation(ma, ituple, std::get(ituple), iptrs...); - } - - - template - static void printTuple(std::ostream& out, const std::tuple& tp) - { - out << std::get(tp) << ", "; - PackNum::printTuple(out, tp); - } - - template - static auto mkSteps(std::intptr_t ii, const std::tuple& otp) - -> decltype(PackNum::mkSteps(ii, otp).extend( std::get(otp).rootSteps(ii)) ) - { - return PackNum::mkSteps(ii, otp).extend( std::get(otp).rootSteps(ii)); - } - - template - static void mkExt(std::array& out, - const std::array& siar, - const OpClass& second) - { - std::get(out) = second.rootSteps( std::get(siar) ); - PackNum::mkExt(out, siar, second); - } - - template - static inline auto 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"); - static constexpr size_t NEXT = LAST - NextOpType::SIZE; - typedef decltype(std::get(ops).get(getX( pos ))) ArgT; - return PackNum::template mkOpExpr - ( f, pos, ops, std::get(ops).get(getX( pos )), args...); - } - - template - static inline auto mkVOpExpr(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"); - static constexpr size_t NEXT = LAST - NextOpType::SIZE; - typedef decltype(std::get(ops).template vget(getX( pos ))) ArgT; - return PackNum::template mkVOpExpr - ( f, pos, ops, std::get(ops).template vget(getX( pos )), args...); - } - - template - static auto mkLoop( const OpTuple& ot, Expr exp ) - -> decltype(std::get(ot).loop( PackNum::mkLoop(ot,exp) )) - { - return std::get(ot).loop( PackNum::mkLoop(ot,exp) ); - } - - template - static void mkSliceBlocks(std::array& blocks, - const ContainerIndex& index, - const Op& op, size_t total = 1) - { - const size_t tmp = - op.rootSteps(reinterpret_cast - ( index.template getPtr().get() ) ) - .val(); - std::get(blocks) = tmp; - PackNum::template mkSliceBlocks(blocks, index, op, total * tmp); - } - - template - static bool checkIfSameInstance(const std::tuple...>& rtp1, - const std::tuple...>& rtp2) - { - return std::get(rtp1).get() == std::get(rtp2).get() and PackNum::checkIfSameInstance(rtp1,rtp2); - } - - template - static inline auto mkMapOp(const MA& ma, const ITuple& itp, const std::shared_ptr&... inds) - -> decltype(PackNum::mkMapOp(ma, itp, std::get(itp), inds...)) - { - return PackNum::mkMapOp(ma, itp, std::get(itp), inds...); - } - - template - 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"); - static constexpr size_t NEXT = LAST - NextOpType::SIZE; - std::get( ot ).set( getX( et ) ); - PackNum::template setOpPos(ot, et); - } - }; - - template<> - struct PackNum<0> - { - template - static auto mkElemOperation(const MA& ma, const ITuple& ituple, IPtrs... iptrs) - -> decltype(ma(iptrs...)) - { - return ma(iptrs...); - } - - template - static void printTuple(std::ostream& out, const std::tuple& tp) - { - out << std::get(tp); - } - - template - static auto mkSteps(std::intptr_t ii, const std::tuple& otp) - -> decltype(std::get<0>(otp).rootSteps(ii)) - { - return std::get<0>(otp).rootSteps(ii); - } - - template - static void mkExt(std::array& out, - const std::array& siar, - const OpClass& second) - { - std::get<0>(out) = second.rootSteps( std::get<0>(siar) ); - } - - template - static inline auto mkOpExpr(std::shared_ptr f, const ETuple& pos, const OpTuple& ops, const Args&... args) - { - typedef typename std::remove_reference(ops))>::type NextOpType; - static constexpr size_t NEXT = LAST - NextOpType::SIZE; - static_assert(NEXT == 0, "inconsistent array positions"); - if constexpr(OpFunction::FISSTATIC){ - return OpFunction::apply(std::get<0>(ops).get(getX<0>( pos )), args...); - } - else { - return (*f)(std::get<0>(ops).get(getX<0>( pos )), args...); - } - } - - template - static inline auto mkVOpExpr(std::shared_ptr f, const ETuple& pos, const OpTuple& ops, const Args&... args) - { - typedef typename std::remove_reference(ops))>::type NextOpType; - static constexpr size_t NEXT = LAST - NextOpType::SIZE; - static_assert(NEXT == 0, "inconsistent array positions"); - if constexpr(OpFunction::FISSTATIC){ - return OpFunction::apply(std::get<0>(ops).template vget(getX<0>( pos )), args...); - } - else { - return (*f)(std::get<0>(ops).template vget(getX<0>( pos )), args...); - } - } - - template - static auto mkLoop( const OpTuple& ot, Expr exp ) - -> decltype(std::get<0>(ot).loop( exp )) - { - return std::get<0>(ot).loop( exp ); - } - - template - static void mkSliceBlocks(std::array& blocks, - const ContainerIndex& index, - const Op& op, size_t total = 1) - { - const size_t tmp = - op.rootSteps(reinterpret_cast - ( index.template getPtr<0>().get() ) ) - .val(); - std::get<1>(blocks) = tmp; - std::get<0>(blocks) = total * tmp; // this is not correct, but not used so far ... !!! - } - - template - static bool checkIfSameInstance(const std::tuple...>& rtp1, - const std::tuple...>& rtp2) - { - return std::get<0>(rtp1).get() == std::get<0>(rtp2).get(); - } - - template - static inline auto mkMapOp(const MA& ma, const ITuple& itp, const std::shared_ptr&... inds) - -> decltype(ma.exec(std::get<0>(itp), inds...)) - { - return ma.exec(std::get<0>(itp), inds...); - } - - template - static inline void setOpPos(OpTuple& ot, const ETuple& et) - { - typedef typename std::remove_reference(ot))>::type NextOpType; - static constexpr size_t NEXT = LAST - NextOpType::SIZE; - static_assert(NEXT == 0, "inconsistent array positions"); - std::get<0>( ot ).set( getX( et ) ); - } - - }; - - - -} // end namespace MultiArrayHelper - -#endif diff --git a/src/include/slice.cc.h b/src/include/slice.cc.h index 3d302f7..0505805 100644 --- a/src/include/slice.cc.h +++ b/src/include/slice.cc.h @@ -243,8 +243,9 @@ namespace MultiArrayTools SliceDef& SliceDef::operator=(const OperationRoot& op) { std::array blocks; - PackNum:: - template mkSliceBlocks,SRanges...>(blocks, mIndex, op); + MA_SFOR(i,0,sizeof...(SRanges),i+1, + std::get(blocks) = op.rootSteps(reinterpret_cast + ( mIndex.template getPtr().get())).val();); mSl.format(blocks); mSl.mData = op.data(); return *this; @@ -264,8 +265,9 @@ namespace MultiArrayTools ConstSliceDef& ConstSliceDef::operator=(const ConstOperationRoot& op) { std::array blocks; - PackNum:: - template mkSliceBlocks,SRanges...>(blocks, mIndex, op); + MA_SFOR(i,0,sizeof...(SRanges),i+1, + std::get(blocks) = op.rootSteps(reinterpret_cast + ( mIndex.template getPtr().get())).val();); mSl.format(blocks); mSl.mData = op.data(); return *this; @@ -276,8 +278,9 @@ namespace MultiArrayTools ConstSliceDef& ConstSliceDef::operator=(const OperationRoot& op) { std::array blocks; - PackNum:: - template mkSliceBlocks,SRanges...>(blocks, mIndex, op); + MA_SFOR(i,0,sizeof...(SRanges),i+1, + std::get(blocks) = op.rootSteps(reinterpret_cast + ( mIndex.template getPtr().get())).val();); mSl.format(blocks); mSl.mData = op.data(); return *this; diff --git a/src/include/slice.h b/src/include/slice.h index bd79d83..886df4b 100644 --- a/src/include/slice.h +++ b/src/include/slice.h @@ -108,13 +108,13 @@ namespace MultiArrayTools template static Slice mkSlice( const typename Slice::IndexType& ind, - const Op& op ) + const Op& op ) { Slice out(ind->range()->space(), &*ind); std::array ff; - for(size_t i = 0; i != sizeof...(SRanges)+1; ++i){ - PackNum::mkSliceBlocks(ff, ind, op); - } + MA_SFOR(i,0,sizeof...(SRanges),i+1, + std::get(ff) = op.rootSteps(reinterpret_cast + ( ind.template getPtr().get())).val();); out.format(ff); return out; } @@ -145,9 +145,9 @@ namespace MultiArrayTools { ConstSlice out(ind->range()->space(), &*ind); std::array ff; - for(size_t i = 0; i != sizeof...(SRanges)+1; ++i){ - PackNum::mkSliceBlocks(ff, ind, op); - } + MA_SFOR(i,0,sizeof...(SRanges),i+1, + std::get(ff) = op.rootSteps(reinterpret_cast + ( ind.template getPtr().get())).val();); out.format(ff); return out; } diff --git a/src/include/statics/static_for.h b/src/include/statics/static_for.h index 5fb77c9..c89cc6f 100644 --- a/src/include/statics/static_for.h +++ b/src/include/statics/static_for.h @@ -14,7 +14,7 @@ namespace MultiArrayTools //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){ + if constexpr(incr(idx) >= END){ return tmp; } else { @@ -30,7 +30,7 @@ namespace MultiArrayTools //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){ + if constexpr(incr(idx) >= END){ return conc(tmp, arg); } else { @@ -45,7 +45,7 @@ namespace MultiArrayTools 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){ + if constexpr(BEG >= END){ return create(args...); } else { @@ -58,6 +58,7 @@ namespace MultiArrayTools #define MA_SFOR(i,beg,end,incr,expr) sfor([&](auto i) constexpr { return incr; }, [&](auto i){ expr return 0; }, [&](auto f, auto next) { return 0; }) #define MA_SCFOR(i,beg,end,incr,expr,conc) sfor([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }) +#define MA_SCFOR2(i,beg,end,incr,expr,conc) sfor([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, [&](auto a, auto b) { return conc(a,b); }) #define MA_SRFOR(i,beg,end,decr,expr) sfor([&](auto i) constexpr { return decr; }, [&](auto i){ expr return 0; }, [&](auto f, auto next) { return 0; }) #define MA_SCRFOR(i,beg,end,decr,expr,conc) sfor([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }) #define MA_SCRAFOR(i,beg,end,decr,expr,conc,arg) sfor([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }, arg) diff --git a/src/include/type_operations.h b/src/include/type_operations.h index f38c243..3e13521 100644 --- a/src/include/type_operations.h +++ b/src/include/type_operations.h @@ -9,7 +9,8 @@ #include "base_def.h" #include "mbase_def.h" -#include "pack_num.h" +#include "statics/static_for.h" + #include namespace MultiArrayTools @@ -32,7 +33,7 @@ namespace MultiArrayTools inline auto apply(const MultiArray& ma) -> OperationRoot { - return PackNum::mkElemOperation(ma, ituple); + return MA_CFOR(i,0,sizeof...(Ranges),i+1,return std::get(ituple);,ma); } private: