using blocking routines all unit tests work so far

This commit is contained in:
Christian Zimmermann 2017-09-12 18:36:05 +02:00
parent bb6f18cf1c
commit 87c4a9f162
11 changed files with 73 additions and 51 deletions

View file

@ -39,6 +39,8 @@ namespace MultiArrayTools
{
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
PackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack);
}
template <class... Indices>
@ -79,17 +81,17 @@ namespace MultiArrayTools
}
template <class... Indices>
size_t ContainerIndex<Indices...>::pp(std::shared_ptr<IndexBase>& idxPtr)
int ContainerIndex<Indices...>::pp(std::shared_ptr<IndexBase>& idxPtr)
{
size_t tmp = PackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtr);
int tmp = PackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtr);
IB::mPos += tmp;
return tmp;
}
template <class... Indices>
size_t ContainerIndex<Indices...>::mm(std::shared_ptr<IndexBase>& idxPtr)
int ContainerIndex<Indices...>::mm(std::shared_ptr<IndexBase>& idxPtr)
{
size_t tmp = PackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtr);
int tmp = PackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtr);
IB::mPos -= tmp;
return tmp;
}
@ -121,6 +123,9 @@ namespace MultiArrayTools
{
if(mExternControl){
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
//VCHECK(id());
//VCHECK(sizeof...(Indices));
//assert(IB::mPos < IB::max());
}
return *this;
}
@ -173,7 +178,6 @@ namespace MultiArrayTools
return IB::pos() == IB::mRangePtr->size() - 1;
}
template <class... Indices>
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
{

View file

@ -45,8 +45,8 @@ namespace MultiArrayTools
virtual ContainerIndex& operator--() override;
virtual ContainerIndex& operator=(size_t pos) override;
virtual size_t pp(std::shared_ptr<IndexBase>& idxPtr) override;
virtual size_t mm(std::shared_ptr<IndexBase>& idxPtr) override;
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) override;
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) override;
virtual MetaType meta() const override;
virtual ContainerIndex& at(const MetaType& metaPos) override;

View file

@ -44,8 +44,8 @@ namespace MultiArrayTools
virtual IndexBase& operator++() = 0;
virtual IndexBase& operator--() = 0;
virtual size_t pp(std::shared_ptr<IndexBase>& idxPtr) = 0;
virtual size_t mm(std::shared_ptr<IndexBase>& idxPtr) = 0;
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) = 0;
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) = 0;
bool operator==(const IndexBase& in) const;
bool operator!=(const IndexBase& in) const;

View file

@ -54,12 +54,6 @@ namespace MultiArrayTools
// ...
*/
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp)
{
PackNum<sizeof...(T)-1>::printTuple(out, tp);
return out;
}
}
#endif

View file

@ -13,7 +13,8 @@ namespace MultiArrayTools
{
for(size_t inum = 0; inum != i->rangePtr()->dim(); ++inum){
auto ii = i->getPtr(inum);
if(ii->type() == IndexType::MULTI){
if(ii->type() == IndexType::MULTI or
ii->type() == IndexType::CONT){
seekIndexInst(ii, ivec);
}
ivec.push_back(ii);
@ -21,7 +22,8 @@ namespace MultiArrayTools
}
BTSS getBlockType(std::shared_ptr<IndexBase> i,
std::shared_ptr<IndexBase> j, bool first)
std::shared_ptr<IndexBase> j,
bool first, size_t higherStepSize)
{
// returning BlockType and step size is redundant (change in the future)
// stepSize == 0 => VALUE
@ -32,18 +34,21 @@ namespace MultiArrayTools
for(size_t inum = 0; inum != lastNum; ++inum){
auto ii = i->getPtr(inum);
if(ii == j){
if(inum == lastNum - 1 and first){
out = BTSS(BlockType::BLOCK, 1);
}
else {
out = BTSS(BlockType::SPLIT, i->getStepSize(inum));
first = false;
out = BTSS(BlockType::SPLIT, i->getStepSize(inum) * higherStepSize + out.second);
}
continue;
}
if(ii->type() == IndexType::MULTI or
ii->type() == IndexType::CONT){
BTSS tmp = getBlockType(ii, j, inum == lastNum - 1);
BTSS tmp = getBlockType(ii, j, inum == lastNum - 1, i->getStepSize(inum) * higherStepSize);
if(tmp.first != BlockType::VALUE){
out = tmp;
}
@ -199,6 +204,7 @@ namespace MultiArrayTools
(*mIndex) = *index;
auto blockIndex = seekBlockIndex( mIndex, second);
block(blockIndex);
second.block(blockIndex);

View file

@ -39,7 +39,8 @@ namespace MultiArrayTools
typedef std::pair<BlockType,size_t> BTSS;
BTSS getBlockType(std::shared_ptr<IndexBase> i,
std::shared_ptr<IndexBase> j, bool first);
std::shared_ptr<IndexBase> j,
bool first, size_t higherStepSize = 1);
template <typename T>
std::shared_ptr<BlockBase<T> > makeBlock(const std::vector<T>& vec, size_t stepSize, size_t blockSize);

View file

@ -82,17 +82,17 @@ namespace MultiArrayTools
}
template <class... Indices>
size_t MultiIndex<Indices...>::pp(std::shared_ptr<IndexBase>& idxPtr)
int MultiIndex<Indices...>::pp(std::shared_ptr<IndexBase>& idxPtr)
{
size_t tmp = PackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtr);
int tmp = PackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtr);
IB::mPos += tmp;
return tmp;
}
template <class... Indices>
size_t MultiIndex<Indices...>::mm(std::shared_ptr<IndexBase>& idxPtr)
int MultiIndex<Indices...>::mm(std::shared_ptr<IndexBase>& idxPtr)
{
size_t tmp = PackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtr);
int tmp = PackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtr);
IB::mPos -= tmp;
return tmp;
}

View file

@ -46,8 +46,8 @@ namespace MultiArrayTools
virtual MultiIndex& operator--() override;
virtual MultiIndex& operator=(size_t pos) override;
virtual size_t pp(std::shared_ptr<IndexBase>& idxPtr) override;
virtual size_t mm(std::shared_ptr<IndexBase>& idxPtr) override;
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) override;
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) override;
template <size_t DIR>
MultiIndex& up();

View file

@ -14,6 +14,9 @@ namespace MultiArrayHelper
{
using namespace MultiArrayTools;
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp);
template <size_t N>
struct PackNum
{
@ -80,21 +83,22 @@ namespace MultiArrayHelper
}
template <class... Indices>
static inline size_t pp(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::shared_ptr<IndexBase> idxPtr)
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::shared_ptr<IndexBase> idxPtr)
{
auto siPtr = std::get<N>(ip);
auto& siPtr = std::get<N>(ip);
if(siPtr.get() == idxPtr.get()){
return std::get<N>(bs) + PackNum<N-1>::pp(ip, bs, idxPtr);
}
else {
if(siPtr->last()){
size_t tmp = siPtr->pp(idxPtr);
if(siPtr->pos() == siPtr->max()){
(*siPtr) = 0;
return PackNum<N-1>::pp(ip, bs, idxPtr) - siPtr->max() + 1;
}
else {
return siPtr->pp(idxPtr);
return tmp * std::get<N+1>(bs);
}
}
}
@ -113,11 +117,11 @@ namespace MultiArrayHelper
}
template <class... Indices>
static inline size_t mm(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::shared_ptr<IndexBase> idxPtr)
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::shared_ptr<IndexBase> idxPtr)
{
auto siPtr = std::get<N>(ip);
auto& siPtr = std::get<N>(ip);
if(siPtr.get() == idxPtr.get()){
return std::get<N>(bs) + PackNum<N-1>::mm(ip, bs, idxPtr);
}
@ -198,6 +202,8 @@ namespace MultiArrayHelper
static size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
{
auto ID = std::get<N>(iPtrTup)->id();
//VCHECK(std::get<N>(iPtrTup)->pos());
//VCHECK(std::get<N>(iPtrTup)->max());
return std::get<N>(iPtrTup)->pos() +
PackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
}
@ -283,16 +289,16 @@ namespace MultiArrayHelper
}
template <class... Indices>
static inline size_t pp(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::shared_ptr<IndexBase> idxPtr)
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::shared_ptr<IndexBase> idxPtr)
{
auto siPtr = std::get<0>(ip);
auto& siPtr = std::get<0>(ip);
if(siPtr.get() == idxPtr.get()){
return std::get<0>(bs);
}
else {
return siPtr->pp(idxPtr);
return siPtr->pp(idxPtr) * std::get<1>(bs);
}
}
@ -304,13 +310,14 @@ namespace MultiArrayHelper
}
template <class... Indices>
static inline size_t mm(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::shared_ptr<IndexBase> idxPtr)
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::shared_ptr<IndexBase> idxPtr)
{
auto siPtr = std::get<0>(ip);
auto& siPtr = std::get<0>(ip);
if(siPtr.get() == idxPtr.get()){
return std::get<0>(bs);
//return 1;
}
else {
return siPtr->mm(idxPtr);
@ -377,6 +384,8 @@ namespace MultiArrayHelper
static size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
{
auto ID = std::get<0>(iPtrTup)->id();
//VCHECK(std::get<0>(iPtrTup)->pos());
//VCHECK(std::get<0>(iPtrTup)->max());
return std::get<0>(iPtrTup)->pos();
}
@ -417,6 +426,14 @@ namespace MultiArrayHelper
};
template <typename... T>
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp)
{
PackNum<sizeof...(T)-1>::printTuple(out, tp);
return out;
}
} // end namespace MultiArrayHelper
#endif

View file

@ -39,14 +39,14 @@ namespace MultiArrayTools
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::pp(std::shared_ptr<IndexBase>& idxPtr)
int SingleIndex<U,TYPE>::pp(std::shared_ptr<IndexBase>& idxPtr)
{
++(*this);
return 1;
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::mm(std::shared_ptr<IndexBase>& idxPtr)
int SingleIndex<U,TYPE>::mm(std::shared_ptr<IndexBase>& idxPtr)
{
--(*this);
return 1;

View file

@ -33,8 +33,8 @@ namespace MultiArrayTools
virtual SingleIndex& operator++() override;
virtual SingleIndex& operator--() override;
virtual size_t pp(std::shared_ptr<IndexBase>& idxPtr) override;
virtual size_t mm(std::shared_ptr<IndexBase>& idxPtr) override;
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) override;
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) override;
virtual U meta() const override;
virtual SingleIndex& at(const U& metaPos) override;