From 29b1502e60d1e0473180b55e8d96845019e65680 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 14 Jan 2021 19:20:46 +0100 Subject: [PATCH] unify AssigmentExpr2 and AddExpr --- src/include/multi_array_operation.cc.h | 38 +++++++++++++------------- src/include/multi_array_operation.h | 27 +++++++++++------- src/include/xfor/exttype.h | 36 ++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 70dbf7e..9c88d37 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -165,50 +165,50 @@ namespace MultiArrayTools }; - template - AssignmentExpr2::AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec) : + template + AssignmentExpr::AssignmentExpr(T* dataPtr, const Target& tar, const OpClass& sec) : mTar(tar), mSec(sec), mDataPtr(dataPtr) {} - template - inline void AssignmentExpr2::operator()(size_t start) + template + inline void AssignmentExpr::operator()(size_t start) { ExtType last = rootSteps(); last.zero(); //mDataPtr[OpIndexResolve::get(start,last)] = mSec.get(last.next()); - IAssign::f(mDataPtr,OpIndexResolve::get(start,last),mSec,last.next()); + IOp::f(mDataPtr,OpIndexResolve::get(start,last),mSec,last.next()); //mDataPtr[last.val()] = mSec.get(last.next()); } - template - inline void AssignmentExpr2::operator()(size_t start, ExtType last) + template + inline void AssignmentExpr::operator()(size_t start, ExtType last) { //CHECK; //mDataPtr[OpIndexResolve::get(start,last)] = mSec.get(last.next()); - IAssign::f(mDataPtr,OpIndexResolve::get(start,last),mSec,last.next()); + IOp::f(mDataPtr,OpIndexResolve::get(start,last),mSec,last.next()); } - template - typename AssignmentExpr2::ExtType - AssignmentExpr2::rootSteps(std::intptr_t iPtrNum) const + template + typename AssignmentExpr::ExtType + AssignmentExpr::rootSteps(std::intptr_t iPtrNum) const { return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) ); } - template - inline void AssignmentExpr2::operator()(size_t mlast, DExt last) + template + inline void AssignmentExpr::operator()(size_t mlast, DExt last) { (*this)(mlast, std::dynamic_pointer_cast>(last)->ext()); } - template - inline DExt AssignmentExpr2::dRootSteps(std::intptr_t iPtrNum) const + template + inline DExt AssignmentExpr::dRootSteps(std::intptr_t iPtrNum) const { return std::make_shared>(rootSteps(iPtrNum)); } - template - inline DExt AssignmentExpr2::dExtension() const + template + inline DExt AssignmentExpr::dExtension() const { CHECK; return nullptr; //???!!! @@ -298,7 +298,7 @@ namespace MultiArrayTools CHECK; return nullptr; //???!!! } - + /* template AddExpr::AddExpr(T* dataPtr, const Target& tar, const OpClass& sec) : mTar(tar), mSec(sec), mDataPtr(dataPtr) {} @@ -348,7 +348,7 @@ namespace MultiArrayTools CHECK; return nullptr; //???!!! } - + */ /**************************** * ConstOperationRoot * ****************************/ diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 742fb72..b8ac7e8 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -244,11 +244,11 @@ namespace MultiArrayTools }; - template - class AssignmentExpr2 : public ExpressionBase + template + class AssignmentExpr : public ExpressionBase { private: - AssignmentExpr2() = default; + AssignmentExpr() = default; Target mTar; OpClass mSec; @@ -260,15 +260,15 @@ namespace MultiArrayTools static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE; typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType; - AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec); - AssignmentExpr2(const AssignmentExpr2& in) = default; - AssignmentExpr2(AssignmentExpr2&& in) = default; - AssignmentExpr2& operator=(const AssignmentExpr2& in) = default; - AssignmentExpr2& operator=(AssignmentExpr2&& in) = default; + AssignmentExpr(T* dataPtr, const Target& tar, const OpClass& sec); + AssignmentExpr(const AssignmentExpr& in) = default; + AssignmentExpr(AssignmentExpr&& in) = default; + AssignmentExpr& operator=(const AssignmentExpr& in) = default; + AssignmentExpr& operator=(AssignmentExpr&& in) = default; virtual std::shared_ptr deepCopy() const override final { - return std::make_shared>(*this); + return std::make_shared>(*this); } inline void operator()(size_t start = 0); @@ -281,6 +281,12 @@ namespace MultiArrayTools inline DExt dExtension() const override final; }; + template + using AssignmentExpr2 = AssignmentExpr; + + template + using AddExpr = AssignmentExpr; + template class MOp { @@ -371,6 +377,7 @@ namespace MultiArrayTools } //template + /* template class AddExpr : public ExpressionBase { @@ -411,7 +418,7 @@ namespace MultiArrayTools inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; inline DExt dExtension() const override final; }; - + */ template class ConstOperationRoot : public OperationTemplate > { diff --git a/src/include/xfor/exttype.h b/src/include/xfor/exttype.h index 9f94784..b6202c4 100644 --- a/src/include/xfor/exttype.h +++ b/src/include/xfor/exttype.h @@ -85,7 +85,17 @@ namespace MultiArrayHelper inline auto nn() const -> decltype(Getter::getX(*this)) { return Getter::getX(*this); } - + + inline bool operator==(const MExt& in) const + { + return mExt == in.mExt and mNext == in.mNext; + } + + inline bool operator==(size_t in) const + { + return mExt == in and mNext == in; + } + inline MExt operator+(const MExt& in) const; inline MExt operator+(const None& in) const; inline MExt operator*(size_t in) const; @@ -110,7 +120,17 @@ namespace MultiArrayHelper None(const Y& y) {} static constexpr size_t SIZE = 0; - + + inline bool operator==(const None& in) const + { + return true; + } + + inline bool operator==(size_t in) const + { + return true; // CHECK!!! + } + inline None operator+(const None& in) const { return None(); } inline None operator*(size_t in) const { return None(); } @@ -157,7 +177,17 @@ namespace MultiArrayHelper template inline MExt(const MExt& y); - + + inline bool operator==(const MExt& in) const + { + return mExt == in.mExt; + } + + inline bool operator==(size_t in) const + { + return mExt == in; + } + inline const size_t& val() const; inline None next() const { return None(); }