im com + remove Getter class

This commit is contained in:
Christian Zimmermann 2021-04-11 16:34:01 +02:00
parent 1f663e0b76
commit fe22b1ad80
7 changed files with 279 additions and 247 deletions

View file

@ -49,7 +49,7 @@ namespace MultiArrayTools
if(pos != mIndPtr->max()){
const ExtType npos = last + mExt*pos;
const size_t mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
mExpr(mnpos, getX<NEXT>( npos ) );
}
}
@ -63,7 +63,7 @@ namespace MultiArrayTools
if(pos != mIndPtr->max()){
const ExtType npos = last + mExt*pos;
const size_t mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
mExpr(mnpos, getX<NEXT>( npos ));
}
}

View file

@ -226,29 +226,27 @@ namespace MultiArrayTools
template <typename T, class... Ops>
inline size_t MOp<T,Ops...>::get(ExtType last) const
{
return RootSumN<sizeof...(Ops)-1>::get(last,mOps);
return RootSumN<sizeof...(Ops)-1>::get(last,mOps.mOps);
}
template <typename T, class... Ops>
inline MOp<T,Ops...>& MOp<T,Ops...>::set(ExtType last)
{
RootSumN<sizeof...(Ops)-1>::set(last,mOps);
RootSumN<sizeof...(Ops)-1>::set(last,mOps.mOps);
return *this;
}
template <typename T, class... Ops>
template <class Expr>
auto MOp<T,Ops...>::loop(Expr exp) const
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp))
{
return PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp);
return MA_SCRAFOR(i,sizeof...(Ops),0,i-1,std::get<i>(mOps.mOps),loop,exp);
}
template <typename T, class... Ops>
auto MOp<T,Ops...>::rootSteps(std::intptr_t iPtrNum) const
auto MOp<T,Ops...>::rootSteps(std::intptr_t iPtrNum) const -> ExtType
{
return MA_SCFOR(i,0,sizeof...(Ops),i+1,std::get<i>(mOps).rootSteps(iPtrNum),extend);
//return RootSumN<sizeof...(Ops)-1>::rootSteps(mOps,iPtrNum);
return mOps.rootSteps(iPtrNum);
}
template <class OpClass, class NextExpr>
@ -989,7 +987,7 @@ namespace MultiArrayTools
{
typedef std::tuple<Ops...> OpTuple;
return PackNum<sizeof...(Ops)-1>::
template mkOpExpr<SIZE,ET,OpTuple,OpFunction>(mF, pos, mOps);
template mkOpExpr<SIZE,ET,OpTuple,OpFunction>(mF, pos, mOps.mOps);
}
template <typename T, class OpFunction, class... Ops>
@ -998,7 +996,7 @@ namespace MultiArrayTools
{
typedef std::tuple<Ops...> OpTuple;
return PackNum<sizeof...(Ops)-1>::
template mkVOpExpr<SIZE,V,ET,OpTuple,VFunc<OpFunction>>(mkVFuncPtr(mF), pos, mOps); // implement!!!
template mkVOpExpr<SIZE,V,ET,OpTuple,VFunc<OpFunction>>(mkVFuncPtr(mF), pos, mOps.mOps); // implement!!!
}
template <typename T, class OpFunction, class... Ops>
@ -1006,21 +1004,22 @@ namespace MultiArrayTools
inline Operation<T,OpFunction,Ops...>& Operation<T,OpFunction,Ops...>::set(ET pos)
{
typedef std::tuple<Ops...> OpTuple;
PackNum<sizeof...(Ops)-1>::template setOpPos<SIZE,OpTuple,ET>(mOps,pos);
PackNum<sizeof...(Ops)-1>::template setOpPos<SIZE,OpTuple,ET>(mOps.mOps,pos);
return *this;
}
template <typename T, class OpFunction, class... Ops>
auto Operation<T,OpFunction,Ops...>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return MA_SCFOR(i,0,sizeof...(Ops),i+1,std::get<i>(mOps).rootSteps(iPtrNum),extend);
return mOps.rootSteps(iPtrNum);
}
template <typename T, class OpFunction, class... Ops>
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),loop,exp);
return MA_SCRAFOR(i,sizeof...(Ops),0,i-1,std::get<i>(mOps.mOps),loop,exp);
}

