add basic operations (+-*/)
This commit is contained in:
parent
f019b4c2ff
commit
8a75177b39
3 changed files with 61 additions and 23 deletions
|
@ -22,12 +22,36 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class OperationClass>
|
template <class OperationClass>
|
||||||
template <class Second>
|
template <class Second>
|
||||||
Operation<double,std::plus<double>,OperationClass,Second>
|
auto OperationTemplate<OperationClass>::operator+(const Second& in) const
|
||||||
OperationTemplate<OperationClass>::operator+(const Second& in) const
|
-> Operation<double,std::plus<double>,OperationClass,Second>
|
||||||
{
|
{
|
||||||
return Operation<double,std::plus<double>,OperationClass,Second>(*mOc, in);
|
return Operation<double,std::plus<double>,OperationClass,Second>(*mOc, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class OperationClass>
|
||||||
|
template <class Second>
|
||||||
|
auto OperationTemplate<OperationClass>::operator-(const Second& in) const
|
||||||
|
-> Operation<double,std::minus<double>,OperationClass,Second>
|
||||||
|
{
|
||||||
|
return Operation<double,std::minus<double>,OperationClass,Second>(*mOc, in);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class OperationClass>
|
||||||
|
template <class Second>
|
||||||
|
auto OperationTemplate<OperationClass>::operator*(const Second& in) const
|
||||||
|
-> Operation<double,std::multiplies<double>,OperationClass,Second>
|
||||||
|
{
|
||||||
|
return Operation<double,std::multiplies<double>,OperationClass,Second>(*mOc, in);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class OperationClass>
|
||||||
|
template <class Second>
|
||||||
|
auto OperationTemplate<OperationClass>::operator/(const Second& in) const
|
||||||
|
-> Operation<double,std::divides<double>,OperationClass,Second>
|
||||||
|
{
|
||||||
|
return Operation<double,std::divides<double>,OperationClass,Second>(*mOc, in);
|
||||||
|
}
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
* OperationMaster *
|
* OperationMaster *
|
||||||
*************************/
|
*************************/
|
||||||
|
|
|
@ -56,7 +56,21 @@ namespace MultiArrayTools
|
||||||
OperationTemplate(OperationClass* oc);
|
OperationTemplate(OperationClass* oc);
|
||||||
|
|
||||||
template <class Second>
|
template <class Second>
|
||||||
Operation<double,std::plus<double>,OperationClass,Second> operator+(const Second& in) const;
|
auto operator+(const Second& in) const
|
||||||
|
-> Operation<double,std::plus<double>,OperationClass,Second>;
|
||||||
|
|
||||||
|
template <class Second>
|
||||||
|
auto operator-(const Second& in) const
|
||||||
|
-> Operation<double,std::minus<double>,OperationClass,Second>;
|
||||||
|
|
||||||
|
template <class Second>
|
||||||
|
auto operator*(const Second& in) const
|
||||||
|
-> Operation<double,std::multiplies<double>,OperationClass,Second>;
|
||||||
|
|
||||||
|
template <class Second>
|
||||||
|
auto operator/(const Second& in) const
|
||||||
|
-> Operation<double,std::divides<double>,OperationClass,Second>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OperationClass* mOc;
|
OperationClass* mOc;
|
||||||
};
|
};
|
||||||
|
|
|
@ -120,16 +120,16 @@ namespace {
|
||||||
auto i1 = std::dynamic_pointer_cast<SRange::IndexType>( sr2ptr->index() );
|
auto i1 = std::dynamic_pointer_cast<SRange::IndexType>( sr2ptr->index() );
|
||||||
auto i2 = std::dynamic_pointer_cast<SRange::IndexType>( sr4ptr->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);
|
||||||
|
|
||||||
EXPECT_EQ( fabs( res.at(mkt('1','A')) - (2.917 + 8.870) ) < 0.0001, true );
|
EXPECT_EQ( fabs( res.at(mkt('1','A')) - (2.917 * 8.870) ) < 0.0001, true );
|
||||||
EXPECT_EQ( fabs( res.at(mkt('1','B')) - (2.917 + 4.790) ) < 0.0001, true );
|
EXPECT_EQ( fabs( res.at(mkt('1','B')) - (2.917 * 4.790) ) < 0.0001, true );
|
||||||
|
|
||||||
EXPECT_EQ( fabs( res.at(mkt('2','A')) - (9.436 + 8.870) ) < 0.0001, true );
|
EXPECT_EQ( fabs( res.at(mkt('2','A')) - (9.436 * 8.870) ) < 0.0001, true );
|
||||||
EXPECT_EQ( fabs( res.at(mkt('2','B')) - (9.436 + 4.790) ) < 0.0001, true );
|
EXPECT_EQ( fabs( res.at(mkt('2','B')) - (9.436 * 4.790) ) < 0.0001, true );
|
||||||
|
|
||||||
EXPECT_EQ( fabs( res.at(mkt('3','A')) - (0.373 + 8.870) ) < 0.0001, true );
|
EXPECT_EQ( fabs( res.at(mkt('3','A')) - (0.373 * 8.870) ) < 0.0001, true );
|
||||||
EXPECT_EQ( fabs( res.at(mkt('3','B')) - (0.373 + 4.790) ) < 0.0001, true );
|
EXPECT_EQ( fabs( res.at(mkt('3','B')) - (0.373 * 4.790) ) < 0.0001, true );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,22 +143,22 @@ namespace {
|
||||||
auto i1 = std::dynamic_pointer_cast<MRange::IndexType>( mr1ptr->index() );
|
auto i1 = std::dynamic_pointer_cast<MRange::IndexType>( mr1ptr->index() );
|
||||||
auto i2 = std::dynamic_pointer_cast<SRange::IndexType>( sr4ptr->index() );
|
auto i2 = std::dynamic_pointer_cast<SRange::IndexType>( sr4ptr->index() );
|
||||||
|
|
||||||
res(i1,i2) = ma1(i1) + ma2(i2) + ma3(i2);
|
res(i1,i2) = ma1(i1) + ma2(i2) - ma3(i2);
|
||||||
|
|
||||||
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'),'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','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'),'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('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 + 1.470) ) < 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','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'),'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('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'),'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','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'),'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 );
|
EXPECT_EQ( fabs( res.at(mkt(mkt('3','b'),'B')) - (2.911 + 4.790 - 2.210) ) < 0.0001, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(OpTest_MDim, ExecOp3)
|
TEST_F(OpTest_MDim, ExecOp3)
|
||||||
|
|
Loading…
Reference in a new issue