From 6b2bbc30202e820ec0aa6a735b72304e4b8f608b Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 30 Oct 2022 22:28:40 +0100 Subject: [PATCH] OpCont + adapt ifor memeber functions --- src/include/operation/op_types.cc.h | 63 ++++++++++++++++++++++++++++- src/include/operation/op_types.h | 22 ++++++++-- 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 | 6 ++- src/include/ranges/urange.cc.h | 6 +-- src/include/ranges/urange.h | 4 +- src/include/ranges/xindex.cc.h | 5 ++- src/include/ranges/xindex.h | 6 ++- src/include/ranges/yrange.h | 2 +- src/include/xpr/for.cc.h | 15 ------- src/include/xpr/for.h | 14 +------ src/include/xpr/func.cc.h | 24 +++++++++++ src/include/xpr/func.h | 25 ++++++++++++ src/include/xpr/xpr.cc.h | 1 + src/include/xpr/xpr.h | 1 + src/lib/ranges/dindex.cc | 4 +- src/lib/ranges/yrange.cc | 3 +- 19 files changed, 159 insertions(+), 54 deletions(-) create mode 100644 src/include/xpr/func.cc.h create mode 100644 src/include/xpr/func.h diff --git a/src/include/operation/op_types.cc.h b/src/include/operation/op_types.cc.h index d50239d..0146c2e 100644 --- a/src/include/operation/op_types.cc.h +++ b/src/include/operation/op_types.cc.h @@ -106,6 +106,60 @@ namespace CNORXZ } + /**************** + * OpCont * + ****************/ + + template + constexpr OpCont::OpCont(const Sptr& ind) : + mIndex(ind), + mC(mIndex.max()) + {} + + template + template + constexpr decltype(auto) OpCont::operator()(const PosT& pos) const + { + if constexpr(is_epos_type::value){ + if constexpr(pos_type_is_consecutive::value){ + return vreg(mC.data(),pos); + } + else { + // non-consecutive data cannot be directly accessed + // so there is no non-const (write) access! + return vreg(const_cast(mData),pos); + } + } + else { + return mC[pos.val()]; + } + } + + template + constexpr decltype(auto) OpCont::operator()() const + { + return mC[0]; + } + + template + template + constexpr decltype(auto) OpCont::rootSteps(const IndexId& id) const + { + return mIndex->stepSize(id); + } + + template + T* OpCont::data() + { + return mC.data(); + } + + template + const T* OpCont::data() const + { + return mC.data(); + } + /**************** * OpRoot * ****************/ @@ -139,7 +193,7 @@ namespace CNORXZ } template - constexpr OpRoot& OpRoot::operator=(const OpRoot& in) + constexpr OpRoot& OpRoot::operator=(const OpRoot& o) { a(mInd, [](auto& a, const auto& b) { a = b; }, o) return *this; @@ -176,7 +230,12 @@ namespace CNORXZ { return mIndex->stepSize(id); } - + + template + T* OpRoot::data() const + { + return mData; + } /******************* * Operation * diff --git a/src/include/operation/op_types.h b/src/include/operation/op_types.h index e5ef07c..91bebed 100644 --- a/src/include/operation/op_types.h +++ b/src/include/operation/op_types.h @@ -56,8 +56,6 @@ namespace CNORXZ class COpRoot : public COpInterface> { public: - - typedef T value_type; typedef OpInterface> OI; constexpr COpRoot(const DArrayBase& a, const Sptr& ind); @@ -83,6 +81,25 @@ namespace CNORXZ { // operation container (intermediate operation results) // TO BE IMPLEMENTED!!! + public: + typedef OpInterface> OI; + + constexpr OpCont(const Sptr& ind); + + template + constexpr decltype(auto) operator()(const PosT& pos) const; + + constexpr decltype(auto) operator()() const; + + template + constexpr decltype(auto) rootSteps(const IndexId& id) const; + + T* data(); + const T* data() const; + + private: + Sptr mIndex; + Vector mC; }; @@ -90,7 +107,6 @@ namespace CNORXZ class OpRoot : public OpInterface> { public: - typedef T value_type; typedef OpInterface> OI; constexpr OpRoot(MDArrayBase& a, const Sptr& ind); diff --git a/src/include/ranges/crange.cc.h b/src/include/ranges/crange.cc.h index 6aa0e12..2c299ad 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 Xpr& xpr) const + template + decltype(auto) CIndex::ifor(const Xpr& xpr, F&& f) const { - return For<0,Xpr>(this->max(), this->id(), xpr, NoF()); + return For<0,Xpr,F>(this->max(), this->id(), xpr, std::forward(f)); } } diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index eff65e9..505b87c 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 Xpr& xpr) const; + template + decltype(auto) ifor(const Xpr& xpr, F&& f) const; private: Sptr mRangePtr; diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index 9d4817a..5e7dcbd 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 DXpr& xpr) const; + DXpr ifor(const DXpr& xpr, std::function&& f) const; private: XIndexPtr mI; diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index 88d668c..a09c4f0 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -7,6 +7,7 @@ #include "range_base.h" #include "xpr/index_id.h" #include "xpr/xpr_base.h" +#include "xpr/func.h" namespace CNORXZ { @@ -55,8 +56,9 @@ namespace CNORXZ decltype(auto) meta() const { return THIS().meta(); } I& at(const MetaType& meta) { return THIS().at(meta); } - template - decltype(auto) ifor(const Xpr& xpr) const { return THIS().ifor(xpr); } + template + decltype(auto) ifor(const Xpr& xpr, F&& f) const + { return THIS().ifor(xpr,std::forward(f)); } protected: SizeT mPos = 0; diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index c5560af..746da68 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 Xpr& xpr) const + template + decltype(auto) UIndex::ifor(const Xpr& xpr, F&& f) const { - return For<0,Xpr>(this->max(), this->id(), xpr); + return For<0,Xpr>(this->max(), this->id(), xpr, std::forward(f)); } /********************** diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index ec7d65b..939665c 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 Xpr& xpr) const; + template + decltype(auto) ifor(const Xpr& xpr, F&& f) const; private: Sptr mRangePtr; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index 655d6c0..03c0b1f 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -155,9 +155,10 @@ namespace CNORXZ } template - DXpr XIndex::ifor(const DXpr& xpr) const + DXpr XIndex::ifor(const DXpr& xpr, + std::function&& f) const { - return DXpr(mI->ifor(xpr)); + return DXpr(mI->ifor(xpr, std::forward>(f))); } } diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index 1fe2a89..ab65d3e 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -42,7 +42,8 @@ namespace CNORXZ virtual DType meta() const = 0; virtual XIndexBase& at(const DType& meta) = 0; - virtual DXpr ifor(const DXpr& xpr) const = 0; + virtual DXpr ifor(const DXpr& xpr, + std::function&& f) const = 0; }; //Sptr& operator++(Sptr& i); @@ -91,7 +92,8 @@ namespace CNORXZ virtual DType meta() const override final; virtual XIndexBase& at(const DType& meta) override final; - virtual DXpr ifor(const DXpr& xpr) const override final; + virtual DXpr ifor(const DXpr& xpr, + std::function&& f) const override final; private: IndexPtr mI; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 95f9b1d..bb3b440 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 DXpr& xpr) const; + DXpr ifor(const DXpr& xpr, std::function&& f) const; private: diff --git a/src/include/xpr/for.cc.h b/src/include/xpr/for.cc.h index 14b3948..488bc2d 100644 --- a/src/include/xpr/for.cc.h +++ b/src/include/xpr/for.cc.h @@ -8,21 +8,6 @@ namespace CNORXZ { - /************* - * ZeroF * - *************/ - - template - constexpr decltype(auto) ZeroF::operator()(const T&... as) const - { - return 0; - } - - template - constexpr decltype(auto) NoF::operator()(const T&... as) const - { - return; - } /*********** * For * diff --git a/src/include/xpr/for.h b/src/include/xpr/for.h index 0759ad8..d4ea36c 100644 --- a/src/include/xpr/for.h +++ b/src/include/xpr/for.h @@ -4,22 +4,10 @@ #include "base/base.h" #include "xpr_base.h" +#include "func.h" namespace CNORXZ { - class ZeroF - { - public: - template - constexpr decltype(auto) operator()(const T&... as) const; - }; - - class NoF - { - public: - template - constexpr decltype(auto) operator()(const T&... as) const; - }; template class For : public XprInterface> diff --git a/src/include/xpr/func.cc.h b/src/include/xpr/func.cc.h new file mode 100644 index 0000000..e290251 --- /dev/null +++ b/src/include/xpr/func.cc.h @@ -0,0 +1,24 @@ + +#ifndef __cxz_func_cc_h__ +#define __cxz_func_cc_h__ + +#include "func.h" + +namespace CNORXZ +{ + + template + constexpr decltype(auto) ZeroF::operator()(const T&... as) const + { + return 0; + } + + template + constexpr decltype(auto) NoF::operator()(const T&... as) const + { + return; + } + +} + +#endif diff --git a/src/include/xpr/func.h b/src/include/xpr/func.h new file mode 100644 index 0000000..5160674 --- /dev/null +++ b/src/include/xpr/func.h @@ -0,0 +1,25 @@ + +#ifndef __cxz_func_h__ +#define __cxz_func_h__ + +#include "base/base.h" + +namespace CNORXZ +{ + class ZeroF + { + public: + template + constexpr decltype(auto) operator()(const T&... as) const; + }; + + class NoF + { + public: + template + constexpr decltype(auto) operator()(const T&... as) const; + }; + +} + +#endif diff --git a/src/include/xpr/xpr.cc.h b/src/include/xpr/xpr.cc.h index 678c1fd..dd8a5d6 100644 --- a/src/include/xpr/xpr.cc.h +++ b/src/include/xpr/xpr.cc.h @@ -4,3 +4,4 @@ #include "xpr_base.cc.h" #include "for.cc.h" #include "index_id.cc.h" +#include "func.cc.h" diff --git a/src/include/xpr/xpr.h b/src/include/xpr/xpr.h index 597b98c..063a8bd 100644 --- a/src/include/xpr/xpr.h +++ b/src/include/xpr/xpr.h @@ -4,5 +4,6 @@ #include "xpr_base.h" #include "for.h" #include "index_id.h" +#include "func.h" #include "xpr.cc.h" diff --git a/src/lib/ranges/dindex.cc b/src/lib/ranges/dindex.cc index c31d910..83fe638 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 DXpr& xpr) const + DXpr DIndex::ifor(const DXpr& xpr, std::function&& f) const { - return DXpr(mI->ifor(xpr)); + return DXpr(mI->ifor(xpr, std::forward>(f)) ); } } diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index f1f09f8..8af907b 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -171,9 +171,10 @@ namespace CNORXZ return *this; } - DXpr YIndex::ifor(const DXpr& xpr) const + DXpr YIndex::ifor(const DXpr& xpr, std::function&& f) const { assert(0); + f(0,0); return DXpr(); }