View file

@ -300,18 +300,32 @@ namespace MultiArrayTools
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
using AddExpr = AssignmentExpr<T,IPlus<T>,Target,OpClass,OIA>;
template <class... Ops>
struct OperationTuple
{
OperationTuple(const Ops&... ops) : mOps(ops...) {}
std::tuple<Ops...> mOps;
auto rootSteps(std::intptr_t iPtrNum) const;
};
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);
}
template <typename T, class... Ops>
class MOp
{
private:
MOp() = default;
std::tuple<Ops...> mOps;
OperationTuple<Ops...> mOps;
public:
static constexpr size_t LAYER = 0;
static constexpr size_t NHLAYER = 0;
static constexpr size_t SIZE = (... + Ops::SIZE);
typedef decltype(RootSumN<sizeof...(Ops)-1>::rootSteps(mOps,0) ) ExtType;
typedef decltype(mOps.rootSteps(0)) ExtType;
MOp(const Ops&... exprs);
@ -326,11 +340,10 @@ namespace MultiArrayTools
inline size_t vget(ExtType last) const { return get(last); }
inline MOp& set(ExtType last);
auto rootSteps(std::intptr_t iPtrNum = 0) const;
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
template <class Expr>
auto loop(Expr exp) const
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp));
auto loop(Expr exp) const;
T* data() const { assert(0); return nullptr; }
@ -782,8 +795,9 @@ namespace MultiArrayTools
(... and (Ops::VABLE and std::is_same<T,typename Ops::value_type>::value));
private:
std::tuple<Ops...> mOps;
OperationTuple<Ops...> mOps;
std::shared_ptr<OpFunction> mF; // only if non-static
typedef decltype(mOps.rootSteps(0)) ExtType;
public:
@ -799,7 +813,8 @@ namespace MultiArrayTools
template <class ET>
inline Operation& set(ET pos);
auto rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
auto rootSteps(std::intptr_t iPtrNum = 0) const
-> ExtType; // nullptr for simple usage with decltype
template <class Expr>
auto loop(Expr exp) const;

View file

@ -76,9 +76,9 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType;
static_assert(LAST >= NextOpType::SIZE, "inconsistent array positions");
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
typedef decltype(std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos ))) ArgT;
typedef decltype(std::get<N>(ops).get(getX<NEXT>( pos ))) ArgT;
return PackNum<N-1>::template mkOpExpr<NEXT,ETuple,OpTuple,OpFunction,ArgT,Args...>
( f, pos, ops, std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos )), args...);
( f, pos, ops, std::get<N>(ops).get(getX<NEXT>( pos )), args...);
}
template <size_t LAST, typename V, class ETuple, class OpTuple, class OpFunction, typename... Args>
@ -87,9 +87,9 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType;
static_assert(LAST >= NextOpType::SIZE, "inconsistent array positions");
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
typedef decltype(std::get<N>(ops).template vget<V>(Getter<NEXT>::template getX<ETuple>( pos ))) ArgT;
typedef decltype(std::get<N>(ops).template vget<V>(getX<NEXT>( pos ))) ArgT;
return PackNum<N-1>::template mkVOpExpr<NEXT,V,ETuple,OpTuple,OpFunction,ArgT,Args...>
( f, pos, ops, std::get<N>(ops).template vget<V>(Getter<NEXT>::template getX<ETuple>( pos )), args...);
( f, pos, ops, std::get<N>(ops).template vget<V>(getX<NEXT>( pos )), args...);
}
template <class OpTuple, class Expr>
@ -132,7 +132,7 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(std::get<N>(ot))>::type NextOpType;
static_assert(LAST >= NextOpType::SIZE, "inconsistent array positions");
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
std::get<N>( ot ).set( Getter<NEXT>::template getX<ETuple>( et ) );
std::get<N>( ot ).set( getX<NEXT>( et ) );
PackNum<N-1>::template setOpPos<NEXT,OpTuple,ETuple>(ot, et);
}
};
@ -174,9 +174,8 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(std::get<0>(ops))>::type NextOpType;
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
static_assert(NEXT == 0, "inconsistent array positions");
typedef decltype(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos ))) ArgT;
return Application<OpFunction::FISSTATIC>::template apply<OpFunction,ArgT,Args...>(f, std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
//return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
typedef decltype(std::get<0>(ops).get(getX<0>( pos ))) ArgT;
return Application<OpFunction::FISSTATIC>::template apply<OpFunction,ArgT,Args...>(f, std::get<0>(ops).get(getX<0>( pos )), args...);
}
template <size_t LAST, typename V, class ETuple, class OpTuple, class OpFunction, typename... Args>
@ -185,8 +184,8 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(std::get<0>(ops))>::type NextOpType;
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
static_assert(NEXT == 0, "inconsistent array positions");
typedef decltype(std::get<0>(ops).template vget<V>(Getter<0>::template getX<ETuple>( pos ))) ArgT;
return Application<OpFunction::FISSTATIC>::template apply<OpFunction,ArgT,Args...>(f, std::get<0>(ops).template vget<V>(Getter<0>::template getX<ETuple>( pos )), args...);
typedef decltype(std::get<0>(ops).template vget<V>(getX<0>( pos ))) ArgT;
return Application<OpFunction::FISSTATIC>::template apply<OpFunction,ArgT,Args...>(f, std::get<0>(ops).template vget<V>(getX<0>( pos )), args...);
}
template <class OpTuple, class Expr>
@ -229,7 +228,7 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(std::get<0>(ot))>::type NextOpType;
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
static_assert(NEXT == 0, "inconsistent array positions");
std::get<0>( ot ).set( Getter<NEXT>::template getX<ETuple>( et ) );
std::get<0>( ot ).set( getX<NEXT>( et ) );
}
};

