parent
c6f140a18e
commit
d7436ed577
3 changed files with 21 additions and 102 deletions
|
@ -6,18 +6,8 @@ namespace MultiArrayTools
|
||||||
template <typename T, class Operation>
|
template <typename T, class Operation>
|
||||||
const T& DynamicOperation<T,Operation>::get(const DExtT& pos) const
|
const T& DynamicOperation<T,Operation>::get(const DExtT& pos) const
|
||||||
{
|
{
|
||||||
if(pos.isInit()){
|
VCHECK(pos.expl<ET>().val());
|
||||||
VCHECK(pos.stype());
|
return mOp.get(pos.expl<ET>());
|
||||||
ET xx;
|
|
||||||
VCHECK(xx.stype());
|
|
||||||
VCHECK(mOp.rootSteps(0).stype());
|
|
||||||
VCHECK(pos.expl<ET>().val());
|
|
||||||
return mOp.get(pos.expl<ET>());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ET xx;
|
|
||||||
return mOp.get(xx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Operation>
|
template <typename T, class Operation>
|
||||||
|
|
|
@ -92,10 +92,6 @@ namespace MultiArrayHelper
|
||||||
auto extend(const Y& y) const -> MExt<decltype(mNext.extend(y))>
|
auto extend(const Y& y) const -> MExt<decltype(mNext.extend(y))>
|
||||||
{ return MExt<decltype(mNext.extend(y))>(mExt, mNext.extend(y)); }
|
{ return MExt<decltype(mNext.extend(y))>(mExt, mNext.extend(y)); }
|
||||||
|
|
||||||
std::string stype() const { return std::string("E[") + mNext.stype() + "]"; }
|
|
||||||
|
|
||||||
const MExt& lowest() const { return *this; }
|
|
||||||
MExt& lowest() { return *this; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct None
|
struct None
|
||||||
|
@ -121,11 +117,6 @@ namespace MultiArrayHelper
|
||||||
template <class Y>
|
template <class Y>
|
||||||
Y extend(const Y& y) const
|
Y extend(const Y& y) const
|
||||||
{ return y; }
|
{ return y; }
|
||||||
|
|
||||||
std::string stype() const { return "N"; }
|
|
||||||
|
|
||||||
const None& lowest() const { return *this; }
|
|
||||||
None& lowest() { return *this; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -179,10 +170,6 @@ namespace MultiArrayHelper
|
||||||
auto extend(const Y& y) const -> MExt<Y>
|
auto extend(const Y& y) const -> MExt<Y>
|
||||||
{ return MExt<Y>(mExt,y); }
|
{ return MExt<Y>(mExt,y); }
|
||||||
|
|
||||||
std::string stype() const { return "E[N]"; }
|
|
||||||
|
|
||||||
const MExt& lowest() const { return *this; }
|
|
||||||
MExt& lowest() { return *this; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@ namespace MultiArrayHelper
|
||||||
template <class ExtType>
|
template <class ExtType>
|
||||||
const ExtType& expl() const;
|
const ExtType& expl() const;
|
||||||
|
|
||||||
virtual std::string stype() const = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<ExtBase> DExt;
|
typedef std::shared_ptr<ExtBase> DExt;
|
||||||
|
@ -65,7 +63,7 @@ namespace MultiArrayHelper
|
||||||
ExtT& operator=(const ExtT& in) = default;
|
ExtT& operator=(const ExtT& in) = default;
|
||||||
ExtT& operator=(ExtT&& in) = default;
|
ExtT& operator=(ExtT&& in) = default;
|
||||||
|
|
||||||
ExtT(const ExtType& in) : mExt(in) { assert(in.stype()[0] != 'T'); }
|
ExtT(const ExtType& in) : mExt(in) {}
|
||||||
|
|
||||||
virtual std::shared_ptr<ExtBase> deepCopy() const override final { return std::make_shared<ExtT<ExtType>>(mExt); }
|
virtual std::shared_ptr<ExtBase> deepCopy() const override final { return std::make_shared<ExtT<ExtType>>(mExt); }
|
||||||
|
|
||||||
|
@ -80,70 +78,31 @@ namespace MultiArrayHelper
|
||||||
{ return std::make_shared<ExtT>( mExt + dynamic_cast<const ExtT&>(in).mExt ); }
|
{ return std::make_shared<ExtT>( mExt + dynamic_cast<const ExtT&>(in).mExt ); }
|
||||||
virtual DExt operator*(size_t in) const override final
|
virtual DExt operator*(size_t in) const override final
|
||||||
{ return std::make_shared<ExtT>( mExt * in ); }
|
{ return std::make_shared<ExtT>( mExt * in ); }
|
||||||
|
|
||||||
virtual std::string stype() const override final { return std::string("T[")+mExt.stype()+"]"; }
|
|
||||||
const ExtType& lowest() const { return mExt; }
|
|
||||||
ExtType& lowest() { return mExt; }
|
|
||||||
};
|
};
|
||||||
//class DExtT;
|
//class DExtT;
|
||||||
template <class X>
|
|
||||||
class DExtTX;
|
|
||||||
|
|
||||||
template <class Y>
|
|
||||||
struct SptrExtT
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(std::declval<Y>().lowest())>::type YX;
|
|
||||||
|
|
||||||
static DExt mk(const Y& y)
|
|
||||||
{
|
|
||||||
return std::make_shared<ExtT<YX>>(y.lowest());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class X>
|
|
||||||
struct SptrExtT<DExtTX<X>>
|
|
||||||
{
|
|
||||||
static DExt mk(const DExtTX<X>& y)
|
|
||||||
{
|
|
||||||
return y.lowest();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/*
|
|
||||||
template <class Y>
|
|
||||||
struct SptrExtT<ExtT<Y>>
|
|
||||||
{
|
|
||||||
static DExt mk(const ExtT<Y>& y)
|
|
||||||
{
|
|
||||||
return std::make_shared<ExtT<Y>>(y);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
template <class X>
|
template <class X>
|
||||||
class DExtTX
|
class DExtTX
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
mutable DExt mDExt = nullptr;
|
mutable DExt mDExt = nullptr;
|
||||||
X mNext;
|
X mNext;
|
||||||
|
|
||||||
static DExt getDeepCopy(const DExtTX& in) { if(in.mDExt) return in.mDExt->deepCopy(); else return DExt(); }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr size_t NUM = X::SIZE;
|
static constexpr size_t NUM = X::SIZE;
|
||||||
static constexpr size_t SIZE = NUM + 1;
|
static constexpr size_t SIZE = NUM + 1;
|
||||||
|
|
||||||
//DExtTX() { VCHECK(mDExt->val()) ;mDExt = std::make_shared<ExtT<None>>(); }
|
DExtTX() { mDExt = std::make_shared<ExtT<None>>(); }
|
||||||
DExtTX() = default;
|
DExtTX(const DExtTX& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
|
||||||
DExtTX(const DExtTX& in) : mDExt(getDeepCopy(in)), mNext(in.mNext) {}
|
DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {}
|
||||||
DExtTX(DExtTX&& in) : mDExt(getDeepCopy(in)), mNext(in.mNext) {}
|
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); }
|
||||||
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = getDeepCopy(in); }
|
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); }
|
||||||
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = getDeepCopy(in); }
|
|
||||||
DExtTX(const DExt& in) : mDExt(in) {}
|
DExtTX(const DExt& in) : mDExt(in) {}
|
||||||
|
|
||||||
template <class Y>
|
template <class Y>
|
||||||
DExtTX& operator=(const Y& y) { mDExt = SptrExtT<Y>::mk(y); return *this; }
|
DExtTX& operator=(const Y& y) { mDExt = std::make_shared<ExtT<Y>>(y); return *this; }
|
||||||
|
|
||||||
template <class Y>
|
template <class Y>
|
||||||
DExtTX(const Y& y) : mDExt(SptrExtT<Y>::mk(y)) {}
|
DExtTX(const Y& y) : mDExt(std::make_shared<ExtT<Y>>(y)) {}
|
||||||
|
|
||||||
DExtTX(const DExt& y, const X& x) : mDExt(y),
|
DExtTX(const DExt& y, const X& x) : mDExt(y),
|
||||||
mNext(x) {}
|
mNext(x) {}
|
||||||
|
@ -158,8 +117,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
template <class ExtType>
|
template <class ExtType>
|
||||||
inline const ExtType& expl() const
|
inline const ExtType& expl() const
|
||||||
//{ if(mDExt == nullptr) mDExt = std::make_shared<ExtT<ExtType>>(); assert(mDExt != nullptr); return mDExt->expl<ExtType>(); }
|
{ if(mDExt == nullptr) mDExt = std::make_shared<ExtT<ExtType>>(); assert(mDExt != nullptr); return mDExt->expl<ExtType>(); }
|
||||||
{ return mDExt->expl<ExtType>(); }
|
|
||||||
|
|
||||||
template <class Y>
|
template <class Y>
|
||||||
inline auto extend(const Y& y) const -> DExtTX<decltype(mNext.extend(y))>
|
inline auto extend(const Y& y) const -> DExtTX<decltype(mNext.extend(y))>
|
||||||
|
@ -173,13 +131,6 @@ namespace MultiArrayHelper
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
inline auto nn() const -> decltype(Getter<N>::getX(*this))
|
inline auto nn() const -> decltype(Getter<N>::getX(*this))
|
||||||
{ return Getter<N>::getX(*this); }
|
{ return Getter<N>::getX(*this); }
|
||||||
|
|
||||||
inline std::string stype() const { return std::string("S[")+mDExt->stype()+"]"; }
|
|
||||||
|
|
||||||
inline bool isInit() const { return mDExt != nullptr; }
|
|
||||||
|
|
||||||
const DExt& lowest() const { return mDExt; }
|
|
||||||
DExt& lowest() { return mDExt; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef DExtTX<None> DExtT;
|
typedef DExtTX<None> DExtT;
|
||||||
|
@ -543,13 +494,7 @@ namespace MultiArrayHelper
|
||||||
template <class ExtType>
|
template <class ExtType>
|
||||||
const ExtType& ExtBase::expl() const
|
const ExtType& ExtBase::expl() const
|
||||||
{
|
{
|
||||||
VCHECK(this);
|
return dynamic_cast<const ExtT<ExtType>*>(this)->ext();
|
||||||
VCHECK(this->stype());
|
|
||||||
auto xx = dynamic_cast<const ExtT<ExtType>*>(this);
|
|
||||||
VCHECK(xx);
|
|
||||||
ExtT<ExtType> xxx;
|
|
||||||
VCHECK(xxx.stype());
|
|
||||||
return xx->ext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************
|
/*****************
|
||||||
|
@ -577,9 +522,6 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT>
|
||||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast, DExt last)
|
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast, DExt last)
|
||||||
{
|
{
|
||||||
VCHECK(last->stype());
|
|
||||||
ExtType xxx;
|
|
||||||
VCHECK(xxx.stype());
|
|
||||||
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
||||||
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
|
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
|
||||||
}
|
}
|
||||||
|
@ -627,7 +569,7 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT>
|
||||||
DExt For<IndexClass,Expr,FT>::dRootSteps(std::intptr_t iPtrNum) const
|
DExt For<IndexClass,Expr,FT>::dRootSteps(std::intptr_t iPtrNum) const
|
||||||
{
|
{
|
||||||
return SptrExtT<ExtType>::mk(rootSteps(iPtrNum));
|
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||||
//mRootSteps = rootSteps(iPtrNum);
|
//mRootSteps = rootSteps(iPtrNum);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
|
@ -636,7 +578,7 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT>
|
||||||
DExt For<IndexClass,Expr,FT>::dExtension() const
|
DExt For<IndexClass,Expr,FT>::dExtension() const
|
||||||
{
|
{
|
||||||
return SptrExtT<ExtType>::mk(mExt);
|
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
@ -739,7 +681,7 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
DExt PFor<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
|
DExt PFor<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
|
||||||
{
|
{
|
||||||
return SptrExtT<ExtType>::mk(rootSteps(iPtrNum));
|
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||||
//mRootSteps = rootSteps(iPtrNum);
|
//mRootSteps = rootSteps(iPtrNum);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
|
@ -748,7 +690,7 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
DExt PFor<IndexClass,Expr>::dExtension() const
|
DExt PFor<IndexClass,Expr>::dExtension() const
|
||||||
{
|
{
|
||||||
return SptrExtT<ExtType>::mk(mExt);
|
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
@ -826,7 +768,7 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
DExt SingleExpression<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
|
DExt SingleExpression<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
|
||||||
{
|
{
|
||||||
return SptrExtT<ExtType>::mk(rootSteps(iPtrNum));
|
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||||
//mRootSteps = rootSteps(iPtrNum);
|
//mRootSteps = rootSteps(iPtrNum);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
|
@ -835,7 +777,7 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
DExt SingleExpression<IndexClass,Expr>::dExtension() const
|
DExt SingleExpression<IndexClass,Expr>::dExtension() const
|
||||||
{
|
{
|
||||||
return SptrExtT<ExtType>::mk(mExt);
|
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
@ -913,7 +855,7 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
DExt SubExpr<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
|
DExt SubExpr<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
|
||||||
{
|
{
|
||||||
return SptrExtT<ExtType>::mk(rootSteps(iPtrNum));
|
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||||
//mRootSteps = rootSteps(iPtrNum);
|
//mRootSteps = rootSteps(iPtrNum);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
|
||||||
//sizeof(ExtType)/sizeof(size_t));
|
//sizeof(ExtType)/sizeof(size_t));
|
||||||
|
@ -922,7 +864,7 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
DExt SubExpr<IndexClass,Expr>::dExtension() const
|
DExt SubExpr<IndexClass,Expr>::dExtension() const
|
||||||
{
|
{
|
||||||
return SptrExtT<ExtType>::mk(mExt);
|
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
@ -968,7 +910,7 @@ namespace MultiArrayHelper
|
||||||
inline void ExpressionHolder<Expr>::operator()(size_t mlast, ExtType last)
|
inline void ExpressionHolder<Expr>::operator()(size_t mlast, ExtType last)
|
||||||
{
|
{
|
||||||
mExpr(mlast,
|
mExpr(mlast,
|
||||||
SptrExtT<ExtType>::mk(last));
|
std::make_shared<ExtT<ExtType>>(last));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
|
|
Loading…
Reference in a new issue