diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index e2bbaed..404cffa 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -155,6 +155,25 @@ namespace MultiArrayTools return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) ); } + template + inline void AssignmentExpr2::operator()(size_t mlast, DExt last) + { + (*this)(mlast, std::dynamic_pointer_cast>(last)->ext()); + } + + template + inline DExt AssignmentExpr2::dRootSteps(std::intptr_t iPtrNum) const + { + return std::make_shared>(rootSteps(iPtrNum)); + } + + template + inline DExt AssignmentExpr2::dExtension() const + { + CHECK; + return nullptr; //???!!! + } + template AddExpr::AddExpr(T* dataPtr, const Target& tar, const OpClass& sec) : mTar(tar), mSec(sec), mDataPtr(dataPtr) {} @@ -173,7 +192,6 @@ namespace MultiArrayTools //return mSec.rootSteps(iPtrNum); } - /**************************** * ConstOperationRoot * ****************************/ diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 0ff6a4c..86670fd 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -17,6 +17,8 @@ #include "arith.h" +#include "xfor/xfor.h" + namespace MultiArrayTools { @@ -106,7 +108,7 @@ namespace MultiArrayTools }; template - class AssignmentExpr2 + class AssignmentExpr2 : public ExpressionBase { private: AssignmentExpr2() = default; @@ -128,6 +130,11 @@ namespace MultiArrayTools inline void operator()(size_t start = 0); inline void operator()(size_t start, ExtType last); auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; + + inline void operator()(size_t mlast, DExt last) override final; + + inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; + inline DExt dExtension() const override final; }; //template diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index e70bae3..ea70f52 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -21,8 +21,42 @@ namespace MultiArrayHelper // 'HIDDEN FOR' CLASS for nested for loops in contractions a.s.o. // (NO COUNTING OF MASTER POSITION !!!!!) - typedef std::pair DExt; + //typedef std::pair DExt; + class ExtBase + { + public: + ExtBase() = default; + ExtBase(const ExtBase& in) = default; + ExtBase(ExtBase&& in) = default; + ExtBase& operator=(const ExtBase& in) = default; + ExtBase& operator=(ExtBase&& in) = default; + + //virtual size_t size() const = 0; + //virtual size_t rootSteps() const = 0; + }; + + template + class ExtT : public ExtBase + { + private: + ExtType mExt; + public: + ExtT() = default; + ExtT(const ExtT& in) = default; + ExtT(ExtT&& in) = default; + ExtT& operator=(const ExtT& in) = default; + ExtT& operator=(ExtT&& in) = default; + + ExtT(const ExtType& in) : mExt(in) {} + + //virtual size_t size() const override final; + //virtual size_t rootSteps() const override final; + const ExtType& ext() const { return mExt; } + }; + + typedef std::shared_ptr DExt; + inline MExt mkExt(size_t s) { return MExt(s); } class ExpressionBase @@ -367,7 +401,7 @@ namespace MultiArrayHelper namespace MultiArrayHelper { - + /***************** * F o r * *****************/ @@ -393,7 +427,8 @@ namespace MultiArrayHelper template inline void For::operator()(size_t mlast, DExt last) { - operator()(mlast, *reinterpret_cast(last.first)); + operator()(mlast, std::dynamic_pointer_cast>(last)->ext()); + //operator()(mlast, *reinterpret_cast(last.first)); } template @@ -438,16 +473,18 @@ namespace MultiArrayHelper template DExt For::dRootSteps(std::intptr_t iPtrNum) const { - mRootSteps = rootSteps(iPtrNum); - return std::make_pair(reinterpret_cast(&mRootSteps), - sizeof(ExtType)/sizeof(size_t)); + return std::make_shared>(rootSteps(iPtrNum)); + //mRootSteps = rootSteps(iPtrNum); + //return std::make_pair(reinterpret_cast(&mRootSteps), + // sizeof(ExtType)/sizeof(size_t)); } template DExt For::dExtension() const { - return std::make_pair(reinterpret_cast(&mExt), - sizeof(ExtType)/sizeof(size_t)); + return std::make_shared>(mExt); + //return std::make_pair(reinterpret_cast(&mExt), + // sizeof(ExtType)/sizeof(size_t)); } template @@ -482,7 +519,8 @@ namespace MultiArrayHelper template inline void PFor::operator()(size_t mlast, DExt last) { - operator()(mlast, *reinterpret_cast(last.first)); + operator()(mlast, std::dynamic_pointer_cast>(last)->ext()); + //operator()(mlast, *reinterpret_cast(last.first)); } template @@ -545,16 +583,18 @@ namespace MultiArrayHelper template DExt PFor::dRootSteps(std::intptr_t iPtrNum) const { - mRootSteps = rootSteps(iPtrNum); - return std::make_pair(reinterpret_cast(&mRootSteps), - sizeof(ExtType)/sizeof(size_t)); + return std::make_shared>(rootSteps(iPtrNum)); + //mRootSteps = rootSteps(iPtrNum); + //return std::make_pair(reinterpret_cast(&mRootSteps), + // sizeof(ExtType)/sizeof(size_t)); } template DExt PFor::dExtension() const { - return std::make_pair(reinterpret_cast(&mExt), - sizeof(ExtType)/sizeof(size_t)); + return std::make_shared>(mExt); + //return std::make_pair(reinterpret_cast(&mExt), + // sizeof(ExtType)/sizeof(size_t)); } /************************ @@ -586,7 +626,8 @@ namespace MultiArrayHelper template inline void SingleExpression::operator()(size_t mlast, DExt last) { - operator()(mlast, *reinterpret_cast(last.first)); + operator()(mlast, std::dynamic_pointer_cast>(last)->ext()); + //operator()(mlast, *reinterpret_cast(last.first)); } template @@ -628,16 +669,18 @@ namespace MultiArrayHelper template DExt SingleExpression::dRootSteps(std::intptr_t iPtrNum) const { - mRootSteps = rootSteps(iPtrNum); - return std::make_pair(reinterpret_cast(&mRootSteps), - sizeof(ExtType)/sizeof(size_t)); + return std::make_shared>(rootSteps(iPtrNum)); + //mRootSteps = rootSteps(iPtrNum); + //return std::make_pair(reinterpret_cast(&mRootSteps), + // sizeof(ExtType)/sizeof(size_t)); } template DExt SingleExpression::dExtension() const { - return std::make_pair(reinterpret_cast(&mExt), - sizeof(ExtType)/sizeof(size_t)); + return std::make_shared>(mExt); + //return std::make_pair(reinterpret_cast(&mExt), + // sizeof(ExtType)/sizeof(size_t)); } /**************** @@ -670,7 +713,8 @@ namespace MultiArrayHelper template inline void SubExpr::operator()(size_t mlast, DExt last) { - operator()(mlast, *reinterpret_cast(last.first)); + operator()(mlast, std::dynamic_pointer_cast>(last)->ext()); + //operator()(mlast, *reinterpret_cast(last.first)); } template @@ -711,16 +755,18 @@ namespace MultiArrayHelper template DExt SubExpr::dRootSteps(std::intptr_t iPtrNum) const { - mRootSteps = rootSteps(iPtrNum); - return std::make_pair(reinterpret_cast(&mRootSteps), - sizeof(ExtType)/sizeof(size_t)); + return std::make_shared>(rootSteps(iPtrNum)); + //mRootSteps = rootSteps(iPtrNum); + //return std::make_pair(reinterpret_cast(&mRootSteps), + //sizeof(ExtType)/sizeof(size_t)); } template DExt SubExpr::dExtension() const { - return std::make_pair(reinterpret_cast(&mExt), - sizeof(ExtType)/sizeof(size_t)); + return std::make_shared>(mExt); + //return std::make_pair(reinterpret_cast(&mExt), + // sizeof(ExtType)/sizeof(size_t)); } /*************************** @@ -764,9 +810,7 @@ namespace MultiArrayHelper inline void ExpressionHolder::operator()(size_t mlast, ExtType last) { mExpr(mlast, - std::make_pair - (reinterpret_cast(&last), - sizeof(ExtType)/sizeof(size_t))); + std::make_shared>(last)); } template @@ -791,14 +835,16 @@ namespace MultiArrayHelper auto ExpressionHolder::rootSteps(std::intptr_t iPtrNum) const -> ExtType { - return *reinterpret_cast( mExpr.dRootSteps(iPtrNum).first ); + return std::dynamic_pointer_cast>(*mExpr.dRootSteps(iPtrNum))->ext(); + //return *reinterpret_cast( mExpr.dRootSteps(iPtrNum).first ); } template auto ExpressionHolder::extension() const -> ExtType { - return *reinterpret_cast( mExpr.dExtension().first ); + return std::dynamic_pointer_cast>(*mExpr.dExtension())->ext(); + //return *reinterpret_cast( mExpr.dExtension().first ); }