remove all PackNum stuff from multi_array_operation
This commit is contained in:
parent
44f6149a23
commit
acda91d792
3 changed files with 87 additions and 37 deletions
|
@ -983,18 +983,42 @@ namespace MultiArrayTools
|
||||||
static_assert( not FISSTATIC, "using instance of static function" );
|
static_assert( not FISSTATIC, "using instance of static function" );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <size_t I, class OpFunction, class ETuple, class OpTuple, typename... Args>
|
||||||
template <size_t I, size_t J, class ET>
|
inline auto
|
||||||
inline auto Operation<T,OpFunction,Ops...>::getSubX(ET pos) const
|
mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, Args... args)
|
||||||
{
|
{
|
||||||
// somehow get rid of the second condition (should NOT be needed if everything is correct)
|
if constexpr(I == std::tuple_size<OpTuple>{}){
|
||||||
if constexpr(I == J or sizeof...(Ops)-1 == I){
|
if constexpr(OpFunction::FISSTATIC){
|
||||||
return std::get<J>(mOps.mOps).get(pos);
|
return OpFunction::apply(args...);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
typedef typename std::remove_reference<decltype(std::get<I>(mOps.mOps))>::type
|
(*f)(args...);
|
||||||
NextOpType;
|
}
|
||||||
return getSubX<I+1,J>(getX<NextOpType::SIZE>(pos));
|
}
|
||||||
|
else {
|
||||||
|
typedef typename std::remove_reference<decltype(std::get<I>(ops))>::type NextOpType;
|
||||||
|
return mkOpExpr<I+1>
|
||||||
|
( f, getX<NextOpType::SIZE>(pos), ops, args..., std::get<I>(ops).get(pos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I, typename V, class OpFunction, class ETuple, class OpTuple, typename... Args>
|
||||||
|
inline auto
|
||||||
|
mkVOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, Args... args)
|
||||||
|
{
|
||||||
|
if constexpr(I == std::tuple_size<OpTuple>{}){
|
||||||
|
if constexpr(OpFunction::FISSTATIC){
|
||||||
|
return VFunc<OpFunction>::apply(args...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto vf = mkVFuncPtr(f);
|
||||||
|
(*vf)(args...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
typedef typename std::remove_reference<decltype(std::get<I>(ops))>::type NextOpType;
|
||||||
|
return mkVOpExpr<I+1,V>( f, getX<NextOpType::SIZE>(pos), ops, args...,
|
||||||
|
std::get<I>(ops).template vget<V>(pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1002,33 +1026,31 @@ namespace MultiArrayTools
|
||||||
template <class ET>
|
template <class ET>
|
||||||
inline auto Operation<T,OpFunction,Ops...>::get(ET pos) const
|
inline auto Operation<T,OpFunction,Ops...>::get(ET pos) const
|
||||||
{
|
{
|
||||||
auto cre = [&](auto... args)
|
return mkOpExpr<0>(mF, pos, mOps.mOps);
|
||||||
{
|
|
||||||
if constexpr(OpFunction::FISSTATIC){
|
|
||||||
return OpFunction::apply(args...);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return (*mF)(args...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return MA_CFOR2(i,0,sizeof...(Ops),i+1,return getSub<i>(pos);,cre);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
template <typename V, class ET>
|
template <typename V, class ET>
|
||||||
inline auto Operation<T,OpFunction,Ops...>::vget(ET pos) const
|
inline auto Operation<T,OpFunction,Ops...>::vget(ET pos) const
|
||||||
{
|
{
|
||||||
typedef std::tuple<Ops...> OpTuple;
|
return mkVOpExpr<0,V>(mF, pos, mOps.mOps);
|
||||||
return PackNum<sizeof...(Ops)-1>::
|
}
|
||||||
template mkVOpExpr<SIZE,V,ET,OpTuple,VFunc<OpFunction>>(mkVFuncPtr(mF), pos, mOps.mOps); // implement!!!
|
|
||||||
|
template <size_t I, class OpTuple, class ETuple>
|
||||||
|
static inline void setOpPos(OpTuple& ot, const ETuple& et)
|
||||||
|
{
|
||||||
|
if constexpr(I != std::tuple_size<OpTuple>{}){
|
||||||
|
typedef typename std::remove_reference<decltype(std::get<I>(ot))>::type NextOpType;
|
||||||
|
std::get<I>( ot ).set( et );
|
||||||
|
setOpPos<I+1>(ot, getX<NextOpType::SIZE>(et));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
template <class ET>
|
template <class ET>
|
||||||
inline Operation<T,OpFunction,Ops...>& Operation<T,OpFunction,Ops...>::set(ET pos)
|
inline Operation<T,OpFunction,Ops...>& Operation<T,OpFunction,Ops...>::set(ET pos)
|
||||||
{
|
{
|
||||||
typedef std::tuple<Ops...> OpTuple;
|
setOpPos<0>(mOps.mOps,pos);
|
||||||
PackNum<sizeof...(Ops)-1>::template setOpPos<SIZE,OpTuple,ET>(mOps.mOps,pos);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -779,6 +779,42 @@ namespace MultiArrayTools
|
||||||
T const** data() const { assert(0); return nullptr; }
|
T const** data() const { assert(0); return nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
template <typename T>
|
||||||
|
struct TFold
|
||||||
|
{
|
||||||
|
TFold() = default;
|
||||||
|
TFold(const TFold& in) = default;
|
||||||
|
TFold& operator=(const TFold& in) = default;
|
||||||
|
TFold(TFold&& in) = default;
|
||||||
|
TFold& operator=(TFold&& in) = default;
|
||||||
|
explicit TFold(const T v) : val(v) {}
|
||||||
|
|
||||||
|
T val;
|
||||||
|
inline T& operator*() { return val; }
|
||||||
|
inline const T& operator*() const { return val; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
inline std::tuple<TFold<T1>,TFold<T2>> operator,(const TFold<T1>& a1, const TFold<T2>& a2)
|
||||||
|
{
|
||||||
|
return std::make_tuple(a1,a2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1, typename T2...>
|
||||||
|
inline std::tuple<TFold<T1>,TFold<T2>> operator,(const TFold<T1>& a1,
|
||||||
|
const std::tuple<TFold<T2>...>& a2)
|
||||||
|
{
|
||||||
|
return std::tuple_cat(std::make_tuple(a1),a2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T2, typename T1...>
|
||||||
|
inline std::tuple<TFold<T1>,TFold<T2>> operator,(const std::tuple<TFold<T1>...>& a1,
|
||||||
|
const TFold<T2>& a2)
|
||||||
|
{
|
||||||
|
return std::tuple_cat(a1,std::make_tuple(a2));
|
||||||
|
}
|
||||||
|
*/
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
class Operation : public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
|
class Operation : public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
|
||||||
{
|
{
|
||||||
|
@ -804,12 +840,6 @@ namespace MultiArrayTools
|
||||||
Operation(const Ops&... ops);
|
Operation(const Ops&... ops);
|
||||||
Operation(std::shared_ptr<OpFunction> ff, const Ops&... ops);
|
Operation(std::shared_ptr<OpFunction> ff, const Ops&... ops);
|
||||||
|
|
||||||
template <size_t I, size_t J, class ET>
|
|
||||||
inline auto getSubX(ET pos) const;
|
|
||||||
|
|
||||||
template <size_t J, class ET>
|
|
||||||
inline auto getSub(ET pos) const { return getSubX<0,J>(pos); }
|
|
||||||
|
|
||||||
template <class ET>
|
template <class ET>
|
||||||
inline auto get(ET pos) const;
|
inline auto get(ET pos) const;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,6 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MA_SFOR(i,beg,end,incr,expr) sfor<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ expr return 0; }, [&](auto f, auto next) { return 0; })
|
#define MA_SFOR(i,beg,end,incr,expr) sfor<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ expr return 0; }, [&](auto f, auto next) { return 0; })
|
||||||
|
@ -63,7 +62,6 @@ namespace MultiArrayTools
|
||||||
#define MA_SCRFOR(i,beg,end,decr,expr,conc) sfor<beg,end,-1>([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); })
|
#define MA_SCRFOR(i,beg,end,decr,expr,conc) sfor<beg,end,-1>([&](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<beg,end,-1>([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }, arg)
|
#define MA_SCRAFOR(i,beg,end,decr,expr,conc,arg) sfor<beg,end,-1>([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }, arg)
|
||||||
#define MA_CFOR(i,beg,end,incr,expr,cre) unpack<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ expr }, [&](auto... args) { return cre(args...); })
|
#define MA_CFOR(i,beg,end,incr,expr,cre) unpack<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ expr }, [&](auto... args) { return cre(args...); })
|
||||||
#define MA_CFOR2(i,beg,end,incr,expr,cre) unpack<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ expr }, cre)
|
|
||||||
|
|
||||||
#define MA_SCFOR_X(i,beg,end,incr,expr,conc) sfor<beg,end,0>([](auto i) constexpr { return incr; }, [](auto i){ return expr; }, [](auto f, auto next) { return f.conc(next); })
|
#define MA_SCFOR_X(i,beg,end,incr,expr,conc) sfor<beg,end,0>([](auto i) constexpr { return incr; }, [](auto i){ return expr; }, [](auto f, auto next) { return f.conc(next); })
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue