fix 'step bug' (sub range)

This commit is contained in:
Christian Zimmermann 2018-12-21 23:41:14 +01:00
parent 9a4f6e7386
commit 90c0bee44c
3 changed files with 37 additions and 32 deletions

View file

@ -317,9 +317,9 @@ namespace MultiArrayTools
-> For<SubIndex<Index>,SubExpr<Index,Expr>>
{
return For<SubIndex<Index>,SubExpr<Index,Expr>>
(this, 1, SubExpr<Index,Expr>
(this, step, SubExpr<Index,Expr>
( mFullIndex, reinterpret_cast<std::intptr_t>(this),
&mExplicitRangePtr->subset(), step, ex ) );
&mExplicitRangePtr->subset(), ex ) );
}
/************************

View file

@ -151,7 +151,6 @@ namespace MultiArrayHelper
ExtType mExt;
const std::vector<size_t>* mSubSet;
size_t mStep;
mutable ExtType mRootSteps;
@ -168,13 +167,10 @@ namespace MultiArrayHelper
SubExpr(const std::shared_ptr<IndexClass>& indPtr,
std::intptr_t siptr,
const std::vector<size_t>* subset,
size_t step, Expr expr);
const std::vector<size_t>* subset, Expr expr);
SubExpr(const IndexClass* indPtr,
std::intptr_t siptr,
const std::vector<size_t>* subset,
size_t step, Expr expr);
SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
const std::vector<size_t>* subset, Expr expr);
inline void operator()(size_t mlast, DExt last) const override final;
@ -494,27 +490,22 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const std::shared_ptr<IndexClass>& indPtr,
std::intptr_t siptr,
const std::vector<size_t>* subset,
size_t step,
Expr expr) :
const std::vector<size_t>* subset, Expr expr) :
mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
mSubSet(subset), mStep(step)
mSubSet(subset)
{
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr,
std::intptr_t siptr,
const std::vector<size_t>* subset,
size_t step,
Expr expr) :
SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
const std::vector<size_t>* subset, Expr expr) :
mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
mSubSet(subset), mStep(step)
mSubSet(subset)
{
assert(mIndPtr != nullptr);
}
@ -529,9 +520,8 @@ namespace MultiArrayHelper
inline void SubExpr<IndexClass,Expr>::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<ExtType>( 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<ExtType>( npos ));
}

View file

@ -547,6 +547,7 @@ namespace {
auto subptr = MAT::createExplicit(subf);
MultiArray<double,SubRange<SRange>,SRange,SRange> res(subptr,sr3ptr,sr1ptr,0.);
MultiArray<double,SRange,SubRange<SRange>,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)