fix 'step bug' (sub range)
This commit is contained in:
parent
9a4f6e7386
commit
90c0bee44c
3 changed files with 37 additions and 32 deletions
|
@ -317,9 +317,9 @@ namespace MultiArrayTools
|
||||||
-> For<SubIndex<Index>,SubExpr<Index,Expr>>
|
-> For<SubIndex<Index>,SubExpr<Index,Expr>>
|
||||||
{
|
{
|
||||||
return 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),
|
( mFullIndex, reinterpret_cast<std::intptr_t>(this),
|
||||||
&mExplicitRangePtr->subset(), step, ex ) );
|
&mExplicitRangePtr->subset(), ex ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************
|
/************************
|
||||||
|
|
|
@ -151,7 +151,6 @@ namespace MultiArrayHelper
|
||||||
ExtType mExt;
|
ExtType mExt;
|
||||||
|
|
||||||
const std::vector<size_t>* mSubSet;
|
const std::vector<size_t>* mSubSet;
|
||||||
size_t mStep;
|
|
||||||
|
|
||||||
mutable ExtType mRootSteps;
|
mutable ExtType mRootSteps;
|
||||||
|
|
||||||
|
@ -168,13 +167,10 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
SubExpr(const std::shared_ptr<IndexClass>& indPtr,
|
SubExpr(const std::shared_ptr<IndexClass>& indPtr,
|
||||||
std::intptr_t siptr,
|
std::intptr_t siptr,
|
||||||
const std::vector<size_t>* subset,
|
const std::vector<size_t>* subset, Expr expr);
|
||||||
size_t step, Expr expr);
|
|
||||||
|
|
||||||
SubExpr(const IndexClass* indPtr,
|
SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
|
||||||
std::intptr_t siptr,
|
const std::vector<size_t>* subset, Expr expr);
|
||||||
const std::vector<size_t>* subset,
|
|
||||||
size_t step, Expr expr);
|
|
||||||
|
|
||||||
|
|
||||||
inline void operator()(size_t mlast, DExt last) const override final;
|
inline void operator()(size_t mlast, DExt last) const override final;
|
||||||
|
@ -494,27 +490,22 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
SubExpr<IndexClass,Expr>::SubExpr(const std::shared_ptr<IndexClass>& indPtr,
|
SubExpr<IndexClass,Expr>::SubExpr(const std::shared_ptr<IndexClass>& indPtr,
|
||||||
std::intptr_t siptr,
|
std::intptr_t siptr,
|
||||||
const std::vector<size_t>* subset,
|
const std::vector<size_t>* subset, Expr expr) :
|
||||||
size_t step,
|
|
||||||
Expr expr) :
|
|
||||||
mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
|
mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
|
||||||
mExpr(expr),
|
mExpr(expr),
|
||||||
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
|
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
|
||||||
mSubSet(subset), mStep(step)
|
mSubSet(subset)
|
||||||
{
|
{
|
||||||
assert(mIndPtr != nullptr);
|
assert(mIndPtr != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr,
|
SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
|
||||||
std::intptr_t siptr,
|
const std::vector<size_t>* subset, Expr expr) :
|
||||||
const std::vector<size_t>* subset,
|
|
||||||
size_t step,
|
|
||||||
Expr expr) :
|
|
||||||
mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
|
mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
|
||||||
mExpr(expr),
|
mExpr(expr),
|
||||||
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
|
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
|
||||||
mSubSet(subset), mStep(step)
|
mSubSet(subset)
|
||||||
{
|
{
|
||||||
assert(mIndPtr != nullptr);
|
assert(mIndPtr != nullptr);
|
||||||
}
|
}
|
||||||
|
@ -529,9 +520,8 @@ namespace MultiArrayHelper
|
||||||
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast,
|
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast,
|
||||||
ExtType last) const
|
ExtType last) const
|
||||||
{
|
{
|
||||||
// INCLUDE FOR LOOP HERE AGIAN !!!!
|
|
||||||
const size_t pos = (*mSubSet)[last.val()];
|
const size_t pos = (*mSubSet)[last.val()];
|
||||||
const size_t mnpos = mlast * mStep;
|
const size_t mnpos = mlast;
|
||||||
const ExtType npos = last + mExt*pos;
|
const ExtType npos = last + mExt*pos;
|
||||||
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
|
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
|
||||||
}
|
}
|
||||||
|
@ -541,7 +531,7 @@ namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
const ExtType last;
|
const ExtType last;
|
||||||
const size_t pos = (*mSubSet)[last.val()];
|
const size_t pos = (*mSubSet)[last.val()];
|
||||||
const size_t mnpos = mlast * mStep;
|
const size_t mnpos = mlast;
|
||||||
const ExtType npos = last + mExt*pos;
|
const ExtType npos = last + mExt*pos;
|
||||||
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
|
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
|
||||||
}
|
}
|
||||||
|
|
|
@ -547,6 +547,7 @@ namespace {
|
||||||
auto subptr = MAT::createExplicit(subf);
|
auto subptr = MAT::createExplicit(subf);
|
||||||
|
|
||||||
MultiArray<double,SubRange<SRange>,SRange,SRange> res(subptr,sr3ptr,sr1ptr,0.);
|
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 i1 = MAT::getIndex( sr1ptr );
|
||||||
auto i2 = MAT::getIndex( sr2ptr );
|
auto i2 = MAT::getIndex( sr2ptr );
|
||||||
|
@ -555,6 +556,7 @@ namespace {
|
||||||
(*si)(i2);
|
(*si)(i2);
|
||||||
|
|
||||||
res(si,i3,i1) = ma2(i3,i2) - ma1(i1,i2,i3);
|
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.size(), 8 );
|
||||||
EXPECT_EQ( res.vdata().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','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'))) );
|
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( resx.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','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( resx.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','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( resx.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','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)
|
TEST_F(OpTest_MDim, ExecOp1)
|
||||||
|
|
Loading…
Reference in a new issue