replace/remove static for macros

This commit is contained in:
Christian Zimmermann 2021-06-08 16:41:28 +02:00
parent 53362be499
commit c26fb133ae
8 changed files with 54 additions and 94 deletions

View file

@ -6,7 +6,7 @@ namespace MultiArrayTools
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp)
{
MA_SFOR(i,0,sizeof...(T)-1,i+1, out << std::get<i>(tp) << ", ";);
sfor_pn<0,sizeof...(T)-1>( [&](auto i){ out << std::get<i>(tp) << ", "; return 0; } );
out << std::get<sizeof...(T)-1>(tp);
return out;
}
@ -22,8 +22,7 @@ namespace MultiArrayTools
auto getIndex()
-> std::shared_ptr<typename RangeType::IndexType>
{
static_assert( RangeType::defaultable,
/*typeid(typename RangeType).name() + */" is not defaultable" );
static_assert( RangeType::defaultable, "Range not defaultable" );
static auto f = RangeType::factory();
static auto r = std::dynamic_pointer_cast<RangeType>( f.create() );
return std::make_shared<typename RangeType::IndexType>(r);

View file

@ -206,9 +206,9 @@ namespace MultiArrayTools
(*this) = in;
}
else {
MA_SCFOR2(i,0,sizeof...(SRanges),i+1,
std::get<i>(MAB::mRange->space()).get() == std::get<i>(in.mRange->space()).get(),
operator&&);
sfor_p<0,sizeof...(SRanges),0>
( [&](auto i) { return std::get<i>(MAB::mRange->space()).get() == std::get<i>(in.mRange->space()).get(); },
[&](auto a, auto b) { return a and b; });
for(size_t i = 0; i != mCont.size(); ++i){
mCont[i] += in.mCont[i];
}
@ -223,9 +223,9 @@ namespace MultiArrayTools
(*this) = in;
}
else {
MA_SCFOR2(i,0,sizeof...(SRanges),i+1,
std::get<i>(MAB::mRange->space()).get() == std::get<i>(in.mRange->space()).get(),
operator&&);
sfor_p<0,sizeof...(SRanges),0>
( [&](auto i) { return std::get<i>(MAB::mRange->space()).get() == std::get<i>(in.mRange->space()).get(); },
[&](auto a, auto b) { return a and b; });
for(size_t i = 0; i != mCont.size(); ++i){
mCont[i] -= in.mCont[i];
}

View file

@ -216,7 +216,6 @@ namespace MultiArrayTools
template <typename T, class IOp, class Target, class OpClass, OpIndexAff OIA>
inline DExt AssignmentExpr<T,IOp,Target,OpClass,OIA>::dExtension() const
{
CHECK;
return nullptr; //???!!!
}
@ -243,7 +242,10 @@ namespace MultiArrayTools
template <class Expr>
auto MOp<T,Ops...>::loop(Expr exp) const
{
return MA_SCRAFOR(i,sizeof...(Ops),0,i-1,std::get<i>(mOps.mOps),loop,exp);
return sfor_m<sizeof...(Ops),0>
( [&](auto i){ return std::get<i>(mOps.mOps); },
[&](auto f, auto next) { return f.loop(next); },
exp );
}
template <typename T, class... Ops>
@ -331,7 +333,6 @@ namespace MultiArrayTools
{
mIndex(indices...);
mDataPtr = mOrigDataPtr + mIndex.pos();
//mOff = mIndex.pos();
}
template <typename T, class... Ranges>
@ -342,21 +343,19 @@ namespace MultiArrayTools
mIndex( ind )
{
mDataPtr = mOrigDataPtr + mIndex.pos();
//mOff = mIndex.pos();
}
template <typename T, class... Ranges>
template <class ET>
inline const T& ConstOperationRoot<T,Ranges...>::get(ET pos) const
{
return mDataPtr[pos.val()/*+mOff*/];
return mDataPtr[pos.val()];
}
template <typename T, class... Ranges>
template <typename V, class ET>
inline const V& ConstOperationRoot<T,Ranges...>::vget(ET pos) const
{
//VCHECK(pos.val());
return *(reinterpret_cast<const V*>(mDataPtr+pos.val()));
}
@ -364,8 +363,6 @@ namespace MultiArrayTools
template <class ET>
inline ConstOperationRoot<T,Ranges...>& ConstOperationRoot<T,Ranges...>::set(ET pos)
{
//mIndex = pos.val();
//mDataPtr = mOrigDataPtr + mIndex.pos();
mDataPtr = mOrigDataPtr + pos.val();
return *this;
}
@ -373,8 +370,6 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
const T* ConstOperationRoot<T,Ranges...>::data() const
{
//auto i = mIndex;
//return mOrigDataPtr/* + i().pos()*/;
return mDataPtr;
}
@ -452,9 +447,6 @@ namespace MultiArrayTools
inline typename MetaOperationRoot<Range>::value_type
MetaOperationRoot<Range>::get(ET pos) const
{
//VCHECK(pos.val());
//VCHECK(mDataPtr);
//VCHECK(mDataPtr[pos.val()])
return (mWorkIndex = pos.val()).meta();
}
@ -471,7 +463,6 @@ namespace MultiArrayTools
template <class ET>
inline MetaOperationRoot<Range>& MetaOperationRoot<Range>::set(ET pos)
{
//(*mIndex) = pos.val();
return *this;
}
@ -646,7 +637,6 @@ namespace MultiArrayTools
OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::operator+=(const OpClass& in)
{
VExec<OpClass::VABLE>::template exec<xxxplus>(*this,in);
//plus(in)();
return *this;
}
@ -673,7 +663,6 @@ namespace MultiArrayTools
template <typename V, class ET>
inline V& OperationRoot<T,Ranges...>::vget(ET pos) const
{
//VCHECK(pos.val());
return *(reinterpret_cast<V*>(mDataPtr+pos.val()));
}
@ -681,8 +670,6 @@ namespace MultiArrayTools
template <class ET>
inline OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::set(ET pos)
{
//mIndex = pos.val();
//mDataPtr = mOrigDataPtr + mIndex.pos();
mDataPtr = mOrigDataPtr + pos.val();
return *this;
}
@ -703,8 +690,6 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
T* OperationRoot<T,Ranges...>::data() const
{
//auto i = mIndex;
//return mOrigDataPtr/* + i().pos()*/;
return mDataPtr;
}
@ -1063,7 +1048,10 @@ namespace MultiArrayTools
template <class Expr>
auto Operation<T,OpFunction,Ops...>::loop(Expr exp) const
{
return MA_SCRAFOR(i,sizeof...(Ops),0,i-1,std::get<i>(mOps.mOps),loop,exp);
return sfor_m<sizeof...(Ops),0>
( [&](auto i){ return std::get<i>(mOps.mOps); },
[&](auto f, auto next) { return f.loop(next); },
exp );
}

View file

@ -310,7 +310,9 @@ namespace MultiArrayTools
template <class... Ops>
auto OperationTuple<Ops...>::rootSteps(std::intptr_t iPtrNum) const
{
return MA_SCFOR(i,0,sizeof...(Ops),i+1,std::get<i>(mOps).rootSteps(iPtrNum),extend);
return sfor_p<0,sizeof...(Ops)>
( [&](auto i){ return std::get<i>(mOps).rootSteps(iPtrNum); },
[&](auto f, auto next) { return f.extend(next); } );
}
template <typename T, class... Ops>
@ -778,42 +780,6 @@ namespace MultiArrayTools
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>
class Operation : public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
{

View file

@ -243,9 +243,12 @@ namespace MultiArrayTools
SliceDef<T,SRanges...>& SliceDef<T,SRanges...>::operator=(const OperationRoot<T,ORanges...>& op)
{
std::array<size_t,sizeof...(SRanges)+1> blocks;
MA_SFOR(i,0,sizeof...(SRanges),i+1,
std::get<i+1>(blocks) = op.rootSteps(reinterpret_cast<std::intptr_t>
( mIndex.template getPtr<i>().get())).val(););
sfor_pn<0,sizeof...(SRanges)>
( [&](auto i) {
std::get<i+1>(blocks) =
op.rootSteps(reinterpret_cast<std::intptr_t>
( mIndex.template getPtr<i>().get())).val();
return 0; } );
mSl.format(blocks);
mSl.mData = op.data();
return *this;
@ -265,9 +268,12 @@ namespace MultiArrayTools
ConstSliceDef<T,SRanges...>& ConstSliceDef<T,SRanges...>::operator=(const ConstOperationRoot<T,ORanges...>& op)
{
std::array<size_t,sizeof...(SRanges)+1> blocks;
MA_SFOR(i,0,sizeof...(SRanges),i+1,
std::get<i+1>(blocks) = op.rootSteps(reinterpret_cast<std::intptr_t>
( mIndex.template getPtr<i>().get())).val(););
sfor_pn<0,sizeof...(SRanges)>
( [&](auto i) {
std::get<i+1>(blocks) =
op.rootSteps(reinterpret_cast<std::intptr_t>
( mIndex.template getPtr<i>().get())).val();
return 0; } );
mSl.format(blocks);
mSl.mData = op.data();
return *this;
@ -278,9 +284,12 @@ namespace MultiArrayTools
ConstSliceDef<T,SRanges...>& ConstSliceDef<T,SRanges...>::operator=(const OperationRoot<T,ORanges...>& op)
{
std::array<size_t,sizeof...(SRanges)+1> blocks;
MA_SFOR(i,0,sizeof...(SRanges),i+1,
std::get<i+1>(blocks) = op.rootSteps(reinterpret_cast<std::intptr_t>
( mIndex.template getPtr<i>().get())).val(););
sfor_pn<0,sizeof...(SRanges)>
( [&](auto i) {
std::get<i+1>(blocks) =
op.rootSteps(reinterpret_cast<std::intptr_t>
( mIndex.template getPtr<i>().get())).val();
return 0; } );
mSl.format(blocks);
mSl.mData = op.data();
return *this;

View file

@ -112,9 +112,12 @@ namespace MultiArrayTools
{
Slice<T,SRanges...> out(ind->range()->space(), &*ind);
std::array<size_t,sizeof...(SRanges)+1> ff;
MA_SFOR(i,0,sizeof...(SRanges),i+1,
std::get<i+1>(ff) = op.rootSteps(reinterpret_cast<std::intptr_t>
( ind.template getPtr<i>().get())).val(););
sfor_pn<0,sizeof...(SRanges)>
( [&](auto i) {
std::get<i+1>(ff) =
op.rootSteps(reinterpret_cast<std::intptr_t>
( ind.template getPtr<i>().get())).val();
return 0; } );
out.format(ff);
return out;
}
@ -145,9 +148,12 @@ namespace MultiArrayTools
{
ConstSlice<T,SRanges...> out(ind->range()->space(), &*ind);
std::array<size_t,sizeof...(SRanges)+1> ff;
MA_SFOR(i,0,sizeof...(SRanges),i+1,
std::get<i+1>(ff) = op.rootSteps(reinterpret_cast<std::intptr_t>
( ind.template getPtr<i>().get())).val(););
sfor_pn<0,sizeof...(SRanges)>
( [&](auto i) {
std::get<i+1>(ff) =
op.rootSteps(reinterpret_cast<std::intptr_t>
( ind.template getPtr<i>().get())).val();
return 0; } );
out.format(ff);
return out;
}

View file

@ -169,15 +169,4 @@ 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_SCFOR(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_SCFOR2(i,beg,end,incr,expr,conc) sfor<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, [&](auto a, auto b) { return conc(a,b); })
#define MA_SCFOR3(i,beg,end,incr,expr,conc) sfor<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ return expr; }, conc)
#define MA_SRFOR(i,beg,end,decr,expr) sfor<beg,end,-1>([&](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<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_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_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); })
#endif

View file

@ -33,7 +33,10 @@ namespace MultiArrayTools
inline auto apply(const MultiArray<T,Ranges...>& ma)
-> OperationRoot<T,Ranges...>
{
return MA_CFOR(i,0,sizeof...(Ranges),i+1,return std::get<i>(ituple);,ma);
return unpack<0,sizeof...(Ranges),0>
( [&](auto i) constexpr { return i+1; },
[&](auto i){ return std::get<i>(ituple); },
[&](auto... args) { return ma(args...); });
}
private: