From f019b4c2ff2d1ad64a90fef0f6928862854d1bb5 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sat, 26 Aug 2017 16:45:46 +0200 Subject: [PATCH] mdim test3 works --- src/multi_range.cc | 8 ++++++ src/multi_range.h | 6 +++++ src/op_unit_test.cc | 63 +++++++++++++++++++++++++++++++++------------ 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/src/multi_range.cc b/src/multi_range.cc index 0d74682..808e771 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -157,6 +157,14 @@ namespace MultiArrayTools { return std::dynamic_pointer_cast( IB::mRangePtr ); } + + template + MultiIndex& MultiIndex::operator()(std::shared_ptr&... indices) + { + PackNum::swapIndices(mIPack, indices...); + PackNum::setIndexPack(mIPack, IB::mPos); + return *this; + } /************************* * MultiRangeFactory * diff --git a/src/multi_range.h b/src/multi_range.h index e85236b..1d708d0 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -67,6 +67,12 @@ namespace MultiArrayTools std::shared_ptr range() const; + // raplace instances (in contrast to its analogon in ContainerIndex + // MultiIndices CANNOT be influences be its subindices, so there is + // NO foreign/external controll) + // Do NOT share index instances between two or more MultiIndex instances + MultiIndex& operator()(std::shared_ptr&... indices); + virtual std::string id() const override { return std::string("mul") + std::to_string(IB::mId); } }; diff --git a/src/op_unit_test.cc b/src/op_unit_test.cc index 18cb511..acb9330 100644 --- a/src/op_unit_test.cc +++ b/src/op_unit_test.cc @@ -93,6 +93,7 @@ namespace { std::vector v1 = { 2.917, 9.436, 0.373 }; std::vector v2 = { 8.870, 4.790 }; std::vector v3 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 }; + std::vector v4 = { 1.470, 2.210 }; }; TEST_F(OpTest_1Dim, ExecOp) @@ -118,7 +119,7 @@ namespace { auto i1 = std::dynamic_pointer_cast( sr2ptr->index() ); auto i2 = std::dynamic_pointer_cast( sr4ptr->index() ); - + res(i1,i2) = ma1(i1) + ma2(i2); EXPECT_EQ( fabs( res.at(mkt('1','A')) - (2.917 + 8.870) ) < 0.0001, true ); @@ -137,29 +138,59 @@ namespace { MultiArray res(mr1ptr,sr4ptr); MultiArray ma1(mr1ptr, v3); MultiArray ma2(sr4ptr, v2); - + MultiArray ma3(sr4ptr, v4); + auto i1 = std::dynamic_pointer_cast( mr1ptr->index() ); auto i2 = std::dynamic_pointer_cast( sr4ptr->index() ); - res(i1,i2) = ma1(i1) + ma2(i2); + res(i1,i2) = ma1(i1) + ma2(i2) + ma3(i2); - EXPECT_EQ( fabs( res.at(mkt(mkt('1','a'),'A')) - (0.353 + 8.870) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('1','a'),'B')) - (0.353 + 4.790) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('1','b'),'A')) - (4.005 + 8.870) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('1','b'),'B')) - (4.005 + 4.790) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('1','a'),'A')) - (0.353 + 8.870 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('1','a'),'B')) - (0.353 + 4.790 + 2.210) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('1','b'),'A')) - (4.005 + 8.870 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('1','b'),'B')) - (4.005 + 4.790 + 2.210) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('2','a'),'A')) - (1.070 + 8.870) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('2','a'),'B')) - (1.070 + 4.790) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('2','b'),'A')) - (2.310 + 8.870) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('2','b'),'B')) - (2.310 + 4.790) ) < 0.0001, true ); - - EXPECT_EQ( fabs( res.at(mkt(mkt('3','a'),'A')) - (9.243 + 8.870) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('3','a'),'B')) - (9.243 + 4.790) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('3','b'),'A')) - (2.911 + 8.870) ) < 0.0001, true ); - EXPECT_EQ( fabs( res.at(mkt(mkt('3','b'),'B')) - (2.911 + 4.790) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('2','a'),'A')) - (1.070 + 8.870 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('2','a'),'B')) - (1.070 + 4.790 + 2.210) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('2','b'),'A')) - (2.310 + 8.870 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('2','b'),'B')) - (2.310 + 4.790 + 2.210) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('3','a'),'A')) - (9.243 + 8.870 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('3','a'),'B')) - (9.243 + 4.790 + 2.210) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('3','b'),'A')) - (2.911 + 8.870 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('3','b'),'B')) - (2.911 + 4.790 + 2.210) ) < 0.0001, true ); } + TEST_F(OpTest_MDim, ExecOp3) + { + MultiArray res(mr1ptr,sr4ptr); + MultiArray ma1(mr1ptr, v3); + MultiArray ma2(sr2ptr, v1); + MultiArray ma3(sr4ptr, v4); + + auto si1 = std::dynamic_pointer_cast( sr2ptr->index() ); + auto si2 = std::dynamic_pointer_cast( sr3ptr->index() ); + auto si3 = std::dynamic_pointer_cast( sr4ptr->index() ); + auto mi = std::dynamic_pointer_cast( mr1ptr->index() ); + mi->operator()(si1,si2); + + res(mi,si3) = ma1(mi) + ma2(si1) + ma3(si3); + + EXPECT_EQ( fabs( res.at(mkt(mkt('1','a'),'A')) - (0.353 + 2.917 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('1','a'),'B')) - (0.353 + 2.917 + 2.210) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('1','b'),'A')) - (4.005 + 2.917 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('1','b'),'B')) - (4.005 + 2.917 + 2.210) ) < 0.0001, true ); + + EXPECT_EQ( fabs( res.at(mkt(mkt('2','a'),'A')) - (1.070 + 9.436 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('2','a'),'B')) - (1.070 + 9.436 + 2.210) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('2','b'),'A')) - (2.310 + 9.436 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('2','b'),'B')) - (2.310 + 9.436 + 2.210) ) < 0.0001, true ); + + EXPECT_EQ( fabs( res.at(mkt(mkt('3','a'),'A')) - (9.243 + 0.373 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('3','a'),'B')) - (9.243 + 0.373 + 2.210) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('3','b'),'A')) - (2.911 + 0.373 + 1.470) ) < 0.0001, true ); + EXPECT_EQ( fabs( res.at(mkt(mkt('3','b'),'B')) - (2.911 + 0.373 + 2.210) ) < 0.0001, true ); + } } // anonymous namspace