From fdb1bb6833d569b5fe1dfc2da2ca154043d0b5fe Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 14 Jan 2021 17:40:08 +0100 Subject: [PATCH] xfor: vectrization requirements --- src/include/map_range.cc.h | 23 +++++++++++++++++++++++ src/include/map_range.h | 10 ++++++++-- src/include/multi_array_operation.cc.h | 6 +++--- src/include/xfor/xfor.h | 20 ++++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/include/map_range.cc.h b/src/include/map_range.cc.h index 678b32e..8f786dd 100644 --- a/src/include/map_range.cc.h +++ b/src/include/map_range.cc.h @@ -27,6 +27,18 @@ namespace MultiArrayTools assert(mIndPtr != nullptr); } + template + std::shared_ptr OpExpr::deepCopy() const + { + return std::make_shared>(*this); + } + + template + inline void OpExpr::operator()(size_t mlast, DExt last) + { + operator()(mlast, std::dynamic_pointer_cast>(last)->ext()); + } + template inline void OpExpr::operator()(size_t mlast, ExtType last) @@ -63,7 +75,18 @@ namespace MultiArrayTools //return mExpr.rootSteps(iPtrNum).extend( mOp.rootSteps(iPtrNum) ); } + template + DExt OpExpr::dRootSteps(std::intptr_t iPtrNum) const + { + return std::make_shared>(rootSteps(iPtrNum)); + } + template + DExt OpExpr::dExtension() const + { + return std::make_shared>(mExt); + } + // -> define in range_base.cc //std::shared_ptr mkMULTI(const char** dp); diff --git a/src/include/map_range.h b/src/include/map_range.h index fcb56f3..42623b0 100644 --- a/src/include/map_range.h +++ b/src/include/map_range.h @@ -50,7 +50,7 @@ namespace MultiArrayTools template //template - class OpExpr + class OpExpr : public ExpressionBase { public: //typedef typename Index::OIType OIType; @@ -80,11 +80,17 @@ namespace MultiArrayTools OpExpr(const Op& mapf, const Index* ind, size_t step, Expr ex); + virtual std::shared_ptr deepCopy() const override final; + + inline void operator()(size_t mlast, DExt last) override final; inline void operator()(size_t mlast, ExtType last); - inline void operator()(size_t mlast = 0); + inline void operator()(size_t mlast = 0) override final; auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; + virtual DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; + virtual DExt dExtension() const override final; + }; template diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index f0d9c32..70dbf7e 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -401,7 +401,7 @@ namespace MultiArrayTools template inline const V& ConstOperationRoot::vget(ET pos) const { - return *reinterpret_cast(mDataPtr+pos.val()); + return *(reinterpret_cast(mDataPtr)+pos.val()); } template @@ -668,7 +668,7 @@ namespace MultiArrayTools template inline V& OperationRoot::vget(ET pos) const { - return *reinterpret_cast(mDataPtr + pos.val()); + return *(reinterpret_cast(mDataPtr)+pos.val()); } template @@ -815,7 +815,7 @@ namespace MultiArrayTools template inline V& ParallelOperationRoot::vget(ET pos) const { - return *reinterpret_cast(mDataPtr+pos.val()); + return *(reinterpret_cast(mDataPtr)+pos.val()); } template diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index 58a8106..292b666 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -173,6 +173,8 @@ namespace MultiArrayHelper ExpressionBase& operator=(const ExpressionBase& in) = default; ExpressionBase& operator=(ExpressionBase&& in) = default; + virtual std::intptr_t vec(size_t vs) { return 0; } + virtual std::shared_ptr deepCopy() const = 0; virtual void operator()(size_t mlast, DExt last) = 0; @@ -377,6 +379,15 @@ namespace MultiArrayHelper return std::make_shared>(*this); } + virtual std::intptr_t vec(size_t vs) override final + { + if(mStep == 1 and mMax % vs == 0){ + mMax /= vs; + return reinterpret_cast(mIndPtr); + } + return mExpr.vec(vs); + } + inline void operator()(size_t mlast, DExt last) override final; inline void operator()(size_t mlast, ExtType last) ; inline void operator()(size_t mlast = 0) override final; @@ -425,6 +436,15 @@ namespace MultiArrayHelper PFor(const IndexClass* indPtr, size_t step, Expr expr); + virtual std::intptr_t vec(size_t vs) override final + { + if(mStep == 1 and mMax % vs == 0){ + mMax /= vs; + return reinterpret_cast(mIndPtr); + } + return mExpr.vec(vs); + } + virtual std::shared_ptr deepCopy() const override final { return std::make_shared>(*this);