crucial arithmetics extension: operations involving native c++ scalars should be possible

This commit is contained in:
Christian Zimmermann 2018-07-17 22:10:36 +02:00
parent 4499dfd7fc
commit e2dc8b3fea
2 changed files with 16 additions and 4 deletions

View file

@ -33,8 +33,8 @@ namespace MultiArrayTools
OperationClass& THIS() { return static_cast<OperationClass&>(*this); } OperationClass& THIS() { return static_cast<OperationClass&>(*this); }
const OperationClass& THIS() const { return static_cast<OperationClass const&>(*this); } const OperationClass& THIS() const { return static_cast<OperationClass const&>(*this); }
//inline auto operator+(const T& in) const inline auto operator+(const T& in) const
// -> Operation<T,plus<T>,OperationClass,OperationValue<T> >; -> Operation<T,plus<T>,OperationClass,OperationValue<T> >;
// !!! // !!!
@ -204,6 +204,7 @@ namespace MultiArrayTools
template <typename T> template <typename T>
class OperationValue : public OperationTemplate<T,OperationValue<T> > class OperationValue : public OperationTemplate<T,OperationValue<T> >
{ {
public:
typedef T value_type; typedef T value_type;
typedef OperationBase<T,OperationValue<T> > OT; typedef OperationBase<T,OperationValue<T> > OT;
typedef ContainerRange<T,NullRange> CRange; typedef ContainerRange<T,NullRange> CRange;
@ -353,14 +354,14 @@ namespace MultiArrayTools
* OperationTemplate * * OperationTemplate *
***************************/ ***************************/
/*
template <typename T, class OperationClass> template <typename T, class OperationClass>
auto OperationBase<T,OperationClass>::operator+(const T& in) const auto OperationBase<T,OperationClass>::operator+(const T& in) const
-> Operation<T,plus<T>,OperationClass,OperationValue<T> > -> Operation<T,plus<T>,OperationClass,OperationValue<T> >
{ {
return Operation<T,plus<T>,OperationClass,OperationValue<T> >(THIS(), in); return Operation<T,plus<T>,OperationClass,OperationValue<T> >(THIS(), in);
} }
*/
template <typename T, class OperationClass> template <typename T, class OperationClass>
template <class Second> template <class Second>

View file

@ -434,6 +434,7 @@ namespace {
TEST_F(OpTest_MDim, ExecOp1) TEST_F(OpTest_MDim, ExecOp1)
{ {
MultiArray<double,SRange,SRange> res(sr2ptr,sr4ptr); MultiArray<double,SRange,SRange> res(sr2ptr,sr4ptr);
MultiArray<double,SRange,SRange> res2(sr2ptr,sr4ptr);
const MultiArray<double,SRange> ma1(sr2ptr, v1); const MultiArray<double,SRange> ma1(sr2ptr, v1);
const MultiArray<double,SRange> ma2(sr4ptr, v2); const MultiArray<double,SRange> ma2(sr4ptr, v2);
@ -451,6 +452,16 @@ namespace {
EXPECT_EQ( xround( res.at(mkt('3','A')) ), xround(0.373 * 8.870) ); EXPECT_EQ( xround( res.at(mkt('3','A')) ), xround(0.373 * 8.870) );
EXPECT_EQ( xround( res.at(mkt('3','B')) ), xround(0.373 * 4.790) ); EXPECT_EQ( xround( res.at(mkt('3','B')) ), xround(0.373 * 4.790) );
res2(i1,i2) = (ma1(i1) + 3.14 ) * ma2(i2);
EXPECT_EQ( xround( res2.at(mkt('1','A')) ), xround( (2.917 + 3.14) * 8.870) );
EXPECT_EQ( xround( res2.at(mkt('1','B')) ), xround( (2.917 + 3.14) * 4.790) );
EXPECT_EQ( xround( res2.at(mkt('2','A')) ), xround( (9.436 + 3.14) * 8.870) );
EXPECT_EQ( xround( res2.at(mkt('2','B')) ), xround( (9.436 + 3.14) * 4.790) );
EXPECT_EQ( xround( res2.at(mkt('3','A')) ), xround( (0.373 + 3.14) * 8.870) );
EXPECT_EQ( xround( res2.at(mkt('3','B')) ), xround( (0.373 + 3.14) * 4.790) );
} }
TEST_F(OpTest_MDim, ExecContract) TEST_F(OpTest_MDim, ExecContract)