From aafc6f0e2ad55239af3b244440160b4648b7c816 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 21 Oct 2022 00:21:47 +0200 Subject: [PATCH] xpr -> only one pos argument --- src/include/ranges/crange.cc.h | 6 +- src/include/ranges/crange.h | 4 +- src/include/ranges/dindex.h | 2 +- src/include/ranges/index_base.h | 4 +- src/include/ranges/urange.cc.h | 6 +- src/include/ranges/urange.h | 4 +- src/include/ranges/xindex.cc.h | 4 +- src/include/ranges/xindex.h | 4 +- src/include/ranges/xpr/for.cc.h | 130 ++++++++++++--------------- src/include/ranges/xpr/for.h | 48 +++++----- src/include/ranges/xpr/xpr_base.cc.h | 8 +- src/include/ranges/xpr/xpr_base.h | 10 +-- src/include/ranges/yrange.h | 2 +- src/lib/ranges/dindex.cc | 4 +- src/lib/ranges/yrange.cc | 2 +- 15 files changed, 109 insertions(+), 129 deletions(-) diff --git a/src/include/ranges/crange.cc.h b/src/include/ranges/crange.cc.h index b5315b4..e07ad5f 100644 --- a/src/include/ranges/crange.cc.h +++ b/src/include/ranges/crange.cc.h @@ -6,10 +6,10 @@ namespace CNORXZ { - template - decltype(auto) CIndex::ifor(const PosT& step, const Xpr& xpr) const + template + 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); } } diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index d5680ed..eff65e9 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -43,8 +43,8 @@ namespace CNORXZ SizeT meta() const; CIndex& at(const SizeT& metaPos); - template - decltype(auto) ifor(const PosT& step, const Xpr& xpr) const; + template + decltype(auto) ifor(const Xpr& xpr) const; private: Sptr mRangePtr; diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index 2956138..e4231d2 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -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; diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index 13b9e2a..88d668c 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -55,8 +55,8 @@ namespace CNORXZ decltype(auto) meta() const { return THIS().meta(); } I& at(const MetaType& meta) { return THIS().at(meta); } - template - decltype(auto) ifor(const PosT& step, const Xpr& xpr) const { return THIS().ifor(step,xpr); } + template + decltype(auto) ifor(const Xpr& xpr) const { return THIS().ifor(xpr); } protected: SizeT mPos = 0; diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index 14f219a..c5560af 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -145,10 +145,10 @@ namespace CNORXZ } template - template - decltype(auto) UIndex::ifor(const PosT step, Xpr xpr) const + template + decltype(auto) UIndex::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); } /********************** diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index 7bdfc87..ec7d65b 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -48,8 +48,8 @@ namespace CNORXZ const MetaType& meta() const; UIndex& at(const MetaType& metaPos); - template - decltype(auto) ifor(const PosT step, Xpr xpr) const; + template + decltype(auto) ifor(const Xpr& xpr) const; private: Sptr mRangePtr; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index 668de35..b445046 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -155,9 +155,9 @@ namespace CNORXZ } template - DXpr XIndex::ifor(const UPos& step, const DXpr& xpr) const + DXpr XIndex::ifor(const DXpr& xpr) const { - return DXpr(mI->ifor(step, xpr)); + return DXpr(mI->ifor(xpr)); } } diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index 7fd0578..38b359b 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -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& operator++(Sptr& 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 mI; diff --git a/src/include/ranges/xpr/for.cc.h b/src/include/ranges/xpr/for.cc.h index b22b1fa..58ec16e 100644 --- a/src/include/ranges/xpr/for.cc.h +++ b/src/include/ranges/xpr/for.cc.h @@ -12,43 +12,38 @@ namespace CNORXZ * For * ***********/ - template - constexpr For::For(SizeT size, const IndexId& id, const PosT& step, const Xpr& xpr) : + template + constexpr For::For(SizeT size, const IndexId& id, const Xpr& xpr) : mSize(size), mId(id), mXpr(xpr), - mStep(step), mExt(mXpr.rootSteps(mId)) - { - static_assert(is_pos_type::value, "got non-pos type"); - } + {} - template - template - inline SizeT For::operator()(const PosT1& mlast, const PosT2& last) const + template + template + inline SizeT For::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 - inline SizeT For::operator()() const + template + inline SizeT For::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 + template template - inline decltype(auto) For::rootSteps(const IndexId& id) const + inline decltype(auto) For::rootSteps(const IndexId& id) const { return mXpr.rootSteps(id); } @@ -58,60 +53,55 @@ namespace CNORXZ * SFor * ************/ - template - constexpr SFor::SFor(const IndexId& id, const PosT& step, const Xpr& xpr) : + template + constexpr SFor::SFor(const IndexId& id, const Xpr& xpr) : mId(id), - mStep(step), mXpr(xpr), mExt(mXpr.RootSteps(mId)) - { - static_assert(is_pos_type::value, "got non-pos type"); - } + {} - template - template - constexpr SizeT SFor::operator()(const PosT1& mlast, const PosT2& last) const + template + template + constexpr SizeT SFor::operator()(const PosT& last) const { - return exec<0>(mlast, last); + return exec<0>(last); } - template - constexpr SizeT SFor::operator()() const + template + constexpr SizeT SFor::operator()() const { return exec<0>(); } - template + template template - constexpr decltype(auto) SFor::rootSteps(const IndexId& id) const + constexpr decltype(auto) SFor::rootSteps(const IndexId& id) const { return mXpr.rootSteps(id); } - template - template - constexpr SizeT SFor::exec(const PosT1& mlast, const PosT2& last) const + template + template + constexpr SizeT SFor::exec(const PosT& last) const { constexpr SPos 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(mlast, last); + return exec(last); } else { return 0; } } - template + template template - constexpr SizeT SFor::exec() const + constexpr SizeT SFor::exec() const { constexpr SPos i; - const auto mpos = mStep * i; const auto pos = mExt * i; - mXpr(mpos, pos); + mXpr(pos); if constexpr(I < N-1){ return exec(); } @@ -124,24 +114,25 @@ namespace CNORXZ * TFor * ************/ - template - constexpr TFor::TFor(SizeT size, const IndexId& id, const PosT& step, const Xpr& xpr) : + template + constexpr TFor::TFor(SizeT size, const IndexId& id, const Xpr& xpr) : mSize(size), mId(id), - mStep(step), mXpr(xpr), mExt(mXpr.rootSteps(mId)) { - static_assert(is_pos_type::value, "got non-pos type"); + // check for write access!!! + /* if constexpr(is_static_pos_type::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 - template - inline SizeT TFor::operator()(const PosT1& mlast, const PosT2& last) const + template + template + inline SizeT TFor::operator()(const PosT& last) const { int i = 0; const int size = static_cast(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 - inline SizeT TFor::operator()() const + template + inline SizeT TFor::operator()() const { int i = 0; const int size = static_cast(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 + template template - inline decltype(auto) TFor::rootSteps(const IndexId& id) const + inline decltype(auto) TFor::rootSteps(const IndexId& id) const { return mXpr.rootSteps(id); } @@ -188,36 +177,31 @@ namespace CNORXZ * EFor * ************/ - template - constexpr EFor::EFor(const IndexId& id, const PosT& step, const Xpr& xpr) : + template + constexpr EFor::EFor(const IndexId& id, const Xpr& xpr) : mId(id), - mStep(step), mXpr(xpr), mExt(mXpr.RootSteps(mId)) - { - static_assert(is_pos_type::value, "got non-pos type"); - } + {} - template - template - constexpr SizeT EFor::operator()(const PosT1& mlast, const PosT2& last) const + template + template + constexpr SizeT EFor::operator()(const PosT& last) const { - auto mpos = mkEPos(mlast, mStep); auto pos = mkEPos(last, mExt); - return mXpr(mpos, pos); + return mXpr(pos); } - template - constexpr SizeT EFor::operator()() const + template + constexpr SizeT EFor::operator()() const { - auto mpos = mkEPos(SPos<0>(), mStep); auto pos = mkEPos(SPos<0>(), mExt); - return mXpr(mpos, pos); + return mXpr(pos); } - template + template template - constexpr decltype(auto) EFor::rootSteps(const IndexId& id) const + constexpr decltype(auto) EFor::rootSteps(const IndexId& id) const { return mXpr.rootSteps(id); } diff --git a/src/include/ranges/xpr/for.h b/src/include/ranges/xpr/for.h index 40a061b..8b7771e 100644 --- a/src/include/ranges/xpr/for.h +++ b/src/include/ranges/xpr/for.h @@ -8,16 +8,16 @@ namespace CNORXZ { - template - class For : public XprInterface> + template + class For : public XprInterface> { public: DEFAULT_MEMBERS(For); - constexpr For(SizeT size, const IndexId& id, const PosT& step, const Xpr& xpr); + constexpr For(SizeT size, const IndexId& id, const Xpr& xpr); - template - inline SizeT operator()(const PosT1& mlast, const PosT2& last) const; + template + inline SizeT operator()(const PosT& last) const; inline SizeT operator()() const; @@ -28,23 +28,22 @@ namespace CNORXZ SizeT mSize = 0; IndexId mId; Xpr mXpr; - PosT mStep; // one-dim typedef decltype(mXpr.rootSteps(mId)) XPosT; XPosT mExt; }; // unrolled loop: - template - class SFor : public XprInterface> + template + class SFor : public XprInterface> { public: DEFAULT_MEMBERS(SFor); - constexpr SFor(const IndexId& id, const PosT& step, const Xpr& xpr); + constexpr SFor(const IndexId& id, const Xpr& xpr); - template - constexpr SizeT operator()(const PosT1& mlast, const PosT2& last) const; + template + constexpr SizeT operator()(const PosT& last) const; constexpr SizeT operator()() const; @@ -53,15 +52,14 @@ namespace CNORXZ private: - template - constexpr SizeT exec(const PosT1& mlast, const PosT2& last) const; + template + constexpr SizeT exec(const PosT& last) const; template constexpr SizeT exec() const; IndexId mId; Xpr mXpr; - PosT mStep; typedef decltype(mXpr.RootSteps(mId)) XPosT; XPosT mExt; @@ -69,16 +67,16 @@ namespace CNORXZ // multi-threading - template - class TFor : public XprInterface> + template + class TFor : public XprInterface> { public: DEFAULT_MEMBERS(TFor); - constexpr TFor(SizeT size, const IndexId& id, const PosT& step, const Xpr& xpr); + constexpr TFor(SizeT size, const IndexId& id, const Xpr& xpr); - template - inline SizeT operator()(const PosT1& mlast, const PosT2& last) const; + template + inline SizeT operator()(const PosT& last) const; inline SizeT operator()() const; @@ -89,23 +87,22 @@ namespace CNORXZ SizeT mSize = 0; IndexId mId; Xpr mXpr; - PosT mStep; typedef decltype(mXpr.rootSteps(mId)) XPosT; XPosT mExt; }; // Extension For (Vectorization) - template - class EFor : public XprInterface> + template + class EFor : public XprInterface> { public: DEFAULT_MEMBERS(EFor); - constexpr EFor(const IndexId& id, const PosT& step, const Xpr& xpr); + constexpr EFor(const IndexId& id, const Xpr& xpr); - template - constexpr SizeT operator()(const PosT1& mlast, const PosT2& last) const; + template + constexpr SizeT operator()(const PosT& last) const; constexpr SizeT operator()() const; @@ -115,7 +112,6 @@ namespace CNORXZ private: IndexId mId; Xpr mXpr; - PosT mStep; typedef decltype(mXpr.rootSteps(mId)) XPosT; XPosT mExt; }; diff --git a/src/include/ranges/xpr/xpr_base.cc.h b/src/include/ranges/xpr/xpr_base.cc.h index dd4623c..99da39a 100644 --- a/src/include/ranges/xpr/xpr_base.cc.h +++ b/src/include/ranges/xpr/xpr_base.cc.h @@ -23,9 +23,9 @@ namespace CNORXZ } template - SizeT VXpr::vexec(const UPos& mlast, const DPos& last) const + SizeT VXpr::vexec(const DPos& last) const { - return (*this)(mlast, last); + return (*this)(last); } template @@ -49,9 +49,9 @@ namespace CNORXZ ObjHandle(std::make_unique>(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 diff --git a/src/include/ranges/xpr/xpr_base.h b/src/include/ranges/xpr/xpr_base.h index 1975aeb..aad448d 100644 --- a/src/include/ranges/xpr/xpr_base.h +++ b/src/include/ranges/xpr/xpr_base.h @@ -18,8 +18,8 @@ namespace CNORXZ inline Xpr& THIS() { return static_cast(*this); } inline const Xpr& THIS() const { return static_cast(*this); } - template - inline SizeT operator()(const PosT1& mlast, const PosT2& last) const { return THIS()(mlast,last); } + template + inline SizeT operator()(const PosT& last) const { return THIS()(last); } inline SizeT operator()() const { return THIS()(); } @@ -34,7 +34,7 @@ namespace CNORXZ virtual Uptr 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 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 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 diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index a9ac546..58ae0a8 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -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: diff --git a/src/lib/ranges/dindex.cc b/src/lib/ranges/dindex.cc index 54ba839..e2ae9fb 100644 --- a/src/lib/ranges/dindex.cc +++ b/src/lib/ranges/dindex.cc @@ -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)); } } diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index edeb9f8..3789c99 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -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();