xpr -> only one pos argument

This commit is contained in:
Christian Zimmermann 2022-10-21 00:21:47 +02:00
parent 477ea8d43d
commit aafc6f0e2a
15 changed files with 109 additions and 129 deletions

View file

@ -6,10 +6,10 @@
namespace CNORXZ
{
template <class PosT, class Xpr>
decltype(auto) CIndex::ifor(const PosT& step, const Xpr& xpr) const
template <class Xpr>
decltype(auto) CIndex::ifor(const Xpr& xpr) const
{
return For<0,PosT,Xpr>(this->max(), this->id(), step, xpr);
return For<0,Xpr>(this->max(), this->id(), xpr);
}
}

View file

@ -43,8 +43,8 @@ namespace CNORXZ
SizeT meta() const;
CIndex& at(const SizeT& metaPos);
template <class PosT, class Xpr>
decltype(auto) ifor(const PosT& step, const Xpr& xpr) const;
template <class Xpr>
decltype(auto) ifor(const Xpr& xpr) const;
private:
Sptr<RangeType> mRangePtr;

View file

@ -50,7 +50,7 @@ namespace CNORXZ
DType meta() const;
DIndex& at(const DType& meta);
DXpr ifor(const UPos& step, const DXpr& xpr) const;
DXpr ifor(const DXpr& xpr) const;
private:
XIndexPtr mI;

View file

@ -55,8 +55,8 @@ namespace CNORXZ
decltype(auto) meta() const { return THIS().meta(); }
I& at(const MetaType& meta) { return THIS().at(meta); }
template <class PosT, class Xpr>
decltype(auto) ifor(const PosT& step, const Xpr& xpr) const { return THIS().ifor(step,xpr); }
template <class Xpr>
decltype(auto) ifor(const Xpr& xpr) const { return THIS().ifor(xpr); }
protected:
SizeT mPos = 0;

View file

