diff --git a/src/container_range.cc b/src/container_range.cc index b660671..c0fbdd6 100644 --- a/src/container_range.cc +++ b/src/container_range.cc @@ -39,6 +39,8 @@ namespace MultiArrayTools { PackNum::construct(mIPack, *range); IB::mPos = PackNum::makePos(mIPack); + std::get(mBlockSizes) = 1; + PackNum::initBlockSizes(mBlockSizes, mIPack); } template @@ -79,17 +81,17 @@ namespace MultiArrayTools } template - size_t ContainerIndex::pp(std::shared_ptr& idxPtr) + int ContainerIndex::pp(std::shared_ptr& idxPtr) { - size_t tmp = PackNum::pp(mIPack, mBlockSizes, idxPtr); + int tmp = PackNum::pp(mIPack, mBlockSizes, idxPtr); IB::mPos += tmp; return tmp; } template - size_t ContainerIndex::mm(std::shared_ptr& idxPtr) + int ContainerIndex::mm(std::shared_ptr& idxPtr) { - size_t tmp = PackNum::mm(mIPack, mBlockSizes, idxPtr); + int tmp = PackNum::mm(mIPack, mBlockSizes, idxPtr); IB::mPos -= tmp; return tmp; } @@ -121,6 +123,9 @@ namespace MultiArrayTools { if(mExternControl){ IB::mPos = PackNum::makePos(mIPack); + //VCHECK(id()); + //VCHECK(sizeof...(Indices)); + //assert(IB::mPos < IB::max()); } return *this; } @@ -172,7 +177,6 @@ namespace MultiArrayTools { return IB::pos() == IB::mRangePtr->size() - 1; } - template ContainerIndex& ContainerIndex::operator()(const std::shared_ptr&... inds) diff --git a/src/container_range.h b/src/container_range.h index 87c5753..4482567 100644 --- a/src/container_range.h +++ b/src/container_range.h @@ -45,8 +45,8 @@ namespace MultiArrayTools virtual ContainerIndex& operator--() override; virtual ContainerIndex& operator=(size_t pos) override; - virtual size_t pp(std::shared_ptr& idxPtr) override; - virtual size_t mm(std::shared_ptr& idxPtr) override; + virtual int pp(std::shared_ptr& idxPtr) override; + virtual int mm(std::shared_ptr& idxPtr) override; virtual MetaType meta() const override; virtual ContainerIndex& at(const MetaType& metaPos) override; diff --git a/src/index_base.h b/src/index_base.h index a0d0f7b..bc8d2ea 100644 --- a/src/index_base.h +++ b/src/index_base.h @@ -44,8 +44,8 @@ namespace MultiArrayTools virtual IndexBase& operator++() = 0; virtual IndexBase& operator--() = 0; - virtual size_t pp(std::shared_ptr& idxPtr) = 0; - virtual size_t mm(std::shared_ptr& idxPtr) = 0; + virtual int pp(std::shared_ptr& idxPtr) = 0; + virtual int mm(std::shared_ptr& idxPtr) = 0; bool operator==(const IndexBase& in) const; bool operator!=(const IndexBase& in) const; @@ -56,7 +56,7 @@ namespace MultiArrayTools virtual bool last() const = 0; virtual bool first() const = 0; - + //virtual bool locked() const; //virtual IndexBase& lock(std::shared_ptr& idx); diff --git a/src/multi_array_header.h b/src/multi_array_header.h index 6e37477..5fde256 100644 --- a/src/multi_array_header.h +++ b/src/multi_array_header.h @@ -54,12 +54,6 @@ namespace MultiArrayTools // ... */ - template - std::ostream& operator<<(std::ostream& out, const std::tuple& tp) - { - PackNum::printTuple(out, tp); - return out; - } } #endif diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index a6b5cc1..5e1c35c 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -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 i, - std::shared_ptr j, bool first) + std::shared_ptr 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); + ii->type() == IndexType::CONT){ + + 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); diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 8e2f6a0..9998fc1 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -39,7 +39,8 @@ namespace MultiArrayTools typedef std::pair BTSS; BTSS getBlockType(std::shared_ptr i, - std::shared_ptr j, bool first); + std::shared_ptr j, + bool first, size_t higherStepSize = 1); template std::shared_ptr > makeBlock(const std::vector& vec, size_t stepSize, size_t blockSize); diff --git a/src/multi_range.cc b/src/multi_range.cc index 9bf7f94..049ab48 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -82,17 +82,17 @@ namespace MultiArrayTools } template - size_t MultiIndex::pp(std::shared_ptr& idxPtr) + int MultiIndex::pp(std::shared_ptr& idxPtr) { - size_t tmp = PackNum::pp(mIPack, mBlockSizes, idxPtr); + int tmp = PackNum::pp(mIPack, mBlockSizes, idxPtr); IB::mPos += tmp; return tmp; } template - size_t MultiIndex::mm(std::shared_ptr& idxPtr) + int MultiIndex::mm(std::shared_ptr& idxPtr) { - size_t tmp = PackNum::mm(mIPack, mBlockSizes, idxPtr); + int tmp = PackNum::mm(mIPack, mBlockSizes, idxPtr); IB::mPos -= tmp; return tmp; } diff --git a/src/multi_range.h b/src/multi_range.h index 5cd348f..bfd1285 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -46,8 +46,8 @@ namespace MultiArrayTools virtual MultiIndex& operator--() override; virtual MultiIndex& operator=(size_t pos) override; - virtual size_t pp(std::shared_ptr& idxPtr) override; - virtual size_t mm(std::shared_ptr& idxPtr) override; + virtual int pp(std::shared_ptr& idxPtr) override; + virtual int mm(std::shared_ptr& idxPtr) override; template MultiIndex& up(); diff --git a/src/pack_num.h b/src/pack_num.h index c5279b2..fadbbdb 100644 --- a/src/pack_num.h +++ b/src/pack_num.h @@ -13,6 +13,9 @@ namespace MultiArrayHelper { using namespace MultiArrayTools; + + template + std::ostream& operator<<(std::ostream& out, const std::tuple& tp); template struct PackNum @@ -80,21 +83,22 @@ namespace MultiArrayHelper } template - static inline size_t pp(std::tuple...>& ip, - std::array& bs, - std::shared_ptr idxPtr) + static inline int pp(std::tuple...>& ip, + std::array& bs, + std::shared_ptr idxPtr) { - auto siPtr = std::get(ip); + auto& siPtr = std::get(ip); if(siPtr.get() == idxPtr.get()){ return std::get(bs) + PackNum::pp(ip, bs, idxPtr); } else { - if(siPtr->last()){ + size_t tmp = siPtr->pp(idxPtr); + if(siPtr->pos() == siPtr->max()){ (*siPtr) = 0; return PackNum::pp(ip, bs, idxPtr) - siPtr->max() + 1; } else { - return siPtr->pp(idxPtr); + return tmp * std::get(bs); } } } @@ -113,11 +117,11 @@ namespace MultiArrayHelper } template - static inline size_t mm(std::tuple...>& ip, - std::array& bs, - std::shared_ptr idxPtr) + static inline int mm(std::tuple...>& ip, + std::array& bs, + std::shared_ptr idxPtr) { - auto siPtr = std::get(ip); + auto& siPtr = std::get(ip); if(siPtr.get() == idxPtr.get()){ return std::get(bs) + PackNum::mm(ip, bs, idxPtr); } @@ -198,6 +202,8 @@ namespace MultiArrayHelper static size_t makePos(const std::tuple...>& iPtrTup) { auto ID = std::get(iPtrTup)->id(); + //VCHECK(std::get(iPtrTup)->pos()); + //VCHECK(std::get(iPtrTup)->max()); return std::get(iPtrTup)->pos() + PackNum::makePos(iPtrTup) * std::get(iPtrTup)->max(); } @@ -283,16 +289,16 @@ namespace MultiArrayHelper } template - static inline size_t pp(std::tuple...>& ip, - std::array& bs, - std::shared_ptr idxPtr) + static inline int pp(std::tuple...>& ip, + std::array& bs, + std::shared_ptr 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 - static inline size_t mm(std::tuple...>& ip, - std::array& bs, - std::shared_ptr idxPtr) + static inline int mm(std::tuple...>& ip, + std::array& bs, + std::shared_ptr 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...>& 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(); } @@ -416,6 +425,14 @@ namespace MultiArrayHelper } }; + + template + std::ostream& operator<<(std::ostream& out, const std::tuple& tp) + { + PackNum::printTuple(out, tp); + return out; + } + } // end namespace MultiArrayHelper diff --git a/src/single_range.cc b/src/single_range.cc index 7009cc0..7e0e98d 100644 --- a/src/single_range.cc +++ b/src/single_range.cc @@ -39,14 +39,14 @@ namespace MultiArrayTools } template - size_t SingleIndex::pp(std::shared_ptr& idxPtr) + int SingleIndex::pp(std::shared_ptr& idxPtr) { ++(*this); return 1; } template - size_t SingleIndex::mm(std::shared_ptr& idxPtr) + int SingleIndex::mm(std::shared_ptr& idxPtr) { --(*this); return 1; diff --git a/src/single_range.h b/src/single_range.h index b9d86c0..8cc4a23 100644 --- a/src/single_range.h +++ b/src/single_range.h @@ -33,8 +33,8 @@ namespace MultiArrayTools virtual SingleIndex& operator++() override; virtual SingleIndex& operator--() override; - virtual size_t pp(std::shared_ptr& idxPtr) override; - virtual size_t mm(std::shared_ptr& idxPtr) override; + virtual int pp(std::shared_ptr& idxPtr) override; + virtual int mm(std::shared_ptr& idxPtr) override; virtual U meta() const override; virtual SingleIndex& at(const U& metaPos) override;