some fixes + container range test -> working
This commit is contained in:
parent
40864ace00
commit
16e8e588cb
6 changed files with 159 additions and 26 deletions
|
@ -34,7 +34,8 @@ namespace MultiArrayTools
|
|||
|
||||
template <class... Indices>
|
||||
template <class MRange>
|
||||
ContainerIndex<Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range)
|
||||
ContainerIndex<Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range) :
|
||||
IndexInterface<std::tuple<decltype(Indices().meta())...> >(range, 0)
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
|
@ -93,24 +94,31 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
size_t ContainerIndex<Indices...>::pos() const
|
||||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::sync()
|
||||
{
|
||||
if(mExternControl){
|
||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
}
|
||||
return IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <size_t N>
|
||||
auto ContainerIndex<Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
|
||||
{
|
||||
return *std::get<N>( mIPack );
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
bool ContainerIndex<Indices...>::first() const
|
||||
{
|
||||
return pos() == 0;
|
||||
return IB::pos() == 0;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
bool ContainerIndex<Indices...>::last() const
|
||||
{
|
||||
return pos() == IB::mRangePtr->size() - 1;
|
||||
return IB::pos() == IB::mRangePtr->size() - 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -119,7 +127,13 @@ namespace MultiArrayTools
|
|||
{
|
||||
PackNum<sizeof...(Indices)-1>::swapIndices(mIPack, inds...);
|
||||
mExternControl = true;
|
||||
return *this;
|
||||
return sync();
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator()()
|
||||
{
|
||||
return sync();
|
||||
}
|
||||
|
||||
/*****************************
|
||||
|
@ -169,6 +183,20 @@ namespace MultiArrayTools
|
|||
return PackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
template <size_t N>
|
||||
auto ContainerRange<Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
|
||||
{
|
||||
return *std::get<N>( mSpace );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
template <size_t N>
|
||||
auto ContainerRange<Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
|
||||
{
|
||||
return std::get<N>( mSpace );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::begin() const
|
||||
{
|
||||
|
|
|
@ -48,10 +48,16 @@ namespace MultiArrayTools
|
|||
virtual bool last() const override;
|
||||
|
||||
virtual size_t dim() const override;
|
||||
virtual size_t pos() const override; // recalculate when externalControl == true
|
||||
|
||||
ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true
|
||||
|
||||
template <size_t N>
|
||||
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
||||
|
||||
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
||||
|
||||
ContainerIndex& operator()(); // -> sync; just to shorten the code
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -97,6 +103,12 @@ namespace MultiArrayTools
|
|||
virtual size_t dim() const override;
|
||||
virtual size_t size() const override;
|
||||
|
||||
template <size_t N>
|
||||
auto get() const -> decltype( *std::get<N>( mSpace ) )&;
|
||||
|
||||
template <size_t N>
|
||||
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
||||
|
||||
virtual IndexType begin() const override;
|
||||
virtual IndexType end() const override;
|
||||
|
||||
|
|
|
@ -27,6 +27,12 @@ namespace {
|
|||
fptr = nptr;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...))
|
||||
{
|
||||
return std::make_tuple(ts...);
|
||||
}
|
||||
|
||||
class IndexTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -60,12 +66,24 @@ namespace {
|
|||
|
||||
swapMFactory<M3RF>(rfbptr, temp1, temp2, temp3 );
|
||||
m3rptr = std::dynamic_pointer_cast<M3Range>( rfbptr->create() );
|
||||
|
||||
swapMFactory<MasterRF>(rfbptr, sr1ptr, m3rptr, sr2ptr);
|
||||
mstrptr = std::dynamic_pointer_cast<MasterRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<CRF>(rfbptr, m3rptr, sr2ptr);
|
||||
cr1ptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<CRF>(rfbptr, m3rptr, sr1ptr);
|
||||
cr2ptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||
std::shared_ptr<SRange> sr1ptr;
|
||||
std::shared_ptr<SRange> sr2ptr;
|
||||
std::shared_ptr<M3Range> m3rptr;
|
||||
std::shared_ptr<MasterRange> mstrptr;
|
||||
std::shared_ptr<CRange> cr1ptr;
|
||||
std::shared_ptr<CRange> cr2ptr;
|
||||
};
|
||||
|
||||
TEST_F(IndexTest, SingleIndex_SimpleCall)
|
||||
|
@ -101,15 +119,15 @@ namespace {
|
|||
EXPECT_EQ(mi.pos(), 0);
|
||||
EXPECT_EQ(mi.first(), true);
|
||||
EXPECT_EQ(mi.last(), false);
|
||||
EXPECT_EQ(mi.meta() == std::make_tuple('a','1','0'), true);
|
||||
mi.at(std::make_tuple('b','1','7'));
|
||||
EXPECT_EQ(mi.meta() == mkt('a','1','0'), true);
|
||||
mi.at( mkt('b','1','7') );
|
||||
EXPECT_EQ(mi.pos(), mi.max()-1);
|
||||
EXPECT_EQ(mi.first(), false);
|
||||
EXPECT_EQ(mi.last(), true);
|
||||
mi = 1;
|
||||
EXPECT_EQ(mi.meta() == std::make_tuple('a','1','7'), true);
|
||||
EXPECT_EQ(mi.meta() == mkt('a','1','7'), true);
|
||||
++mi;
|
||||
EXPECT_EQ(mi.meta() == std::make_tuple('b','1','0'), true);
|
||||
EXPECT_EQ(mi.meta() == mkt('b','1','0'), true);
|
||||
++mi;
|
||||
auto mi2 = m3rptr->end();
|
||||
--mi2;
|
||||
|
@ -118,6 +136,73 @@ namespace {
|
|||
--mi2;
|
||||
EXPECT_EQ(mi == mi2, false);
|
||||
EXPECT_EQ(mi != mi2, true);
|
||||
auto si = sr1ptr->begin();
|
||||
EXPECT_EQ(si == mi, false);
|
||||
EXPECT_EQ(si != mi, true);
|
||||
}
|
||||
|
||||
TEST_F(IndexTest, MasterRange_Check)
|
||||
{
|
||||
EXPECT_EQ(mstrptr->size(), 48);
|
||||
EXPECT_EQ(mstrptr->template get<0>().size(), 3);
|
||||
EXPECT_EQ(mstrptr->template get<1>().size(), 4);
|
||||
EXPECT_EQ(mstrptr->template get<2>().size(), 4);
|
||||
EXPECT_EQ(mstrptr->dim(), 3);
|
||||
EXPECT_EQ(mstrptr->template get<0>().dim(), 1);
|
||||
EXPECT_EQ(mstrptr->template get<1>().dim(), 3);
|
||||
|
||||
auto mi = mstrptr->begin();
|
||||
EXPECT_EQ(mi.meta() == mkt( 'e' , mkt('a', '1', '0') , 'x' ), true);
|
||||
mi = mi.max()-1;
|
||||
EXPECT_EQ(mi.meta() == mkt( 'n' , mkt('b', '1', '7') , 'f' ), true);
|
||||
mi.template down<1>();
|
||||
EXPECT_EQ(mi.meta() == mkt( 'n' , mkt('b', '1', '0') , 'f' ), true);
|
||||
mi.template down<0>();
|
||||
EXPECT_EQ(mi.meta() == mkt( 'b' , mkt('b', '1', '0') , 'f' ), true);
|
||||
mi.template down<2>();
|
||||
EXPECT_EQ(mi.meta() == mkt( 'b' , mkt('b', '1', '0') , 'l' ), true);
|
||||
mi.template up<1>();
|
||||
EXPECT_EQ(mi.meta() == mkt( 'b' , mkt('b', '1', '7') , 'l' ), true);
|
||||
|
||||
auto& subI = mi.template get<0>();
|
||||
EXPECT_EQ(subI.meta(), 'b');
|
||||
mi.template up<0>();
|
||||
EXPECT_EQ(subI.meta(), 'n');
|
||||
auto& subI2 = mi.template get<1>();
|
||||
EXPECT_EQ(subI2.meta() == mkt('b', '1', '7'), true);
|
||||
mi.template down<1>();
|
||||
EXPECT_EQ(subI2.meta() == mkt('b', '1', '0'), true);
|
||||
}
|
||||
|
||||
TEST_F(IndexTest, ContainerRange_Check)
|
||||
{
|
||||
EXPECT_EQ(cr1ptr->size(), 16);
|
||||
EXPECT_EQ(cr2ptr->size(), 12);
|
||||
|
||||
auto mi = mstrptr->begin();
|
||||
auto ci1 = cr1ptr->begin();
|
||||
auto ci2 = cr2ptr->begin();
|
||||
|
||||
EXPECT_EQ(ci1.max(), 16);
|
||||
EXPECT_EQ(ci2.max(), 12);
|
||||
|
||||
ci1(mi.template getPtr<1>(), mi.template getPtr<2>());
|
||||
ci2(mi.template getPtr<1>(), mi.template getPtr<0>());
|
||||
|
||||
EXPECT_EQ(ci1.pos(), 0);
|
||||
EXPECT_EQ(ci2.pos(), 0);
|
||||
++mi;
|
||||
EXPECT_EQ(ci1().pos(), 1);
|
||||
EXPECT_EQ(ci2().pos(), 0);
|
||||
mi.template up<1>();
|
||||
EXPECT_EQ(ci1().pos(), 5);
|
||||
EXPECT_EQ(ci2().pos(), 3);
|
||||
mi.template up<0>();
|
||||
EXPECT_EQ(ci1().pos(), 5);
|
||||
EXPECT_EQ(ci2().pos(), 4);
|
||||
mi = mi.max()-1;
|
||||
EXPECT_EQ(ci1().pos(), ci1.max()-1);
|
||||
EXPECT_EQ(ci2().pos(), ci2.max()-1);
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
|
|
@ -97,6 +97,13 @@ namespace MultiArrayTools
|
|||
return *std::get<N>(mIPack);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <size_t N>
|
||||
auto MultiIndex<Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
|
||||
{
|
||||
return std::get<N>(mIPack);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
const IndexBase& MultiIndex<Indices...>::get(size_t n) const
|
||||
{
|
||||
|
|
|
@ -50,6 +50,9 @@ namespace MultiArrayTools
|
|||
template <size_t N>
|
||||
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
||||
|
||||
template <size_t N>
|
||||
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
|
||||
|
||||
const IndexBase& get(size_t n) const;
|
||||
|
||||
virtual MetaType meta() const override;
|
||||
|
|
|
@ -92,10 +92,8 @@ namespace MultiArrayHelper
|
|||
auto& i = *std::get<N>(iPack).get();
|
||||
const size_t ownPos = pos % i.max();
|
||||
i = ownPos;
|
||||
if(ownPos == pos){
|
||||
PackNum<N-1>::setIndexPack(iPack, (pos - ownPos) / i.max() );
|
||||
}
|
||||
}
|
||||
|
||||
template <class MRange, class... Indices>
|
||||
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
|
@ -125,21 +123,21 @@ namespace MultiArrayHelper
|
|||
static size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
||||
{
|
||||
return std::get<N>(iPtrTup)->pos() +
|
||||
PackNum<N-1>::makePos(iPtrTup) * std::get<N-1>(iPtrTup)->max();
|
||||
PackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
|
||||
}
|
||||
|
||||
template <class Pack, class IndexType, class... Indices>
|
||||
static void swapIndices(Pack& ipack, const std::shared_ptr<Indices>&... ninds,
|
||||
const std::shared_ptr<IndexType>& nind)
|
||||
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind,
|
||||
const std::shared_ptr<Indices>&... ninds)
|
||||
{
|
||||
std::get<N>(ipack).swap( nind );
|
||||
std::get<std::tuple_size<Pack>::value-N-1>(ipack) = nind;
|
||||
PackNum<N-1>::swapIndices(ipack, ninds...);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
||||
{
|
||||
return std::get<sizeof...(Indices)-N-1>(pack)->size() * PackNum<N-1>::blockSize(pack);
|
||||
return std::get<sizeof...(Indices)-N-1>(pack)->max() * PackNum<N-1>::blockSize(pack);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -231,13 +229,13 @@ namespace MultiArrayHelper
|
|||
template <class Pack, class IndexType>
|
||||
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind)
|
||||
{
|
||||
std::get<0>(ipack).swap( nind );
|
||||
std::get<std::tuple_size<Pack>::value-1>(ipack) = nind;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
||||
{
|
||||
return std::get<sizeof...(Indices)-1>(pack)->size();
|
||||
return std::get<sizeof...(Indices)-1>(pack)->max();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue