From 90c0bee44c3fab1499f17bb9233fb39348c632c6 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 21 Dec 2018 23:41:14 +0100 Subject: [PATCH] fix 'step bug' (sub range) --- src/include/ranges/subrange.h | 4 ++-- src/include/xfor/xfor.h | 30 ++++++++++-------------------- src/tests/op_unit_test.cc | 35 +++++++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/include/ranges/subrange.h b/src/include/ranges/subrange.h index 5a850dc..b9b1885 100644 --- a/src/include/ranges/subrange.h +++ b/src/include/ranges/subrange.h @@ -317,9 +317,9 @@ namespace MultiArrayTools -> For,SubExpr> { return For,SubExpr> - (this, 1, SubExpr + (this, step, SubExpr ( mFullIndex, reinterpret_cast(this), - &mExplicitRangePtr->subset(), step, ex ) ); + &mExplicitRangePtr->subset(), ex ) ); } /************************ diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index b9d6fe0..727a263 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -151,7 +151,6 @@ namespace MultiArrayHelper ExtType mExt; const std::vector* mSubSet; - size_t mStep; mutable ExtType mRootSteps; @@ -168,13 +167,10 @@ namespace MultiArrayHelper SubExpr(const std::shared_ptr& indPtr, std::intptr_t siptr, - const std::vector* subset, - size_t step, Expr expr); + const std::vector* subset, Expr expr); - SubExpr(const IndexClass* indPtr, - std::intptr_t siptr, - const std::vector* subset, - size_t step, Expr expr); + SubExpr(const IndexClass* indPtr, std::intptr_t siptr, + const std::vector* subset, Expr expr); inline void operator()(size_t mlast, DExt last) const override final; @@ -494,27 +490,22 @@ namespace MultiArrayHelper template SubExpr::SubExpr(const std::shared_ptr& indPtr, std::intptr_t siptr, - const std::vector* subset, - size_t step, - Expr expr) : + const std::vector* subset, Expr expr) : mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr), mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast( mIndPtr )) ) ), - mSubSet(subset), mStep(step) + mSubSet(subset) { assert(mIndPtr != nullptr); } template - SubExpr::SubExpr(const IndexClass* indPtr, - std::intptr_t siptr, - const std::vector* subset, - size_t step, - Expr expr) : + SubExpr::SubExpr(const IndexClass* indPtr, std::intptr_t siptr, + const std::vector* subset, Expr expr) : mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr), mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast( mIndPtr )) ) ), - mSubSet(subset), mStep(step) + mSubSet(subset) { assert(mIndPtr != nullptr); } @@ -529,9 +520,8 @@ namespace MultiArrayHelper inline void SubExpr::operator()(size_t mlast, ExtType last) const { - // INCLUDE FOR LOOP HERE AGIAN !!!! const size_t pos = (*mSubSet)[last.val()]; - const size_t mnpos = mlast * mStep; + const size_t mnpos = mlast; const ExtType npos = last + mExt*pos; mExpr(mnpos, Getter<1>::template getX( npos )); } @@ -541,7 +531,7 @@ namespace MultiArrayHelper { const ExtType last; const size_t pos = (*mSubSet)[last.val()]; - const size_t mnpos = mlast * mStep; + const size_t mnpos = mlast; const ExtType npos = last + mExt*pos; mExpr(mnpos, Getter<1>::template getX( npos )); } diff --git a/src/tests/op_unit_test.cc b/src/tests/op_unit_test.cc index a2b002d..ec59a34 100644 --- a/src/tests/op_unit_test.cc +++ b/src/tests/op_unit_test.cc @@ -547,6 +547,7 @@ namespace { auto subptr = MAT::createExplicit(subf); MultiArray,SRange,SRange> res(subptr,sr3ptr,sr1ptr,0.); + MultiArray,SRange> res2(sr3ptr,subptr,sr1ptr,0.); auto i1 = MAT::getIndex( sr1ptr ); auto i2 = MAT::getIndex( sr2ptr ); @@ -555,6 +556,7 @@ namespace { (*si)(i2); res(si,i3,i1) = ma2(i3,i2) - ma1(i1,i2,i3); + res2(i3,si,i1) = ma2(i3,i2) - ma1(i1,i2,i3); EXPECT_EQ( res.size(), 8 ); EXPECT_EQ( res.vdata().size(), 8 ); @@ -575,20 +577,33 @@ namespace { EXPECT_EQ( xround( res.at(mkt('3','b','x')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('x','3','b'))) ); EXPECT_EQ( xround( res.at(mkt('3','b','l')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('l','3','b'))) ); - auto res2 = res.format( subptr->outRange(), sr3ptr, sr1ptr ); + auto resx = res.format( subptr->outRange(), sr3ptr, sr1ptr ); - EXPECT_EQ( xround( res2.at(mkt('1','a','x')) ), xround(ma2.at(mkt('a','1')) - ma1.at(mkt('x','1','a'))) ); - EXPECT_EQ( xround( res2.at(mkt('1','a','l')) ), xround(ma2.at(mkt('a','1')) - ma1.at(mkt('l','1','a'))) ); + EXPECT_EQ( xround( resx.at(mkt('1','a','x')) ), xround(ma2.at(mkt('a','1')) - ma1.at(mkt('x','1','a'))) ); + EXPECT_EQ( xround( resx.at(mkt('1','a','l')) ), xround(ma2.at(mkt('a','1')) - ma1.at(mkt('l','1','a'))) ); - EXPECT_EQ( xround( res2.at(mkt('1','b','x')) ), xround(ma2.at(mkt('b','1')) - ma1.at(mkt('x','1','b'))) ); - EXPECT_EQ( xround( res2.at(mkt('1','b','l')) ), xround(ma2.at(mkt('b','1')) - ma1.at(mkt('l','1','b'))) ); + EXPECT_EQ( xround( resx.at(mkt('1','b','x')) ), xround(ma2.at(mkt('b','1')) - ma1.at(mkt('x','1','b'))) ); + EXPECT_EQ( xround( resx.at(mkt('1','b','l')) ), xround(ma2.at(mkt('b','1')) - ma1.at(mkt('l','1','b'))) ); - EXPECT_EQ( xround( res2.at(mkt('3','a','x')) ), xround(ma2.at(mkt('a','3')) - ma1.at(mkt('x','3','a'))) ); - EXPECT_EQ( xround( res2.at(mkt('3','a','l')) ), xround(ma2.at(mkt('a','3')) - ma1.at(mkt('l','3','a'))) ); + EXPECT_EQ( xround( resx.at(mkt('3','a','x')) ), xround(ma2.at(mkt('a','3')) - ma1.at(mkt('x','3','a'))) ); + EXPECT_EQ( xround( resx.at(mkt('3','a','l')) ), xround(ma2.at(mkt('a','3')) - ma1.at(mkt('l','3','a'))) ); + + EXPECT_EQ( xround( resx.at(mkt('3','b','x')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('x','3','b'))) ); + EXPECT_EQ( xround( resx.at(mkt('3','b','l')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('l','3','b'))) ); + + + EXPECT_EQ( xround( res2.at(mkt('a','1','x')) ), xround(ma2.at(mkt('a','1')) - ma1.at(mkt('x','1','a'))) ); + EXPECT_EQ( xround( res2.at(mkt('a','1','l')) ), xround(ma2.at(mkt('a','1')) - ma1.at(mkt('l','1','a'))) ); + + EXPECT_EQ( xround( res2.at(mkt('b','1','x')) ), xround(ma2.at(mkt('b','1')) - ma1.at(mkt('x','1','b'))) ); + EXPECT_EQ( xround( res2.at(mkt('b','1','l')) ), xround(ma2.at(mkt('b','1')) - ma1.at(mkt('l','1','b'))) ); + + EXPECT_EQ( xround( res2.at(mkt('a','3','x')) ), xround(ma2.at(mkt('a','3')) - ma1.at(mkt('x','3','a'))) ); + EXPECT_EQ( xround( res2.at(mkt('a','3','l')) ), xround(ma2.at(mkt('a','3')) - ma1.at(mkt('l','3','a'))) ); + + EXPECT_EQ( xround( res2.at(mkt('b','3','x')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('x','3','b'))) ); + EXPECT_EQ( xround( res2.at(mkt('b','3','l')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('l','3','b'))) ); - EXPECT_EQ( xround( res2.at(mkt('3','b','x')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('x','3','b'))) ); - EXPECT_EQ( xround( res2.at(mkt('3','b','l')) ), xround(ma2.at(mkt('b','3')) - ma1.at(mkt('l','3','b'))) ); - } TEST_F(OpTest_MDim, ExecOp1)