mdim test3 works
This commit is contained in:
parent
c4431a83a9
commit
f019b4c2ff
3 changed files with 61 additions and 16 deletions
|
@ -158,6 +158,14 @@ namespace MultiArrayTools
|
|||
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
|
||||
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*************************
|
||||
* MultiRangeFactory *
|
||||
*************************/
|
||||
|
|
|
@ -67,6 +67,12 @@ namespace MultiArrayTools
|
|||
|
||||
std::shared_ptr<RangeType> 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>&... indices);
|
||||
|
||||
virtual std::string id() const override { return std::string("mul") + std::to_string(IB::mId); }
|
||||
};
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ namespace {
|
|||
std::vector<double> v1 = { 2.917, 9.436, 0.373 };
|
||||
std::vector<double> v2 = { 8.870, 4.790 };
|
||||
std::vector<double> v3 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 };
|
||||
std::vector<double> v4 = { 1.470, 2.210 };
|
||||
};
|
||||
|
||||
TEST_F(OpTest_1Dim, ExecOp)
|
||||
|
@ -137,29 +138,59 @@ namespace {
|
|||
MultiArray<double,MRange,SRange> res(mr1ptr,sr4ptr);
|
||||
MultiArray<double,MRange> ma1(mr1ptr, v3);
|
||||
MultiArray<double,SRange> ma2(sr4ptr, v2);
|
||||
MultiArray<double,SRange> ma3(sr4ptr, v4);
|
||||
|
||||
auto i1 = std::dynamic_pointer_cast<MRange::IndexType>( mr1ptr->index() );
|
||||
auto i2 = std::dynamic_pointer_cast<SRange::IndexType>( 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<double,MRange,SRange> res(mr1ptr,sr4ptr);
|
||||
MultiArray<double,MRange> ma1(mr1ptr, v3);
|
||||
MultiArray<double,SRange> ma2(sr2ptr, v1);
|
||||
MultiArray<double,SRange> ma3(sr4ptr, v4);
|
||||
|
||||
auto si1 = std::dynamic_pointer_cast<SRange::IndexType>( sr2ptr->index() );
|
||||
auto si2 = std::dynamic_pointer_cast<SRange::IndexType>( sr3ptr->index() );
|
||||
auto si3 = std::dynamic_pointer_cast<SRange::IndexType>( sr4ptr->index() );
|
||||
auto mi = std::dynamic_pointer_cast<MRange::IndexType>( 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
|
||||
|
||||
|
|
Loading…
Reference in a new issue