View file

@ -50,23 +50,12 @@ 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(BEG == END){
return create(args...);
}
else {
return sfor<incr(idx),END,OFF>::unpack(incr, f, create, args..., tmp);
}
};
template <size_t END, int OFF>
struct sfor<END,END,OFF>
{
template <typename Incr, typename F, typename Conc>
static inline auto exec(Incr incr, F f, Conc conc)
{
return 0;
}
template <typename Incr, typename F, typename Create, typename... Args>
static inline auto unpack(Incr incr, F f, Create create, const Args&... args)
{
return create(args...);
}
};
}
@ -78,4 +67,6 @@ namespace MultiArrayTools
#define MA_SCRAFOR(i,beg,end,decr,expr,conc,arg) sfor<beg,end,-1>::exec([&](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) sfor<beg,end,0>::unpack([&](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>::exec([](auto i) constexpr { return incr; }, [](auto i){ return expr; }, [](auto f, auto next) { return f.conc(next); })
#endif

View file

@ -7,42 +7,90 @@
namespace MultiArrayHelper
{
template <size_t I>
struct Getter
{
template <class ExtType>
static inline size_t get(const ExtType& et)
{
return Getter<I-1>::get(et.next());
}
template <class ExtType>
static inline auto getX(const ExtType& et)
-> decltype(Getter<I-1>::getX(et.next()))
{
return Getter<I-1>::getX(et.next());
}
};
template <>
struct Getter<0>
{
template <class ExtType>
static inline size_t get(const ExtType& et)
{
return et.get();
}
template <class ExtType>
static inline auto getX(const ExtType& et)
-> ExtType
{
return et;
}
};
struct None;
class ExtBase
{
public:
ExtBase() = default;
ExtBase(const ExtBase& in) = default;
ExtBase(ExtBase&& in) = default;
ExtBase& operator=(const ExtBase& in) = default;
ExtBase& operator=(ExtBase&& in) = default;
virtual size_t size() const = 0;
virtual const size_t& val() const = 0;
//virtual size_t rootSteps() const = 0;
virtual bool operator==(const ExtBase& in) const = 0;
virtual bool operator==(size_t in) const = 0;
virtual std::shared_ptr<ExtBase> operator+(const ExtBase& in) const = 0;
virtual std::shared_ptr<ExtBase> operator*(size_t in) const = 0;
virtual void zero() = 0;
virtual std::shared_ptr<ExtBase> deepCopy() const = 0;
template <class ExtType>
const ExtType& expl() const;
virtual std::string stype() const = 0;
};
typedef std::shared_ptr<ExtBase> DExt;
template <class ExtType>
class ExtT : public ExtBase
{
private:
ExtType mExt;
public:
static constexpr size_t SIZE = ExtType::SIZE;
static constexpr size_t NUM = ExtType::NUM;
ExtT() = default;
ExtT(const ExtT& in) = default;
ExtT(ExtT&& in) = default;
ExtT& operator=(const ExtT& in) = default;
ExtT& operator=(ExtT&& in) = default;
ExtT(const ExtType& in) : mExt(in) {}
virtual std::shared_ptr<ExtBase> deepCopy() const override final { return std::make_shared<ExtT<ExtType>>(mExt); }
virtual size_t size() const override final { return sizeof(ExtType)/sizeof(size_t); }
//virtual size_t size() const override final { return ExtType::MExtSize(); }
//virtual size_t rootSteps() const override final;
const ExtType& ext() const { return mExt; }
virtual const size_t& val() const override final { return mExt.val(); }
virtual void zero() override final { mExt.zero(); }
virtual bool operator==(const ExtBase& in) const override final
{ return mExt == dynamic_cast<const ExtT<ExtType>&>(in).mExt; }
virtual bool operator==(size_t in) const override final
{ return mExt == in; }
virtual DExt operator+(const ExtBase& in) const override final
{ return std::make_shared<ExtT<ExtType>>( mExt + dynamic_cast<const ExtT<ExtType>&>(in).mExt ); }
virtual DExt operator*(size_t in) const override final
{ return std::make_shared<ExtT<ExtType>>( mExt * in ); }
virtual std::string stype() const override final { return std::string("T[") + mExt.stype() + "]"; }
};
//class DExtT;
template <class ExtType>
DExt mkDExt(const ExtT<ExtType>& in)
{
return std::make_shared<ExtT<ExtType>>(in);
}
template <class ExtType>
ExtT<ExtType> mkExtT(const ExtType& in)
{
return ExtT<ExtType>(in);
}
template <class X>
class MExt
{
@ -82,9 +130,7 @@ namespace MultiArrayHelper
inline const X& next() const;
template <size_t N>
inline auto nn() const
-> decltype(Getter<N>::getX(*this))
{ return Getter<N>::getX(*this); }
inline auto nn() const;
inline bool operator==(const MExt& in) const
{
@ -194,9 +240,7 @@ namespace MultiArrayHelper
inline void zero();
template <size_t N>
inline auto nn() const
-> decltype(Getter<N>::getX(*this))
{ return Getter<N>::getX(*this); }
inline auto nn() const;
inline MExt operator+(const MExt& in) const;
inline MExt operator+(const None& in) const;
@ -210,7 +254,124 @@ namespace MultiArrayHelper
};
template <class X>
class DExtTX
{
private:
mutable DExt mDExt = nullptr;
X mNext;
template <class Y>
friend class DExtTX;
public:
static constexpr size_t NUM = X::SIZE;
static constexpr size_t SIZE = NUM + 1;
DExtTX() { mDExt = std::make_shared<ExtT<None>>(); }
DExtTX(const DExtTX& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
explicit DExtTX(const DExt& in) : mDExt(in) {}
/*
template <class Y>
DExtTX& operator=(const Y& y) { mDExt = std::make_shared<ExtT<Y>>(y); return *this; }
template <class Y>
DExtTX(const Y& y) : mDExt(std::make_shared<ExtT<Y>>(y)) {}
*/
bool operator==(const DExtTX& in) const
{ return *mDExt == *in.mDExt and mNext == in.mNext; }
bool operator==(size_t in) const
{ return *mDExt == in and mNext == in; }
template <class Y>
DExtTX(const DExtTX<Y>& in) : mDExt(in.mDExt), mNext(in.mNext) {}
DExtTX(const DExt& y, const X& x) : mDExt(y->deepCopy()),
mNext(x) {}
virtual size_t size() const { return mDExt->size(); }
inline const DExt& get() const { return mDExt; }
inline DExtTX<None> reduce() const { return DExtTX<None>(mDExt,None(0)); }
inline DExtTX operator+(const DExtTX& in) const
{ if (not mDExt) return in; else return DExtTX( (*mDExt) + (*in.mDExt), mNext + in.mNext ); }
inline DExtTX operator*(size_t in) const
{ if (not mDExt) return *this; else return DExtTX((*mDExt) * in, mNext * in); }
template <class ExtType>
inline const ExtType& expl() const
{ if(mDExt == nullptr) mDExt = std::make_shared<ExtT<ExtType>>(); assert(mDExt != nullptr); return mDExt->expl<ExtType>(); }
template <class Y>
inline auto extend(const Y& y) const -> DExtTX<decltype(mNext.extend(y))>
{ return DExtTX<decltype(mNext.extend(y))>(mDExt, mNext.extend(y)); }
inline const size_t& val() const { return mDExt->val(); }
inline const X& next() const { return mNext; }
inline void zero() { mDExt->zero(); }
template <size_t N>
inline auto nn() const;
std::string stype() const { return std::string("D[") + mDExt->stype() + "," + mNext.stype() + "]"; }
};
typedef DExtTX<None> DExtT;
inline MExt<None> mkExt(size_t s) { return MExt<None>(s); }
template <size_t I, class X>
auto getX(const MExt<X>& et)
{
if constexpr(I == 0){
return et;
}
else {
return getX<I-1>(et.next());
}
}
template <size_t I, class X>
auto getX(const DExtTX<X>& et)
{
if constexpr(I == 0){
return et;
}
else {
return getX<I-1>(et.next());
}
}
template <size_t I>
auto getX(const None& et)
{
static_assert(I == 0);
return et;
}
template <size_t I, class X>
size_t get(const MExt<X>& et)
{
return getX<I>(et).get();
}
template <size_t I, class X>
size_t get(const DExtTX<X>& et)
{
return getX<I>(et).get();
}
template <size_t I>
size_t get(const None& et)
{
return getX<I>(et).get();
}
} // end namespace MultiArrayHelper
@ -263,6 +424,13 @@ namespace MultiArrayHelper
mNext.zero();
}
template <class X>
template <size_t N>
inline auto MExt<X>::nn() const
{
return getX<N>(*this);
}
template <class X>
inline MExt<X> MExt<X>::operator+(const MExt<X>& in) const
{
@ -312,6 +480,12 @@ namespace MultiArrayHelper
mExt = 0u;
}
template <size_t N>
inline auto MExt<None>::nn() const
{
return getX<N>(*this);
}
inline const size_t& MExt<None>::val() const
{
return mExt;
@ -334,6 +508,12 @@ namespace MultiArrayHelper
return MExt<None>(mExt * in);
}
template <class X>
template <size_t N>
inline auto DExtTX<X>::nn() const
{
return getX<N>(*this);
}
} // end namespace MultiArrayHelper