@ -145,10 +145,10 @@ namespace CNORXZ
}
template <typename MetaType>
template <class PosT, class Xpr>
decltype(auto) UIndex<MetaType>::ifor(const PosT step, Xpr xpr) const
template <class Xpr>
decltype(auto) UIndex<MetaType>::ifor(const Xpr& xpr) const
{
return For<0,PosT,Xpr>(this->max(), this->id(), step, xpr);
return For<0,Xpr>(this->max(), this->id(), xpr);
}
/**********************

View file

@ -48,8 +48,8 @@ namespace CNORXZ
const MetaType& meta() const;
UIndex& at(const MetaType& metaPos);
template <class PosT, class Xpr>
decltype(auto) ifor(const PosT step, Xpr xpr) const;
template <class Xpr>
decltype(auto) ifor(const Xpr& xpr) const;
private:
Sptr<RangeType> mRangePtr;

View file

@ -155,9 +155,9 @@ namespace CNORXZ
}
template <class Index, typename Meta>
DXpr XIndex<Index,Meta>::ifor(const UPos& step, const DXpr& xpr) const
DXpr XIndex<Index,Meta>::ifor(const DXpr& xpr) const
{
return DXpr(mI->ifor(step, xpr));
return DXpr(mI->ifor(xpr));
}
}

View file

@ -42,7 +42,7 @@ namespace CNORXZ
virtual DType meta() const = 0;
virtual XIndexBase& at(const DType& meta) = 0;
virtual DXpr ifor(const UPos& step, const DXpr& xpr) const = 0;
virtual DXpr ifor(const DXpr& xpr) const = 0;
};
//Sptr<XIndexBase>& operator++(Sptr<XIndexBase>& i);
@ -91,7 +91,7 @@ namespace CNORXZ
virtual DType meta() const override final;
virtual XIndexBase& at(const DType& meta) override final;
virtual DXpr ifor(const UPos& step, const DXpr& xpr) const override final;
virtual DXpr ifor(const DXpr& xpr) const override final;
private:
IndexPtr<Index,Meta> mI;

View file

@ -12,43 +12,38 @@ namespace CNORXZ
* For *
***********/
template <SizeT L, class PosT, class Xpr>
constexpr For<L,PosT,Xpr>::For(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr) :
template <SizeT L, class Xpr>
constexpr For<L,Xpr>::For(SizeT size, const IndexId<L>& id, const Xpr& xpr) :
mSize(size),
mId(id),
mXpr(xpr),
mStep(step),
mExt(mXpr.rootSteps(mId))
{
static_assert(is_pos_type<PosT>::value, "got non-pos type");
}
{}
template <SizeT L, class PosT, class Xpr>
template <class PosT1, class PosT2>
inline SizeT For<L,PosT,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
template <SizeT L, class Xpr>
template <class PosT>
inline SizeT For<L,Xpr>::operator()(const PosT& last) const
{
for(SizeT i = 0; i != mSize; ++i){
const auto mpos = mlast + mStep * UPos(i);
const auto pos = last + mExt * UPos(i);
mXpr(mpos, pos);
mXpr(pos);
}
return 0;
}
template <SizeT L, class PosT, class Xpr>
inline SizeT For<L,PosT,Xpr>::operator()() const
template <SizeT L, class Xpr>
inline SizeT For<L,Xpr>::operator()() const
{
for(SizeT i = 0; i != mSize; ++i){
const auto mpos = mStep * UPos(i);
const auto pos = mExt * UPos(i);
mXpr(mpos, pos);
mXpr(pos);
}
return 0;
}
template <SizeT L, class PosT, class Xpr>
template <SizeT L, class Xpr>
template <SizeT I>
inline decltype(auto) For<L,PosT,Xpr>::rootSteps(const IndexId<I>& id) const
inline decltype(auto) For<L,Xpr>::rootSteps(const IndexId<I>& id) const
{
return mXpr.rootSteps(id);
}
@ -58,60 +53,55 @@ namespace CNORXZ
* SFor *
************/
template <SizeT N, SizeT L, class PosT, class Xpr>
constexpr SFor<N,L,PosT,Xpr>::SFor(const IndexId<L>& id, const PosT& step, const Xpr& xpr) :
template <SizeT N, SizeT L, class Xpr>
constexpr SFor<N,L,Xpr>::SFor(const IndexId<L>& id, const Xpr& xpr) :
mId(id),
mStep(step),
mXpr(xpr),
mExt(mXpr.RootSteps(mId))
{
static_assert(is_pos_type<PosT>::value, "got non-pos type");
}
{}
template <SizeT N, SizeT L, class PosT, class Xpr>
template <class PosT1, class PosT2>
constexpr SizeT SFor<N,L,PosT,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
template <SizeT N, SizeT L, class Xpr>
template <class PosT>
constexpr SizeT SFor<N,L,Xpr>::operator()(const PosT& last) const
{
return exec<0>(mlast, last);
return exec<0>(last);
}
template <SizeT N, SizeT L, class PosT, class Xpr>
constexpr SizeT SFor<N,L,PosT,Xpr>::operator()() const
template <SizeT N, SizeT L, class Xpr>
constexpr SizeT SFor<N,L,Xpr>::operator()() const
{
return exec<0>();
}
template <SizeT N, SizeT L, class PosT, class Xpr>
template <SizeT N, SizeT L, class Xpr>
template <SizeT I>
constexpr decltype(auto) SFor<N,L,PosT,Xpr>::rootSteps(const IndexId<I>& id) const
constexpr decltype(auto) SFor<N,L,Xpr>::rootSteps(const IndexId<I>& id) const
{
return mXpr.rootSteps(id);
}
template <SizeT N, SizeT L, class PosT, class Xpr>
template <SizeT I, class PosT1, class PosT2>
constexpr SizeT SFor<N,L,PosT,Xpr>::exec(const PosT1& mlast, const PosT2& last) const
template <SizeT N, SizeT L, class Xpr>
template <SizeT I, class PosT>
constexpr SizeT SFor<N,L,Xpr>::exec(const PosT& last) const
{
constexpr SPos<I> i;
const auto mpos = mlast + mStep * i;
const auto pos = last + mExt * i;
mXpr(mpos, pos);
mXpr(pos);
if constexpr(I < N-1){
return exec<I+1>(mlast, last);
return exec<I+1>(last);
}
else {
return 0;
}
}
template <SizeT N, SizeT L, class PosT, class Xpr>
template <SizeT N, SizeT L, class Xpr>
template <SizeT I>
constexpr SizeT SFor<N,L,PosT,Xpr>::exec() const
constexpr SizeT SFor<N,L,Xpr>::exec() const
{
constexpr SPos<I> i;
const auto mpos = mStep * i;
const auto pos = mExt * i;
mXpr(mpos, pos);
mXpr(pos);
if constexpr(I < N-1){
return exec<I+1>();
}
@ -124,24 +114,25 @@ namespace CNORXZ
* TFor *
************/
template <SizeT L, class PosT, class Xpr>
constexpr TFor<L,PosT,Xpr>::TFor(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr) :
template <SizeT L, class Xpr>
constexpr TFor<L,Xpr>::TFor(SizeT size, const IndexId<L>& id, const Xpr& xpr) :
mSize(size),
mId(id),
mStep(step),
mXpr(xpr),
mExt(mXpr.rootSteps(mId))
{
static_assert(is_pos_type<PosT>::value, "got non-pos type");
// check for write access!!!
/*
if constexpr(is_static_pos_type<PosT>::value){
static_assert(step.val() != 0, "step has to be non-zero for TPos");
}
CXZ_ASSERT(step.val() != 0, "step has to be non-zero for TPos");
*/
}
template <SizeT L, class PosT, class Xpr>
template <class PosT1, class PosT2>
inline SizeT TFor<L,PosT,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
template <SizeT L, class Xpr>
template <class PosT>
inline SizeT TFor<L,Xpr>::operator()(const PosT& last) const
{
int i = 0;
const int size = static_cast<int>(mSize);
@ -150,16 +141,15 @@ namespace CNORXZ
auto xpr = mXpr;
#pragma omp for
for(i = 0; i < size; i++){
const auto mpos = mlast + mStep * UPos(i);
const auto pos = last + mExt * UPos(i);
xpr(mpos, pos);
xpr(pos);
}
}
return 0;
}
template <SizeT L, class PosT, class Xpr>
inline SizeT TFor<L,PosT,Xpr>::operator()() const
template <SizeT L, class Xpr>
inline SizeT TFor<L,Xpr>::operator()() const
{
int i = 0;
const int size = static_cast<int>(mSize);
@ -168,17 +158,16 @@ namespace CNORXZ
auto xpr = mXpr;
#pragma omp for
for(i = 0; i < size; i++){
const auto mpos = mStep * UPos(i);
const auto pos = mExt * UPos(i);
xpr(mpos, pos);
xpr(pos);
}
}
return 0;
}
template <SizeT L, class PosT, class Xpr>
template <SizeT L, class Xpr>
template <SizeT I>
inline decltype(auto) TFor<L,PosT,Xpr>::rootSteps(const IndexId<I>& id) const
inline decltype(auto) TFor<L,Xpr>::rootSteps(const IndexId<I>& id) const
{
return mXpr.rootSteps(id);
}
@ -188,36 +177,31 @@ namespace CNORXZ
* EFor *
************/
template <SizeT N, SizeT L, class PosT, class Xpr>
constexpr EFor<N,L,PosT,Xpr>::EFor(const IndexId<L>& id, const PosT& step, const Xpr& xpr) :
template <SizeT N, SizeT L, class Xpr>
constexpr EFor<N,L,Xpr>::EFor(const IndexId<L>& id, const Xpr& xpr) :
mId(id),
mStep(step),
mXpr(xpr),
mExt(mXpr.RootSteps(mId))
{
static_assert(is_pos_type<PosT>::value, "got non-pos type");
}
{}
template <SizeT N, SizeT L, class PosT, class Xpr>
template <class PosT1, class PosT2>
constexpr SizeT EFor<N,L,PosT,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
template <SizeT N, SizeT L, class Xpr>
template <class PosT>
constexpr SizeT EFor<N,L,Xpr>::operator()(const PosT& last) const
{
auto mpos = mkEPos<N>(mlast, mStep);
auto pos = mkEPos<N>(last, mExt);
return mXpr(mpos, pos);
return mXpr(pos);
}
template <SizeT N, SizeT L, class PosT, class Xpr>
constexpr SizeT EFor<N,L,PosT,Xpr>::operator()() const
template <SizeT N, SizeT L, class Xpr>
constexpr SizeT EFor<N,L,Xpr>::operator()() const
{
auto mpos = mkEPos<N>(SPos<0>(), mStep);
auto pos = mkEPos<N>(SPos<0>(), mExt);
return mXpr(mpos, pos);
return mXpr(pos);
}
template <SizeT N, SizeT L, class PosT, class Xpr>
template <SizeT N, SizeT L, class Xpr>
template <SizeT I>
constexpr decltype(auto) EFor<N,L,PosT,Xpr>::rootSteps(const IndexId<I>& id) const
constexpr decltype(auto) EFor<N,L,Xpr>::rootSteps(const IndexId<I>& id) const
{
return mXpr.rootSteps(id);
}

View file

@ -8,16 +8,16 @@
namespace CNORXZ
{
template <SizeT L, class PosT, class Xpr>
class For : public XprInterface<For<L,PosT,Xpr>>
template <SizeT L, class Xpr>
class For : public XprInterface<For<L,Xpr>>
{
public:
DEFAULT_MEMBERS(For);
constexpr For(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr);
constexpr For(SizeT size, const IndexId<L>& id, const Xpr& xpr);
template <class PosT1, class PosT2>
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const;
template <class PosT>
inline SizeT operator()(const PosT& last) const;
inline SizeT operator()() const;
@ -28,23 +28,22 @@ namespace CNORXZ
SizeT mSize = 0;
IndexId<L> mId;
Xpr mXpr;
PosT mStep; // one-dim
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
};
// unrolled loop:
template <SizeT N, SizeT L, class PosT, class Xpr>
class SFor : public XprInterface<SFor<N,L,PosT,Xpr>>
template <SizeT N, SizeT L, class Xpr>
class SFor : public XprInterface<SFor<N,L,Xpr>>
{
public:
DEFAULT_MEMBERS(SFor);
constexpr SFor(const IndexId<L>& id, const PosT& step, const Xpr& xpr);
constexpr SFor(const IndexId<L>& id, const Xpr& xpr);
template <class PosT1, class PosT2>
constexpr SizeT operator()(const PosT1& mlast, const PosT2& last) const;
template <class PosT>
constexpr SizeT operator()(const PosT& last) const;
constexpr SizeT operator()() const;
@ -53,15 +52,14 @@ namespace CNORXZ
private:
template <SizeT I, class PosT1, class PosT2>
constexpr SizeT exec(const PosT1& mlast, const PosT2& last) const;
template <SizeT I, class PosT>
constexpr SizeT exec(const PosT& last) const;
template <SizeT I>
constexpr SizeT exec() const;
IndexId<L> mId;
Xpr mXpr;
PosT mStep;
typedef decltype(mXpr.RootSteps(mId)) XPosT;
XPosT mExt;
@ -69,16 +67,16 @@ namespace CNORXZ
// multi-threading
template <SizeT L, class PosT, class Xpr>
class TFor : public XprInterface<TFor<L,PosT,Xpr>>
template <SizeT L, class Xpr>
class TFor : public XprInterface<TFor<L,Xpr>>
{
public:
DEFAULT_MEMBERS(TFor);
constexpr TFor(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr);
constexpr TFor(SizeT size, const IndexId<L>& id, const Xpr& xpr);
template <class PosT1, class PosT2>
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const;
template <class PosT>
inline SizeT operator()(const PosT& last) const;
inline SizeT operator()() const;
@ -89,23 +87,22 @@ namespace CNORXZ
SizeT mSize = 0;
IndexId<L> mId;
Xpr mXpr;
PosT mStep;
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
};
// Extension For (Vectorization)
template <SizeT N, SizeT L, class PosT, class Xpr>
class EFor : public XprInterface<EFor<N,L,PosT,Xpr>>
template <SizeT N, SizeT L, class Xpr>
class EFor : public XprInterface<EFor<N,L,Xpr>>
{
public:
DEFAULT_MEMBERS(EFor);
constexpr EFor(const IndexId<L>& id, const PosT& step, const Xpr& xpr);
constexpr EFor(const IndexId<L>& id, const Xpr& xpr);
template <class PosT1, class PosT2>
constexpr SizeT operator()(const PosT1& mlast, const PosT2& last) const;
template <class PosT>
constexpr SizeT operator()(const PosT& last) const;
constexpr SizeT operator()() const;
@ -115,7 +112,6 @@ namespace CNORXZ
private:
IndexId<L> mId;
Xpr mXpr;
PosT mStep;
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
};

View file

@ -23,9 +23,9 @@ namespace CNORXZ
}
template <class Xpr>
SizeT VXpr<Xpr>::vexec(const UPos& mlast, const DPos& last) const
SizeT VXpr<Xpr>::vexec(const DPos& last) const
{
return (*this)(mlast, last);
return (*this)(last);
}
template <class Xpr>
@ -49,9 +49,9 @@ namespace CNORXZ
ObjHandle<VXprBase>(std::make_unique<VXpr<Xpr>>(a))
{}
inline SizeT DXpr::operator()(const UPos& mlast, const DPos& last) const
inline SizeT DXpr::operator()(const DPos& last) const
{
return mC->vexec(mlast, last);
return mC->vexec(last);
}
inline SizeT DXpr::operator()() const

View file

@ -18,8 +18,8 @@ namespace CNORXZ
inline Xpr& THIS() { return static_cast<Xpr&>(*this); }
inline const Xpr& THIS() const { return static_cast<const Xpr&>(*this); }
template <class PosT1, class PosT2>
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const { return THIS()(mlast,last); }
template <class PosT>
inline SizeT operator()(const PosT& last) const { return THIS()(last); }
inline SizeT operator()() const { return THIS()(); }
@ -34,7 +34,7 @@ namespace CNORXZ
virtual Uptr<VXprBase> copy() const = 0;
virtual SizeT vexec(const UPos& mlast, const DPos& last) const = 0;
virtual SizeT vexec(const DPos& last) const = 0;
virtual SizeT vexec() const = 0;
virtual DPos vrootSteps(const IndexId<0>& id) const = 0;
@ -49,7 +49,7 @@ namespace CNORXZ
virtual Uptr<VXprBase> copy() const override final;
virtual SizeT vexec(const UPos& mlast, const DPos& last) const override final;
virtual SizeT vexec(const DPos& last) const override final;
virtual SizeT vexec() const override final;
virtual DPos vrootSteps(const IndexId<0>& id) const override final;
@ -64,7 +64,7 @@ namespace CNORXZ
template <class Xpr>
explicit DXpr(const Xpr& a);
inline SizeT operator()(const UPos& mlast, const DPos& last) const;
inline SizeT operator()(const DPos& last) const;
inline SizeT operator()() const;
template <SizeT I>

View file

@ -51,7 +51,7 @@ namespace CNORXZ
DType meta() const;
YIndex& at(const DType& meta);
DXpr ifor(const UPos& step, const DXpr& xpr) const;
DXpr ifor(const DXpr& xpr) const;
private:

View file

@ -138,9 +138,9 @@ namespace CNORXZ
return *this;
}
DXpr DIndex::ifor(const UPos& step, const DXpr& xpr) const
DXpr DIndex::ifor(const DXpr& xpr) const
{
return DXpr(mI->ifor(step, xpr));
return DXpr(mI->ifor(xpr));
}
}

View file

@ -171,7 +171,7 @@ namespace CNORXZ
return *this;
}
DXpr YIndex::ifor(const UPos& step, const DXpr& xpr) const
DXpr YIndex::ifor(const DXpr& xpr) const
{
assert(0);
return DXpr();