op4utest works
This commit is contained in:
parent
d7436ed577
commit
d2e7cb3a63
5 changed files with 69 additions and 21 deletions
|
@ -6,7 +6,6 @@ namespace MultiArrayTools
|
|||
template <typename T, class Operation>
|
||||
const T& DynamicOperation<T,Operation>::get(const DExtT& pos) const
|
||||
{
|
||||
VCHECK(pos.expl<ET>().val());
|
||||
return mOp.get(pos.expl<ET>());
|
||||
}
|
||||
|
||||
|
@ -20,7 +19,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class Operation>
|
||||
DExtT DynamicOperation<T,Operation>::rootSteps(std::intptr_t iPtrNum) const
|
||||
{
|
||||
return mOp.rootSteps(iPtrNum);
|
||||
return DExtT(mkDExt(mkExtT(mOp.rootSteps(iPtrNum))),None(0));
|
||||
}
|
||||
|
||||
template <typename T, class Operation>
|
||||
|
@ -35,5 +34,11 @@ namespace MultiArrayTools
|
|||
return mOp.data();
|
||||
}
|
||||
|
||||
template <typename T, class Operation>
|
||||
std::shared_ptr<DynamicOperationBase<T>> DynamicOperation<T,Operation>::deepCopy() const
|
||||
{
|
||||
return std::make_shared<DynamicOperation<T,Operation>>(*this);
|
||||
}
|
||||
|
||||
|
||||
} // namespace MultiArrayTools
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace MultiArrayTools
|
|||
virtual DExtT rootSteps(std::intptr_t iPtrNum = 0) const = 0;
|
||||
virtual DynamicExpression loop(const DynamicExpression& exp) const = 0;
|
||||
virtual const T* data() const = 0;
|
||||
virtual std::shared_ptr<DynamicOperationBase<T>> deepCopy() const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -38,7 +39,8 @@ namespace MultiArrayTools
|
|||
private:
|
||||
Operation mOp;
|
||||
public:
|
||||
typedef decltype(std::declval<Operation>().rootSteps()) ET;
|
||||
typedef decltype(mOp.rootSteps()) ET;
|
||||
//typedef decltype(std::declval<Operation>().rootSteps()) ET;
|
||||
|
||||
DynamicOperation() = default;
|
||||
DynamicOperation(const DynamicOperation& in) = default;
|
||||
|
@ -53,6 +55,7 @@ namespace MultiArrayTools
|
|||
virtual DExtT rootSteps(std::intptr_t iPtrNum = 0) const override final;
|
||||
virtual DynamicExpression loop(const DynamicExpression& exp) const override final;
|
||||
virtual const T* data() const override final;
|
||||
virtual std::shared_ptr<DynamicOperationBase<T>> deepCopy() const override final;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -69,15 +72,16 @@ namespace MultiArrayTools
|
|||
static constexpr bool CONT = true;
|
||||
|
||||
DynamicO() = default;
|
||||
DynamicO(const DynamicO& in) = default;
|
||||
DynamicO(DynamicO&& in) = default;
|
||||
DynamicO& operator=(const DynamicO& in) = default;
|
||||
DynamicO& operator=(DynamicO&& in) = default;
|
||||
DynamicO(const DynamicO& in) : mOp(in.mOp->deepCopy()) {}
|
||||
DynamicO(DynamicO&& in) : mOp(in.mOp->deepCopy()) {}
|
||||
DynamicO& operator=(const DynamicO& in) { mOp = in.mOp->deepCopy(); }
|
||||
DynamicO& operator=(DynamicO&& in) { mOp = in.mOp->deepCopy(); }
|
||||
|
||||
template <class Op>
|
||||
DynamicO(const Op& op) : mOp(std::make_shared<DynamicOperation<T,Op>>(op)) {}
|
||||
|
||||
inline const T& get(const DExtT& pos) const { return mOp->get(pos); }
|
||||
template <class X>
|
||||
inline const T& get(const DExtTX<X>& pos) const { return mOp->get(pos.reduce()); }
|
||||
inline DynamicO& set(const DExtT& pos) { return mOp->set(pos); }
|
||||
inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return mOp->rootSteps(iPtrNum); }
|
||||
inline DynamicExpression loop(const DynamicExpression& exp) const { return mOp->loop(exp); }
|
||||
|
|
|
@ -181,6 +181,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class Target, class OpClass, OpIndexAff OIA>
|
||||
inline void AssignmentExpr2<T,Target,OpClass,OIA>::operator()(size_t start, ExtType last)
|
||||
{
|
||||
//CHECK;
|
||||
mDataPtr[OpIndexResolve<OIA>::get(start,last)] = mSec.get(last.next());
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace MultiArrayHelper
|
|||
}
|
||||
};
|
||||
|
||||
struct None;
|
||||
|
||||
template <class X>
|
||||
class MExt
|
||||
|
@ -86,12 +87,14 @@ namespace MultiArrayHelper
|
|||
{ return Getter<N>::getX(*this); }
|
||||
|
||||
inline MExt operator+(const MExt& in) const;
|
||||
inline MExt operator+(const None& in) const;
|
||||
inline MExt operator*(size_t in) const;
|
||||
|
||||
template <class Y>
|
||||
auto extend(const Y& y) const -> MExt<decltype(mNext.extend(y))>
|
||||
{ return MExt<decltype(mNext.extend(y))>(mExt, mNext.extend(y)); }
|
||||
|
||||
std::string stype() const { return std::string("E[") + mNext.stype() + "]"; }
|
||||
};
|
||||
|
||||
struct None
|
||||
|
@ -117,6 +120,8 @@ namespace MultiArrayHelper
|
|||
template <class Y>
|
||||
Y extend(const Y& y) const
|
||||
{ return y; }
|
||||
|
||||
std::string stype() const { return std::string("N"); }
|
||||
};
|
||||
|
||||
template <>
|
||||
|
@ -164,12 +169,15 @@ namespace MultiArrayHelper
|
|||
{ return Getter<N>::getX(*this); }
|
||||
|
||||
inline MExt operator+(const MExt& in) const;
|
||||
inline MExt operator+(const None& in) const;
|
||||
inline MExt operator*(size_t in) const;
|
||||
|
||||
template <class Y>
|
||||
auto extend(const Y& y) const -> MExt<Y>
|
||||
{ return MExt<Y>(mExt,y); }
|
||||
|
||||
std::string stype() const { return std::string("E[N]"); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -231,6 +239,12 @@ namespace MultiArrayHelper
|
|||
return MExt<X>(mExt + in.val(), mNext + in.next());
|
||||
}
|
||||
|
||||
template <class X>
|
||||
inline MExt<X> MExt<X>::operator+(const None& in) const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
inline MExt<X> MExt<X>::operator*(size_t in) const
|
||||
{
|
||||
|
@ -279,6 +293,11 @@ namespace MultiArrayHelper
|
|||
return MExt<None>(mExt + in.val());
|
||||
}
|
||||
|
||||
inline MExt<None> MExt<None>::operator+(const None& in) const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
//template <>
|
||||
inline MExt<None> MExt<None>::operator*(size_t in) const
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ namespace MultiArrayHelper
|
|||
template <class ExtType>
|
||||
const ExtType& expl() const;
|
||||
|
||||
virtual std::string stype() const = 0;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ExtBase> DExt;
|
||||
|
@ -75,12 +76,26 @@ namespace MultiArrayHelper
|
|||
virtual void zero() override final { mExt.zero(); }
|
||||
|
||||
virtual DExt operator+(const ExtBase& in) const override final
|
||||
{ return std::make_shared<ExtT>( mExt + dynamic_cast<const ExtT&>(in).mExt ); }
|
||||
{ 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>( mExt * in ); }
|
||||
{ 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
|
||||
{
|
||||
|
@ -96,24 +111,26 @@ namespace MultiArrayHelper
|
|||
DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
|
||||
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); }
|
||||
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); }
|
||||
DExtTX(const DExt& in) : mDExt(in) {}
|
||||
|
||||
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)) {}
|
||||
|
||||
DExtTX(const DExt& y, const X& x) : mDExt(y),
|
||||
mNext(x) {}
|
||||
*/
|
||||
explicit 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) ) ; }
|
||||
{ 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 ) ; }
|
||||
{ if (not mDExt) return *this; else return DExtTX((*mDExt) * in, mNext * in); }
|
||||
|
||||
template <class ExtType>
|
||||
inline const ExtType& expl() const
|
||||
|
@ -131,6 +148,8 @@ namespace MultiArrayHelper
|
|||
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;
|
||||
|
@ -438,8 +457,8 @@ namespace MultiArrayHelper
|
|||
inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
|
||||
inline DExt dExtension() const override final;
|
||||
|
||||
inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return dRootSteps(iPtrNum); }
|
||||
inline DExtT extension() const { return dExtension(); }
|
||||
inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return DExtT(dRootSteps(iPtrNum)); }
|
||||
inline DExtT extension() const { return DExtT(dExtension()); }
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue