prelim fix... (CAUTION)

This commit is contained in:
Christian Zimmermann 2018-12-25 17:48:52 +01:00
parent edae293f14
commit 22b93b0612
5 changed files with 89 additions and 21 deletions

View file

@ -85,7 +85,7 @@ namespace MultiArrayTools
template <typename T, class... SRanges>
typename MultiArrayBase<T,SRanges...>::IndexType MultiArrayBase<T,SRanges...>::begin() const
{
IndexType i(*mProtoI);
IndexType i(*mProtoI,true);
i = 0;
return i.setData(data());
}
@ -93,7 +93,7 @@ namespace MultiArrayTools
template <typename T, class... SRanges>
typename MultiArrayBase<T,SRanges...>::IndexType MultiArrayBase<T,SRanges...>::end() const
{
IndexType i(*mProtoI);
IndexType i(*mProtoI,true);
i = i.max();
//i = mRange->size();
return i.setData(data());
@ -103,7 +103,7 @@ namespace MultiArrayTools
typename MultiArrayBase<T,SRanges...>::IndexType
MultiArrayBase<T,SRanges...>::beginIndex() const
{
IndexType i(*mProtoI);
IndexType i(*mProtoI,true);
i = 0;
return i.setData(data());
}
@ -112,7 +112,7 @@ namespace MultiArrayTools
typename MultiArrayBase<T,SRanges...>::IndexType
MultiArrayBase<T,SRanges...>::endIndex() const
{
IndexType i(*mProtoI);
IndexType i(*mProtoI,true);
i = i.max();
//i = mRange->size();
return i.setData(data());

View file

@ -49,14 +49,45 @@ namespace MultiArrayTools
IndexPack mIPack;
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
const T* mData = nullptr;
size_t mCPos;
//const MultiArrayBase<T,typename Indices::RangeType...>* mMa = nullptr;
std::intptr_t mObjPtrNum;
public:
ContainerIndex(const ContainerIndex& in) = default;
ContainerIndex(const ContainerIndex& in) = default;
ContainerIndex& operator=(const ContainerIndex& in) = default;
ContainerIndex(const ContainerIndex& in, bool copy) :
IB(in),
mNonTrivialBlocks(in.mNonTrivialBlocks),
mExternControl(false),
mBlockSizes(in.mBlockSizes),
mData(in.mData),
mCPos(in.mCPos),
mObjPtrNum(in.mObjPtrNum)
{
//if(copy){
RPackNum<sizeof...(Indices)-1>::copyIndex(mIPack, in);
//}
//else {
//mIPack = in.mIPack;
//}
}
ContainerIndex& copy(const ContainerIndex& in)
{
IB::operator=(in);
mNonTrivialBlocks = in.mNonTrivialBlocks;
mExternControl = false;
mBlockSizes = in.mBlockSizes;
mData = in.mData;
mCPos = in.mCPos;
mObjPtrNum = in.mObjPtrNum;
RPackNum<sizeof...(Indices)-1>::copyIndex(mIPack, in);
return *this;
}
template <typename X>
ContainerIndex& operator=(const ContainerIndex<X,Indices...>& in);
@ -245,7 +276,8 @@ namespace MultiArrayTools
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
}
template <typename T, class... Indices>
@ -258,7 +290,8 @@ namespace MultiArrayTools
{
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
mBlockSizes = blockSizes;
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
mNonTrivialBlocks = true;
}
@ -277,6 +310,7 @@ namespace MultiArrayTools
{
if(mExternControl){
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
//VCHECK(id());
//VCHECK(sizeof...(Indices));
//assert(IB::mPos < IB::max());
@ -330,6 +364,7 @@ namespace MultiArrayTools
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
}
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
++IB::mPos;
return *this;
}
@ -341,6 +376,7 @@ namespace MultiArrayTools
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
}
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
--IB::mPos;
return *this;
@ -351,6 +387,7 @@ namespace MultiArrayTools
{
IB::mPos = pos;
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
return *this;
}
@ -499,14 +536,15 @@ namespace MultiArrayTools
const T& ContainerIndex<T,Indices...>::operator*() const
{
//return mMa[*this];
return mData[IB::mPos];
return mData[mCPos];
//return mData[IB::mPos];
}
template <typename T, class... Indices>
const T* ContainerIndex<T,Indices...>::operator->() const
{
//return &mMa[*this];
return &mData[IB::mPos];
return &mData[mCPos];
}
/*
template <typename T, class... Indices>

View file

@ -189,9 +189,10 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(*std::get<N>(ip).get())>::type TypeFromIndexPack;
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
"inconsiśtent types");
"inconsistent types");
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<N>() ) );
*std::get<N>(ip) = 0;
RPackNum<N-1>::construct(ip, range);
}
@ -202,7 +203,16 @@ namespace MultiArrayHelper
std::get<N>(ip) = ind.template getPtr<N>() ;
RPackNum<N-1>::copyInst(ip, ind);
}
template <class IndexType, class... Indices>
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind)
{
typedef typename std::remove_reference<decltype(*std::get<N>(ip))>::type SubType;
std::get<N>(ip) = std::make_shared<SubType>( ind.template get<N>() ) ;
RPackNum<N-1>::copyIndex(ip, ind);
}
template <class... Indices>
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
{
@ -454,9 +464,10 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(*std::get<0>(ip).get())>::type TypeFromIndexPack;
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
"inconsiśtent types");
"inconsistent types");
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<0>() ) );
*std::get<0>(ip) = 0;
}
template <class IndexType, class... Indices>
@ -465,7 +476,15 @@ namespace MultiArrayHelper
{
std::get<0>(ip) = ind.template getPtr<0>();
}
template <class IndexType, class... Indices>
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind)
{
typedef typename std::remove_reference<decltype(*std::get<0>(ip))>::type SubType;
std::get<0>(ip) = std::make_shared<SubType>( ind.template get<0>() ) ;
}
template <class... Indices>
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
{

View file

@ -67,11 +67,11 @@ namespace MultiArrayTools
{
return true;
}
template <typename T, class... SRanges>
auto ConstSlice<T,SRanges...>::begin() const -> ConstSlice<T,SRanges...>::IType
{
IType i(*MAB::mProtoI);
IType i(*MAB::mProtoI,true);
i = 0;
//i = mStartPos;
return i.setData(data());
@ -80,12 +80,12 @@ namespace MultiArrayTools
template <typename T, class... SRanges>
auto ConstSlice<T,SRanges...>::end() const -> ConstSlice<T,SRanges...>::IType
{
IType i(*MAB::mProtoI);
IType i(*MAB::mProtoI,true);
i = i.max(); // CHECK !!!
//i = std::get<sizeof...(SRanges)>(mBlockSizes);
return i.setData(data());
}
template <typename T, class... SRanges>
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > ConstSlice<T,SRanges...>::anonymous(bool slice) const
{
@ -169,7 +169,7 @@ namespace MultiArrayTools
template <typename T, class... SRanges>
auto Slice<T,SRanges...>::begin() const -> Slice<T,SRanges...>::IType
{
IType i(*MAB::mProtoI);
IType i(*MAB::mProtoI,true);
i = 0;
//i = mStartPos;
return i.setData(data());
@ -178,7 +178,7 @@ namespace MultiArrayTools
template <typename T, class... SRanges>
auto Slice<T,SRanges...>::end() const -> Slice<T,SRanges...>::IType
{
IType i(*MAB::mProtoI);
IType i(*MAB::mProtoI,true);
i = i.max(); // CHECK !!!
//i = std::get<sizeof...(SRanges)>(mBlockSizes);
return i.setData(data());

View file

@ -221,39 +221,50 @@ namespace {
j->at('1');
sl3.define(j, j1, j2) = ma(mj, j);
auto ci = sl3.begin();
EXPECT_EQ( sl3.at( mkt('1', 'x','a') ), 2.917 );
EXPECT_EQ( *ci, 2.917 );
EXPECT_EQ( sl3.at( mkt('2', 'x','a') ), 9.436 );
EXPECT_EQ( sl3.at( mkt('3', 'x','a') ), 0.373 );
EXPECT_EQ( sl3.at( mkt('1', 'x','l') ), 7.192 );
EXPECT_EQ( *(++ci), 7.192 );
EXPECT_EQ( sl3.at( mkt('2', 'x','l') ), 7.315 );
EXPECT_EQ( sl3.at( mkt('3', 'x','l') ), 1.536 );
EXPECT_EQ( sl3.at( mkt('1', 'x','f') ), 4.892 );
EXPECT_EQ( *(++ci), 4.892 );
EXPECT_EQ( sl3.at( mkt('2', 'x','f') ), 0.280 );
EXPECT_EQ( sl3.at( mkt('3', 'x','f') ), 8.870 );
EXPECT_EQ( sl3.at( mkt('1', 'x','g') ), 4.790 );
EXPECT_EQ( *(++ci), 4.790 );
EXPECT_EQ( sl3.at( mkt('2', 'x','g') ), 8.215 );
EXPECT_EQ( sl3.at( mkt('3', 'x','g') ), 5.063 );
EXPECT_EQ( sl3.at( mkt('1', 'y','a') ), 1.530 );
EXPECT_EQ( *(++ci), 1.530 );
EXPECT_EQ( sl3.at( mkt('2', 'y','a') ), 3.084 );
EXPECT_EQ( sl3.at( mkt('3', 'y','a') ), 1.609 );
EXPECT_EQ( sl3.at( mkt('1', 'y','l') ), 4.847 );
EXPECT_EQ( *(++ci), 4.847 );
EXPECT_EQ( sl3.at( mkt('2', 'y','l') ), 8.175 );
EXPECT_EQ( sl3.at( mkt('3', 'y','l') ), 0.112 );
EXPECT_EQ( sl3.at( mkt('1', 'y','f') ), 6.712 );
EXPECT_EQ( *(++ci), 6.712 );
EXPECT_EQ( sl3.at( mkt('2', 'y','f') ), 6.408 );
EXPECT_EQ( sl3.at( mkt('3', 'y','f') ), 1.959 );
EXPECT_EQ( sl3.at( mkt('1', 'y','g') ), 0.331 );
EXPECT_EQ( *(++ci), 0.331 );
EXPECT_EQ( sl3.at( mkt('2', 'y','g') ), 4.209 );
EXPECT_EQ( sl3.at( mkt('3', 'y','g') ), 2.951 );
EXPECT_EQ( *(++ci), 9.436 );
EXPECT_EQ( *(++ci), 7.315 );
}