fix slice step size issue

This commit is contained in:
Christian Zimmermann 2018-09-16 18:53:28 +02:00
parent 9229ead298
commit 67492e24b7
6 changed files with 35 additions and 11 deletions

View file

@ -591,6 +591,7 @@ namespace MultiArrayTools
inline void OperationMaster<T,OpClass,Ranges...>::AssignmentExpr:: inline void OperationMaster<T,OpClass,Ranges...>::AssignmentExpr::
operator()(size_t start, ExtType last) const operator()(size_t start, ExtType last) const
{ {
//VCHECK(mSec.template get<ExtType>(last));
mM.add(start, mSec.template get<ExtType>(last) ); mM.add(start, mSec.template get<ExtType>(last) );
} }

View file

@ -66,6 +66,9 @@ namespace MultiArrayTools
template <size_t N> template <size_t N>
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&; auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
template <size_t N>
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
const IndexPack& pack() const { return mIPack; } const IndexPack& pack() const { return mIPack; }
ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true

View file

@ -76,6 +76,9 @@ namespace MultiArrayTools
template <size_t N> template <size_t N>
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&; auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
template <size_t N>
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
// raplace instances (in contrast to its analogon in ContainerIndex // raplace instances (in contrast to its analogon in ContainerIndex
// MultiIndices CANNOT be influences be its subindices, so there is // MultiIndices CANNOT be influences be its subindices, so there is
// NO foreign/external controll) // NO foreign/external controll)

View file

@ -276,7 +276,8 @@ namespace MultiArrayHelper
const auto& ni = ii.template get<N>(); const auto& ni = ii.template get<N>();
const size_t max = ni.max(); const size_t max = ni.max();
const size_t tmp = getStepSize(ni, j); const size_t tmp = getStepSize(ni, j);
ss += tmp * sx; //ss += tmp * sx;
ss += tmp * ii.template getBlockSize<N+1>();
sx *= max; sx *= max;
RPackNum<N-1>::getStepSizeX(ii, j, ss, sx); RPackNum<N-1>::getStepSizeX(ii, j, ss, sx);
} }
@ -507,7 +508,8 @@ namespace MultiArrayHelper
const auto& ni = ii.template get<0>(); const auto& ni = ii.template get<0>();
const size_t max = ni.max(); const size_t max = ni.max();
const size_t tmp = getStepSize(ni, j); const size_t tmp = getStepSize(ni, j);
ss += tmp * sx; //ss += tmp * sx;
ss += tmp * ii.template getBlockSize<1>();
sx *= max; sx *= max;
} }

View file

@ -16,6 +16,8 @@ namespace MultiArrayTools
typedef MultiArrayBase<T,SRanges...> MAB; typedef MultiArrayBase<T,SRanges...> MAB;
typedef ContainerIndex<T,typename SRanges::IndexType...> IType; typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
using MultiArrayBase<T,SRanges...>::operator();
DEFAULT_MEMBERS(ConstSlice); DEFAULT_MEMBERS(ConstSlice);
ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr); ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr);
@ -54,6 +56,9 @@ namespace MultiArrayTools
typedef MultiArrayBase<T,SRanges...> MAB; typedef MultiArrayBase<T,SRanges...> MAB;
typedef ContainerIndex<T,typename SRanges::IndexType...> IType; typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
using MultiArrayBase<T,SRanges...>::operator();
using MutableMultiArrayBase<T,SRanges...>::operator();
DEFAULT_MEMBERS(Slice); DEFAULT_MEMBERS(Slice);
Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr); Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr);

View file

@ -469,7 +469,7 @@ namespace {
<< std::endl; << std::endl;
std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl; std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl;
} }
/*
TEST_F(OpTest_Performance, PCheck) TEST_F(OpTest_Performance, PCheck)
{ {
MultiArray<double,MRange> ma2(mrptr, cv2); MultiArray<double,MRange> ma2(mrptr, cv2);
@ -508,7 +508,7 @@ namespace {
//EXPECT_EQ( xround( res.at(mkt(700,900)) ), xround(res2[700*vs1 + 900]) ); //EXPECT_EQ( xround( res.at(mkt(700,900)) ), xround(res2[700*vs1 + 900]) );
} }
*/
TEST_F(OpTest_1Dim, ExecOp) TEST_F(OpTest_1Dim, ExecOp)
{ {
MultiArray<double,SRange> ma1(srptr, v1); MultiArray<double,SRange> ma1(srptr, v1);
@ -675,10 +675,10 @@ namespace {
MultiArray<double,SRange> ma5(sr1ptr, v3); MultiArray<double,SRange> ma5(sr1ptr, v3);
MultiArray<double,SRange> ma6(sr3ptr, v2); MultiArray<double,SRange> ma6(sr3ptr, v2);
auto si0 = MAT::getIndex( sr1ptr ); auto si0 = MAT::getIndex( sr1ptr ); // 'x'
auto si1 = MAT::getIndex( sr2ptr ); auto si1 = MAT::getIndex( sr2ptr ); // '1'
auto si2 = MAT::getIndex( sr3ptr ); auto si2 = MAT::getIndex( sr3ptr ); // 'a'
auto si3 = MAT::getIndex( sr4ptr ); auto si3 = MAT::getIndex( sr4ptr ); // 'A'
auto mi = MAT::getIndex( mr1ptr ); auto mi = MAT::getIndex( mr1ptr );
mi->operator()(si1,si2); mi->operator()(si1,si2);
@ -704,9 +704,19 @@ namespace {
ma7(si1,si3) = ma4(si0,si1,si2,si3).slc(si0,si2); ma7(si1,si3) = ma4(si0,si1,si2,si3).slc(si0,si2);
si1->at('1'); si1->at('1');
si3->at('A'); si0->at('x');
Slice<double,SRange,SRange> sl(sr1ptr,sr3ptr); (*si2) = 0;
sl.define(si2,si3) = ma4(si0,si1,si2,si3); (*si3) = 0;
Slice<double,SRange,SRange> sl(sr4ptr,sr3ptr);
sl.define(si3,si2) = ma4(si0,si1,si2,si3);
MultiArrayBase<double,SRange,SRange>& slb = sl;
MultiArray<double,SRange,SRange> ma8(sr3ptr,sr4ptr);
//ma8(si2,si3) = ma4(si0,si1,si2,si3);
ma8(si2,si3) = slb(si3,si2);
EXPECT_EQ( xround( ma8.at(mkt('a','A')) ), xround( sl.at(mkt('A','a')) ) );
EXPECT_EQ( xround( ma8.at(mkt('b','A')) ), xround( sl.at(mkt('A','b')) ) );
EXPECT_EQ( xround( ma7.at(mkt('1','A')).at(mkt('x','a')) ), EXPECT_EQ( xround( ma7.at(mkt('1','A')).at(mkt('x','a')) ),
xround( ma4.at(mkt('x','1','a','A')) ) ); xround( ma4.at(mkt('x','1','a','A')) ) );