add utilities in xfor.h + fix SIZE in SubExpr

This commit is contained in:
Christian Zimmermann 2019-07-10 18:14:50 +02:00
parent a2d67ef78c
commit b79f010c87
2 changed files with 30 additions and 7 deletions

View file

@ -13,6 +13,13 @@ namespace MultiArrayHelper
template <size_t N> template <size_t N>
struct NN struct NN
{ {
template <class LTp>
static inline constexpr size_t LSIZE()
{
typedef typename std::tuple_element<N,LTp>::type LType;
return LType::SIZE + NN<N-1>::template LSIZE<LTp>();
}
template <class LTp> template <class LTp>
static inline constexpr size_t lsize(const LTp& ltp) static inline constexpr size_t lsize(const LTp& ltp)
{ {
@ -44,12 +51,19 @@ namespace MultiArrayHelper
std::get<N>(ltp)(std::get<N>(umpos)*mpos, pos.template nn<NN<N-1>::lsize(ltp)>()); std::get<N>(ltp)(std::get<N>(umpos)*mpos, pos.template nn<NN<N-1>::lsize(ltp)>());
return 0; return 0;
} }
}; };
template <> template <>
struct NN<0> struct NN<0>
{ {
template <class LTp>
static inline constexpr size_t LSIZE()
{
typedef typename std::tuple_element<0,LTp>::type LType;
return LType::SIZE;
}
template <class LTp> template <class LTp>
static inline constexpr size_t lsize(const LTp& ltp) static inline constexpr size_t lsize(const LTp& ltp)
{ {
@ -88,7 +102,7 @@ namespace MultiArrayHelper
private: private:
static constexpr size_t LTpSize = std::tuple_size<LTp>::value; static constexpr size_t LTpSize = std::tuple_size<LTp>::value;
static constexpr size_t VarTpSize = std::tuple_size<VarTp>::value; static constexpr size_t VarTpSize = std::tuple_size<VarTp>::value;
OpTp mOpTp; OpTp mOpTp;
IndTp mIndTp; IndTp mIndTp;
@ -99,7 +113,8 @@ namespace MultiArrayHelper
std::array<size_t,VarTpSize> mSetzero; // set variable to zero after each cycle std::array<size_t,VarTpSize> mSetzero; // set variable to zero after each cycle
public: public:
static constexpr size_t SIZE = NN<LTpSize-1>::lsize(std::declval<LTp>()); //static constexpr size_t SIZE = NN<LTpSize-1>::lsize(std::declval<LTp>());
static constexpr size_t SIZE = NN<LTpSize-1>::template LSIZE<LTp>();
static constexpr bool CONT = false; static constexpr bool CONT = false;
typedef decltype(NN<LTpSize-1>::rootSteps(mLTp)) ExtType; typedef decltype(NN<LTpSize-1>::rootSteps(mLTp)) ExtType;
@ -108,7 +123,7 @@ namespace MultiArrayHelper
ILoop(const OpTp& opTp, const IndTp& indTp, const VarTp& varTp, const LTp& lTp, ILoop(const OpTp& opTp, const IndTp& indTp, const VarTp& varTp, const LTp& lTp,
const std::array<size_t,LTpSize>& umpos, const std::array<size_t,VarTpSize>& setzero) : const std::array<size_t,LTpSize>& umpos, const std::array<size_t,VarTpSize>& setzero) :
mOpTp(opTp), mIndTp(indTp), mVarTp(varTp), mLTp(lTp), mUmpos(umpos), mSetzero(setzero) {} mOpTp(opTp), mIndTp(indTp), mVarTp(varTp), mLTp(lTp), mUmpos(umpos), mSetzero(setzero) {}
inline size_t operator()(size_t mpos, ExtType pos) inline size_t operator()(size_t mpos, ExtType pos)
{ {
NN<VarTpSize-1>::zero(mVarTp, mSetzero); NN<VarTpSize-1>::zero(mVarTp, mSetzero);
@ -122,7 +137,11 @@ namespace MultiArrayHelper
{ {
return NN<LTpSize-1>::rootSteps(mLTp,i); return NN<LTpSize-1>::rootSteps(mLTp,i);
} }
VarTp& var() const
{
return mVarTp;
}
}; };
template <size_t N> template <size_t N>
@ -236,7 +255,11 @@ namespace MultiArrayHelper
{ {
return mL.rootSteps(i); return mL.rootSteps(i);
} }
auto var() const
{
return mL.var();
}
}; };
} }

View file

@ -161,7 +161,7 @@ namespace MultiArrayHelper
typedef ExpressionBase EB; typedef ExpressionBase EB;
static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE; static constexpr size_t SIZE = Expr::SIZE + 1;
SubExpr(const SubExpr& in) = default; SubExpr(const SubExpr& in) = default;
SubExpr& operator=(const SubExpr& in) = default; SubExpr& operator=(const SubExpr& in) = default;