dynamic re-ordering assignment

This commit is contained in:
Christian Zimmermann 2018-12-02 18:46:44 +01:00
parent 6671c784f3
commit 7331ff608f
2 changed files with 54 additions and 17 deletions

View file

@ -35,6 +35,12 @@ namespace MultiArrayTools
template <class EC, template <class> class OpF, class... MAs> template <class EC, template <class> class OpF, class... MAs>
using AEX = AEXT<EC,OX<EC,OpF,MAs...>>; using AEX = AEXT<EC,OX<EC,OpF,MAs...>>;
template <class EC>
using AEX_M = AEXT<EC,oo<EC,DDMMA<EC>>>;
template <class EC>
using AEX_C = AEXT<EC,oo<EC,DDMA<EC>>>;
template <class EC, template <class> class OpF> template <class EC, template <class> class OpF>
using AEX_B_MM = AEX<EC,OpF,DDMMA<EC>,DDMMA<EC>>; using AEX_B_MM = AEX<EC,OpF,DDMMA<EC>,DDMMA<EC>>;
@ -86,6 +92,9 @@ namespace MultiArrayTools
V_IFOR_X(AEX_B_CM<EC XCOMMAX() OpF>); \ V_IFOR_X(AEX_B_CM<EC XCOMMAX() OpF>); \
V_IFOR_X(AEX_B_CC<EC XCOMMAX() OpF>) V_IFOR_X(AEX_B_CC<EC XCOMMAX() OpF>)
#define V_IFOR_A_1(EC) \
V_IFOR_X(AEX_M<EC>); \
V_IFOR_X(AEX_C<EC>)
template <class Index> template <class Index>
class E1; class E1;
@ -107,6 +116,7 @@ namespace MultiArrayTools
V_IFOR_A(EX,MultiArrayTools::minus); V_IFOR_A(EX,MultiArrayTools::minus);
V_IFOR_A(EX,MultiArrayTools::multiplies); V_IFOR_A(EX,MultiArrayTools::multiplies);
V_IFOR_A(EX,MultiArrayTools::divides); V_IFOR_A(EX,MultiArrayTools::divides);
V_IFOR_A_1(EX);
public: public:
template <class Expr> template <class Expr>
@ -140,6 +150,10 @@ namespace MultiArrayTools
D_IFOR_X(AEX_B_CM<EC XCOMMAX() OpF>,Ind); \ D_IFOR_X(AEX_B_CM<EC XCOMMAX() OpF>,Ind); \
D_IFOR_X(AEX_B_CC<EC XCOMMAX() OpF>,Ind) D_IFOR_X(AEX_B_CC<EC XCOMMAX() OpF>,Ind)
#define D_IFOR_A_1(EC,Ind) \
D_IFOR_X(AEX_M<EC>,Ind); \
D_IFOR_X(AEX_C<EC>,Ind)
template <class Index> template <class Index>
class E1 : public Expressions1 class E1 : public Expressions1
{ {
@ -155,6 +169,7 @@ namespace MultiArrayTools
D_IFOR_A(EX,MultiArrayTools::minus,mI); D_IFOR_A(EX,MultiArrayTools::minus,mI);
D_IFOR_A(EX,MultiArrayTools::multiplies,mI); D_IFOR_A(EX,MultiArrayTools::multiplies,mI);
D_IFOR_A(EX,MultiArrayTools::divides,mI); D_IFOR_A(EX,MultiArrayTools::divides,mI);
D_IFOR_A_1(EX,mI);
public: public:
E1(const E1& in) = default; E1(const E1& in) = default;

View file

@ -654,10 +654,12 @@ namespace {
MultiArray<double,MRange,SRange> ma1(mr1ptr,sr4ptr,v5); MultiArray<double,MRange,SRange> ma1(mr1ptr,sr4ptr,v5);
MultiArray<double,SRange> ma2(sr2ptr,v1); MultiArray<double,SRange> ma2(sr2ptr,v1);
MultiArray<double,SRange,MRange> res(sr4ptr,mr1ptr); MultiArray<double,SRange,MRange> res(sr4ptr,mr1ptr);
MultiArray<double,MRange,SRange> res2(mr1ptr,sr4ptr);
DMA dma1 = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( ma1 ) ); DMA dma1 = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( ma1 ) );
DMA dma2 = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( ma2 ) ); DMA dma2 = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( ma2 ) );
DMA dres = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( res ) ); DMA dres = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( res ) );
DMA dres2 = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( res2 ) );
auto si2 = MAT::getIndex( sr2ptr ); auto si2 = MAT::getIndex( sr2ptr );
auto si3 = MAT::getIndex( sr3ptr ); auto si3 = MAT::getIndex( sr3ptr );
@ -668,28 +670,48 @@ namespace {
auto di1 = MAT::getIndex( MAT::rptr<0>( dma1 ) ); auto di1 = MAT::getIndex( MAT::rptr<0>( dma1 ) );
auto di2 = MAT::getIndex( MAT::rptr<0>( dma2 ) ); auto di2 = MAT::getIndex( MAT::rptr<0>( dma2 ) );
auto dir = MAT::getIndex( MAT::rptr<0>( dres ) ); auto dir = MAT::getIndex( MAT::rptr<0>( dres ) );
//auto dirx = MAT::getIndex( MAT::rptr<0>( dres ) );
auto dir2 = MAT::getIndex( MAT::rptr<0>( dres2 ) );
(*di1)(mi,si4); (*di1)(mi,si4);
(*di2)(si2); (*di2)(si2);
(*dir)(si4,mi); (*dir)(si4,mi);
(*dir2)(mi,si4);
dres(dir) = dma1(di1) + dma2(di2); dres(dir) = dma1(di1) + dma2(di2);
res = dres.format(sr4ptr,mr1ptr);
MultiArray<double,SRange,MRange> res2(sr4ptr,mr1ptr,dres.vdata()); EXPECT_EQ( xround( res.at( mkt('A',mkt('1','a')) ) ), xround( 30.932 + 2.917 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('1','b')) ) ), xround( -26.205 + 2.917 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('2','a')) ) ), xround( 21.227 + 9.436 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('2','b')) ) ), xround( -14.364 + 9.436 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('3','a')) ) ), xround( -25.703 + 0.373 ) );
EXPECT_EQ( xround( res.at( mkt('A',mkt('3','b')) ) ), xround( 23.563 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('1','a')) ) ), xround( 30.932 + 2.917 ) ); EXPECT_EQ( xround( res.at( mkt('B',mkt('1','a')) ) ), xround( -33.693 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('1','b')) ) ), xround( -26.205 + 2.917 ) ); EXPECT_EQ( xround( res.at( mkt('B',mkt('1','b')) ) ), xround( -15.504 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('2','a')) ) ), xround( 21.227 + 9.436 ) ); EXPECT_EQ( xround( res.at( mkt('B',mkt('2','a')) ) ), xround( 17.829 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('2','b')) ) ), xround( -14.364 + 9.436 ) ); EXPECT_EQ( xround( res.at( mkt('B',mkt('2','b')) ) ), xround( -1.868 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('3','a')) ) ), xround( -25.703 + 0.373 ) ); EXPECT_EQ( xround( res.at( mkt('B',mkt('3','a')) ) ), xround( 13.836 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt('A',mkt('3','b')) ) ), xround( 23.563 + 0.373 ) ); EXPECT_EQ( xround( res.at( mkt('B',mkt('3','b')) ) ), xround( 41.339 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('1','a')) ) ), xround( -33.693 + 2.917 ) ); //dres = *std::dynamic_pointer_cast<DMA>( dynamic<EC1>( res ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('1','b')) ) ), xround( -15.504 + 2.917 ) ); dres2(dir2) = dres(dir);
EXPECT_EQ( xround( res2.at( mkt('B',mkt('2','a')) ) ), xround( 17.829 + 9.436 ) ); res2 = dres2.format(mr1ptr,sr4ptr);
EXPECT_EQ( xround( res2.at( mkt('B',mkt('2','b')) ) ), xround( -1.868 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('3','a')) ) ), xround( 13.836 + 0.373 ) ); EXPECT_EQ( xround( res2.at( mkt(mkt('1','a'),'A') ) ), xround( 30.932 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt('B',mkt('3','b')) ) ), xround( 41.339 + 0.373 ) ); EXPECT_EQ( xround( res2.at( mkt(mkt('1','b'),'A') ) ), xround( -26.205 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('2','a'),'A') ) ), xround( 21.227 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('2','b'),'A') ) ), xround( -14.364 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('3','a'),'A') ) ), xround( -25.703 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('3','b'),'A') ) ), xround( 23.563 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('1','a'),'B') ) ), xround( -33.693 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('1','b'),'B') ) ), xround( -15.504 + 2.917 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('2','a'),'B') ) ), xround( 17.829 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('2','b'),'B') ) ), xround( -1.868 + 9.436 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('3','a'),'B') ) ), xround( 13.836 + 0.373 ) );
EXPECT_EQ( xround( res2.at( mkt(mkt('3','b'),'B') ) ), xround( 41.339 + 0.373 ) );
} }