diff --git a/src/include/arith.cc.h b/src/include/arith.cc.h new file mode 100644 index 0000000..28dae5d --- /dev/null +++ b/src/include/arith.cc.h @@ -0,0 +1,35 @@ + +#include "arith.h" + +namespace MultiArrayTools +{ + + template + template + auto StaticFunctionBase::mk(const Ops&... ops) + { + return Operation(ops...); + } + + template + template + inline auto StaticFunctionBase::xapply(const Tuple& tp, As... as) + { + if constexpr(N > 0){ + return xapply(tp, std::get(tp), as...); + } + else { + return F::apply(std::get<0>(tp), as...); + } + } + + template + template + inline auto StaticFunctionBase::apply(const std::tuple& arg) + { + return xapply(arg); + //return ArgPack::template mk >(arg); + } + + +} diff --git a/src/include/arith.h b/src/include/arith.h index e9339d8..6423911 100644 --- a/src/include/arith.h +++ b/src/include/arith.h @@ -7,70 +7,33 @@ namespace MultiArrayTools { - template - struct ArgPack - { - template - static inline auto mk(const Tuple& tp, As... as) - -> decltype(ArgPack::template mk(tp)),As...>(tp, std::get(tp), as...)) - { - return ArgPack::template mk(tp)),As...>(tp, std::get(tp), as...); - } - - template - static inline auto mkd(const F& ff, const Tuple& tp, As... as) - -> decltype(ArgPack::template mkd(tp)),As...>(ff, tp, std::get(tp), as...)) - { - return ArgPack::template mkd(tp)),As...>(ff, tp, std::get(tp), as...); - } - }; - - template <> - struct ArgPack<0> - { - template - static inline auto mk(const Tuple& tp, As... as) - -> decltype(F::apply(std::get<0>(tp), as...)) - { - return F::apply(std::get<0>(tp), as...); - } - - template - static inline auto mkd(const F& ff, const Tuple& tp, As... as) - -> decltype(ff(std::get<0>(tp), as...)) - { - return ff(std::get<0>(tp), as...); - } - }; - - template + //template + template struct StaticFunctionBase { static constexpr bool FISSTATIC = true; - typedef T value_type; typedef F function; + //typedef typename F::value_type value_type; template - static auto mk(const Ops&... ops) - -> Operation - { - return Operation(ops...); - } + static auto mk(const Ops&... ops); - static inline T apply(const std::tuple& arg) - { - return ArgPack::template mk >(arg); - } + template + static inline auto xapply(const Tuple& tp, As... as); + + template + static inline auto apply(const std::tuple& arg); }; // OPERATIONS (STATIC) template - struct identity : public StaticFunctionBase, T> + struct identity : public StaticFunctionBase> { //static constexpr bool FISSTATIC = true; - using StaticFunctionBase, T>::apply; - + using StaticFunctionBase>::apply; + typedef T value_type; + static inline T apply(T a) { return a; @@ -95,12 +58,13 @@ namespace MultiArrayTools using dividesv = decltype(std::declval()/std::declval()); template - struct plusx : public StaticFunctionBase, plusx, T, U> + struct plusx : public StaticFunctionBase> { static constexpr bool FISSTATIC = true; - using StaticFunctionBase, plusx, T, U>::apply; - - static inline plusv apply(T a1, U a2) + using StaticFunctionBase>::apply; + typedef plusv value_type; + + static inline value_type apply(T a1, U a2) { return a1 + a2; } @@ -112,36 +76,39 @@ namespace MultiArrayTools }; template - struct minusx : public StaticFunctionBase, minusx, T, U> + struct minusx : public StaticFunctionBase> { static constexpr bool FISSTATIC = true; - using StaticFunctionBase, minusx, T, U>::apply; + using StaticFunctionBase>::apply; + typedef minusv value_type; - static inline plusv apply(T a1, U a2) + static inline value_type apply(T a1, U a2) { return a1 - a2; } }; template - struct multipliesx : public StaticFunctionBase, multipliesx, T, U> + struct multipliesx : public StaticFunctionBase> { static constexpr bool FISSTATIC = true; - using StaticFunctionBase, multipliesx, T, U>::apply; + using StaticFunctionBase>::apply; + typedef multipliesv value_type; - static inline multipliesv apply(T a1, U a2) + static inline value_type apply(T a1, U a2) { return a1 * a2; } }; template - struct dividesx : public StaticFunctionBase, dividesx, T, U> + struct dividesx : public StaticFunctionBase> { static constexpr bool FISSTATIC = true; - using StaticFunctionBase, dividesx, T, U>::apply; + using StaticFunctionBase>::apply; + typedef dividesv value_type; - static inline dividesv apply(T a1, U a2) + static inline value_type apply(T a1, U a2) { return a1 / a2; } @@ -149,11 +116,12 @@ namespace MultiArrayTools }; template - struct negate : public StaticFunctionBase, T> + struct negate : public StaticFunctionBase> { static constexpr bool FISSTATIC = true; - using StaticFunctionBase, T>::apply; - + using StaticFunctionBase>::apply; + typedef T value_type; + static inline T apply(T a) { return -a; @@ -173,60 +141,6 @@ namespace MultiArrayTools template using divides = dividesx; - /* - template - struct plus : public StaticFunctionBase, T, T> - { - static constexpr bool FISSTATIC = true; - using StaticFunctionBase, T, T>::apply; - - static inline T apply(T a1, T a2) - { - return a1 + a2; - } - - static inline T& selfApply(T& a1, const T& a2) - { - return a1 += a2; - } - }; - - template - struct minus : public StaticFunctionBase, T, T> - { - static constexpr bool FISSTATIC = true; - using StaticFunctionBase, T, T>::apply; - - static inline T apply(T a1, T a2) - { - return a1 - a2; - } - }; - - template - struct multiplies : public StaticFunctionBase, T, T> - { - static constexpr bool FISSTATIC = true; - using StaticFunctionBase, T, T>::apply; - - static inline T apply(T a1, T a2) - { - return a1 * a2; - } - }; - - template - struct divides : public StaticFunctionBase, T, T> - { - static constexpr bool FISSTATIC = true; - using StaticFunctionBase, T, T>::apply; - - static inline T apply(T a1, T a2) - { - return a1 / a2; - } - }; - */ // OPERATIONS (STATIC) template class function @@ -247,16 +161,28 @@ namespace MultiArrayTools return mF(args...); } + template + static inline auto xapply(const std::function& ff, const Tuple& tp, As... as) + { + if constexpr(N > 0){ + return xapply(ff, tp, std::get(tp), as...); + } + else { + return ff(std::get<0>(tp), as...); + } + } + inline R operator()(const std::tuple& args) { - return ArgPack::template mkd,std::tuple>>(mF, args); + return xapply(mF, args); } }; #include #define regFunc1(fff) template \ - struct x_##fff : public StaticFunctionBase, T> {\ + struct x_##fff : public StaticFunctionBase> {\ static constexpr bool FISSTATIC = true;\ + typedef T value_type; \ static inline T apply(T a){\ return fff(a); } }; @@ -271,35 +197,17 @@ namespace MultiArrayTools template static inline T apply(T a) { - return a * x_ipow::apply(a); + if constexpr(N > 0){ + return a * x_ipow::apply(a); + } + else { + return a; + } } }; - template <> - struct x_ipow<0> - { - static constexpr bool FISSTATIC = true; - - template - static inline T apply(T a) - { - return a; - } - }; - - /* - template - struct dynamic_function - { - static constexpr bool FISSTATIC = false; - - template - inline T apply(Us... args) - { - return f(args...); - } - }; - */ } // end namespace MultiArrayHelper - + +#include "arith.cc.h" + #endif diff --git a/src/include/operation_helper.h b/src/include/operation_helper.h deleted file mode 100644 index 4b4b002..0000000 --- a/src/include/operation_helper.h +++ /dev/null @@ -1,46 +0,0 @@ - -#ifndef __operation_helper_h__ -#define __operation_helper_h__ - -#include "multi_array_operation.h" - -namespace MultiArrayTools -{ - - template - class PseudoArray - { - size_t mThreadNum; - Slice<> mSl; - mutable ConstOperationRoot mOp; - - public: - - template - const SrcHolder> operator[](ET pos) const; - }; - - template - class SrcHolder - { - - TempHolder operator+(SrcHolder in) const; - // aso - }; - - template - class TempHolder - { - TempHolder operator+(SrcHolder in) const; - TempHolder operator+(TempHolder in) const; - }; - - template - class TarHolder - { - TarHolder& operator=(TempHolder in); - }; - -} // namespace MultiArrayTools - -#endif