From 7afd193d09cc58746d5221bb75240dfe25239614 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 27 Aug 2020 23:48:04 +0200 Subject: [PATCH] im com --- src/include/dynamic_operation.cc.h | 32 +++++++++++++++++++-------- src/include/dynamic_operation.h | 35 ++++++++++++++++++++++-------- src/tests/op4_unit_test.cc | 27 +++++++++++++++++++++-- 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/src/include/dynamic_operation.cc.h b/src/include/dynamic_operation.cc.h index 227c0ee..07fc65f 100644 --- a/src/include/dynamic_operation.cc.h +++ b/src/include/dynamic_operation.cc.h @@ -1,5 +1,6 @@ #include "dynamic_operation.h" +#include "helper_tools.h" namespace MultiArrayTools { @@ -43,23 +44,28 @@ namespace MultiArrayTools template DynamicOuterOp::DynamicOuterOp(const Operation& op, const std::shared_ptr&... inds) - : mOp(op) + : mOp(op), + mMa(std::make_shared>(mkArray(inds->range()...))), + mProto((*mMa)(inds...)) { - //...!!! - // setup operations + /* + auto ll = mkILoop(std::make_tuple(mProto.mOp,mOp), std::make_tuple(inds...), + std::make_tuple(mMa), std::make_tuple(mProto.mOp.assign( mOp )), + std::array({0}), std::array({0})); + */ } template - OpH> DynamicOuterOp::get(const DExtT& pos) const + OpH> DynamicOuterOp::get(const DExtT& pos) const { mOp.get(pos.expl()); - //... + //mL(); // execute assignment... care about threads!!! - return OpH>(); // empty + return mProto.mOp; // empty } template - DynamicOperationBase>>& + DynamicOperationBase>>& DynamicOuterOp::set(const DExtT& pos) { mOp.set(pos.expl()); @@ -79,16 +85,24 @@ namespace MultiArrayTools } template - const OpH>* DynamicOuterOp::data() const + const OpH>* DynamicOuterOp::data() const { return &mProto; } template - std::shared_ptr>>> + std::shared_ptr>>> DynamicOuterOp::deepCopy() const { return std::make_shared>(*this); } + template + DynamicOuterOp + mkDynOutOp(const Operation& op, const std::shared_ptr&... inds) + { + return DynamicOuterOp(op, inds...); + } + } // namespace MultiArrayTools diff --git a/src/include/dynamic_operation.h b/src/include/dynamic_operation.h index 3ba7f86..a073c12 100644 --- a/src/include/dynamic_operation.h +++ b/src/include/dynamic_operation.h @@ -61,16 +61,26 @@ namespace MultiArrayTools template struct OpH { - Op mOp; + Op mOp; + OpH(const Op& op) : mOp(op) {} }; template - class DynamicOuterOp : public DynamicOperationBase>> + class DynamicOuterOp : public DynamicOperationBase>> { private: Operation mOp; - //ConstOperationRoot mProto; - OpH> mProto; + //OperationRoot mProto; + std::shared_ptr> mMa; + OpH> mProto; + /* + typedef ILoop,Operation>, + std::tuple...>, + std::tuple>>, + std::tuple> LoopT; + + LoopT mL; + */ public: typedef decltype(mOp.rootSteps()) ET; //typedef decltype(std::declval().rootSteps()) ET; @@ -82,15 +92,19 @@ namespace MultiArrayTools DynamicOuterOp& operator=(DynamicOuterOp&& in) = default; DynamicOuterOp(const Operation& op, const std::shared_ptr&... inds); - - virtual OpH> get(const DExtT& pos) const override final; - virtual DynamicOperationBase>>& set(const DExtT& pos) override final; + + virtual OpH> get(const DExtT& pos) const override final; + virtual DynamicOperationBase>>& set(const DExtT& pos) override final; virtual DExtT rootSteps(std::intptr_t iPtrNum = 0) const override final; virtual DynamicExpression loop(const DynamicExpression& exp) const override final; - virtual const OpH>* data() const override final; - virtual std::shared_ptr>>> deepCopy() const override final; + virtual const OpH>* data() const override final; + virtual std::shared_ptr>>> deepCopy() const override final; }; + template + DynamicOuterOp + mkDynOutOp(const Operation& op, const std::shared_ptr&... inds); + template class DynamicO : public OperationTemplate> { @@ -113,6 +127,9 @@ namespace MultiArrayTools template DynamicO(const Op& op) : mOp(std::make_shared>(op)) {} + DynamicO(const std::shared_ptr>& op) : + mOp(op) {} + template inline T get(const DExtTX& pos) const { return mOp->get(pos.reduce()); } template diff --git a/src/tests/op4_unit_test.cc b/src/tests/op4_unit_test.cc index f3da2bd..8d07a16 100644 --- a/src/tests/op4_unit_test.cc +++ b/src/tests/op4_unit_test.cc @@ -53,12 +53,15 @@ namespace std::map> imap; std::shared_ptr dr1; + std::shared_ptr dr1a; std::shared_ptr dr2; std::shared_ptr dr3; std::shared_ptr dr4; std::shared_ptr dr5; std::shared_ptr dr6; std::shared_ptr cr1; + + std::shared_ptr ci4; OpTest_Dyn() { @@ -70,6 +73,7 @@ namespace auto cr5 = createRangeE(13); dr1 = createRangeE(cr2,cr2,cr3,cr4); + dr1a = createRangeE(cr2,cr2,cr3); dr2 = createRangeE(cr3,cr3,cr4); dr3 = createRangeE(cr2,cr5); dr5 = createRangeE(cr5); @@ -94,7 +98,8 @@ namespace imap["i2_2"] = mkIndexW(getIndex(cr2)); imap["i3_1"] = mkIndexW(getIndex(cr3)); imap["i3_2"] = mkIndexW(getIndex(cr3)); - imap["i4_1"] = mkIndexW(getIndex(cr4)); + ci4 = getIndex(cr4); + imap["i4_1"] = mkIndexW(ci4); imap["i4_2"] = mkIndexW(getIndex(cr4)); imap["i5_1"] = mkIndexW(getIndex(cr5)); imap["i5_2"] = mkIndexW(getIndex(cr5)); @@ -105,21 +110,39 @@ namespace { auto i1 = getIndex(cr1); auto di1 = getIndex(dr1); + auto di1a = getIndex(dr1a); auto di2 = getIndex(dr2); auto di4 = getIndex(dr4); + auto mi = mkMIndex(i1,di1a); + (*di1)({imap["i2_1"],imap["i2_2"],imap["i3_1"],imap["i4_1"]}); + (*di1a)({imap["i2_1"],imap["i2_2"],imap["i3_1"]}); (*di2)({imap["i3_1"],imap["i3_1"],imap["i4_2"]}); (*di4)({imap["i2_1"],imap["i3_1"],imap["i4_1"],imap["i4_2"]}); auto resx1 = res1; auto resx2 = res1; auto resx3 = res1; + auto resx4 = res1; + //auto xx = std::make_shared(resx4); res1(i1,di4) = ma1(i1,di1) * ma2(i1,di2); resx1(i1,di4) = mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2)); resx2(i1,di4) = mkDynOp(ma1(i1,di1) * ma2(i1,di2)); resx3(i1,di4) = mkDynOp(mkDynOp(ma1(i1,di1)) * mkDynOp(ma2(i1,di2))); - + + auto op1 = mkDynOutOp(ma1(i1,di1) * ma2(i1,di2), ci4); + /**auto opr = resx4(i1,di4); + auto loop = mkILoop(std::make_tuple(opr,op1), std::make_tuple(ci4), + std::make_tuple(xx), std::make_tuple(opr.assign( op1.data()->mOp )), + //std::make_tuple(), std::make_tuple(), + std::array({1}), std::array({0})); + */ + //std::array(), std::array()); + //!!!! + //mi->ifor(1, loop)(); + + //mi->ifor(1, opr.assign( op1.data()->mOp ))(); auto i2_1 = imap.at("i2_1"); auto i2_2 = imap.at("i2_2"); auto i3_1 = imap.at("i3_1");