View file

@ -23,159 +23,7 @@ namespace MultiArrayHelper
//typedef std::pair<size_t const*,size_t> DExt;
class ExtBase
{
public:
ExtBase() = default;
ExtBase(const ExtBase& in) = default;
ExtBase(ExtBase&& in) = default;
ExtBase& operator=(const ExtBase& in) = default;
ExtBase& operator=(ExtBase&& in) = default;
virtual size_t size() const = 0;
virtual const size_t& val() const = 0;
//virtual size_t rootSteps() const = 0;
virtual bool operator==(const ExtBase& in) const = 0;
virtual bool operator==(size_t in) const = 0;
virtual std::shared_ptr<ExtBase> operator+(const ExtBase& in) const = 0;
virtual std::shared_ptr<ExtBase> operator*(size_t in) const = 0;
virtual void zero() = 0;
virtual std::shared_ptr<ExtBase> deepCopy() const = 0;
template <class ExtType>
const ExtType& expl() const;
virtual std::string stype() const = 0;
};
typedef std::shared_ptr<ExtBase> DExt;
template <class ExtType>
class ExtT : public ExtBase
{
private:
ExtType mExt;
public:
static constexpr size_t SIZE = ExtType::SIZE;
static constexpr size_t NUM = ExtType::NUM;
ExtT() = default;
ExtT(const ExtT& in) = default;
ExtT(ExtT&& in) = default;
ExtT& operator=(const ExtT& in) = default;
ExtT& operator=(ExtT&& in) = default;
ExtT(const ExtType& in) : mExt(in) {}
virtual std::shared_ptr<ExtBase> deepCopy() const override final { return std::make_shared<ExtT<ExtType>>(mExt); }
virtual size_t size() const override final { return sizeof(ExtType)/sizeof(size_t); }
//virtual size_t size() const override final { return ExtType::MExtSize(); }
//virtual size_t rootSteps() const override final;
const ExtType& ext() const { return mExt; }
virtual const size_t& val() const override final { return mExt.val(); }
virtual void zero() override final { mExt.zero(); }
virtual bool operator==(const ExtBase& in) const override final
{ return mExt == dynamic_cast<const ExtT<ExtType>&>(in).mExt; }
virtual bool operator==(size_t in) const override final
{ return mExt == in; }
virtual DExt operator+(const ExtBase& in) const override final
{ return std::make_shared<ExtT<ExtType>>( mExt + dynamic_cast<const ExtT<ExtType>&>(in).mExt ); }
virtual DExt operator*(size_t in) const override final
{ return std::make_shared<ExtT<ExtType>>( mExt * in ); }
virtual std::string stype() const override final { return std::string("T[") + mExt.stype() + "]"; }
};
//class DExtT;
template <class ExtType>
DExt mkDExt(const ExtT<ExtType>& in)
{
return std::make_shared<ExtT<ExtType>>(in);
}
template <class ExtType>
ExtT<ExtType> mkExtT(const ExtType& in)
{
return ExtT<ExtType>(in);
}
template <class X>
class DExtTX
{
private:
mutable DExt mDExt = nullptr;
X mNext;
template <class Y>
friend class DExtTX;
public:
static constexpr size_t NUM = X::SIZE;
static constexpr size_t SIZE = NUM + 1;
DExtTX() { mDExt = std::make_shared<ExtT<None>>(); }
DExtTX(const DExtTX& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
explicit DExtTX(const DExt& in) : mDExt(in) {}
/*
template <class Y>
DExtTX& operator=(const Y& y) { mDExt = std::make_shared<ExtT<Y>>(y); return *this; }
template <class Y>
DExtTX(const Y& y) : mDExt(std::make_shared<ExtT<Y>>(y)) {}
*/
bool operator==(const DExtTX& in) const
{ return *mDExt == *in.mDExt and mNext == in.mNext; }
bool operator==(size_t in) const
{ return *mDExt == in and mNext == in; }
template <class Y>
DExtTX(const DExtTX<Y>& in) : mDExt(in.mDExt), mNext(in.mNext) {}
DExtTX(const DExt& y, const X& x) : mDExt(y->deepCopy()),
mNext(x) {}
virtual size_t size() const { return mDExt->size(); }
inline const DExt& get() const { return mDExt; }
inline DExtTX<None> reduce() const { return DExtTX<None>(mDExt,None(0)); }
inline DExtTX operator+(const DExtTX& in) const
{ if (not mDExt) return in; else return DExtTX( (*mDExt) + (*in.mDExt), mNext + in.mNext ); }
inline DExtTX operator*(size_t in) const
{ if (not mDExt) return *this; else return DExtTX((*mDExt) * in, mNext * in); }
template <class ExtType>
inline const ExtType& expl() const
{ if(mDExt == nullptr) mDExt = std::make_shared<ExtT<ExtType>>(); assert(mDExt != nullptr); return mDExt->expl<ExtType>(); }
template <class Y>
inline auto extend(const Y& y) const -> DExtTX<decltype(mNext.extend(y))>
{ return DExtTX<decltype(mNext.extend(y))>(mDExt, mNext.extend(y)); }
inline const size_t& val() const { return mDExt->val(); }
inline const X& next() const { return mNext; }
inline void zero() { mDExt->zero(); }
template <size_t N>
inline auto nn() const -> decltype(Getter<N>::getX(*this))
{ return Getter<N>::getX(*this); }
std::string stype() const { return std::string("D[") + mDExt->stype() + "," + mNext.stype() + "]"; }
};
typedef DExtTX<None> DExtT;
inline MExt<None> mkExt(size_t s) { return MExt<None>(s); }
class ExpressionBase
{
@ -1061,7 +909,7 @@ namespace MultiArrayHelper
const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast;
const ExtType npos = last + mExt*pos;
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
mExpr(mnpos, getX<1>( npos ));
}
template <class IndexClass, class Expr>
@ -1072,7 +920,7 @@ namespace MultiArrayHelper
const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast;
const ExtType npos = last + mExt*pos;
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
mExpr(mnpos, getX<1>( npos ));
}