using blocking routines all unit tests work so far
This commit is contained in:
parent
bb6f18cf1c
commit
87c4a9f162
11 changed files with 73 additions and 51 deletions
|
@ -39,6 +39,8 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
||||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||||
|
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
||||||
|
PackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
|
@ -79,17 +81,17 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
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;
|
IB::mPos += tmp;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
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;
|
IB::mPos -= tmp;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
@ -121,6 +123,9 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
if(mExternControl){
|
if(mExternControl){
|
||||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||||
|
//VCHECK(id());
|
||||||
|
//VCHECK(sizeof...(Indices));
|
||||||
|
//assert(IB::mPos < IB::max());
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +177,6 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return IB::pos() == IB::mRangePtr->size() - 1;
|
return IB::pos() == IB::mRangePtr->size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
|
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
|
||||||
|
|
|
@ -45,8 +45,8 @@ namespace MultiArrayTools
|
||||||
virtual ContainerIndex& operator--() override;
|
virtual ContainerIndex& operator--() override;
|
||||||
virtual ContainerIndex& operator=(size_t pos) override;
|
virtual ContainerIndex& operator=(size_t pos) override;
|
||||||
|
|
||||||
virtual size_t pp(std::shared_ptr<IndexBase>& idxPtr) override;
|
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) override;
|
||||||
virtual size_t mm(std::shared_ptr<IndexBase>& idxPtr) override;
|
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) override;
|
||||||
|
|
||||||
virtual MetaType meta() const override;
|
virtual MetaType meta() const override;
|
||||||
virtual ContainerIndex& at(const MetaType& metaPos) override;
|
virtual ContainerIndex& at(const MetaType& metaPos) override;
|
||||||
|
|
|
@ -44,8 +44,8 @@ namespace MultiArrayTools
|
||||||
virtual IndexBase& operator++() = 0;
|
virtual IndexBase& operator++() = 0;
|
||||||
virtual IndexBase& operator--() = 0;
|
virtual IndexBase& operator--() = 0;
|
||||||
|
|
||||||
virtual size_t pp(std::shared_ptr<IndexBase>& idxPtr) = 0;
|
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) = 0;
|
||||||
virtual size_t mm(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;
|
||||||
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 last() const = 0;
|
||||||
virtual bool first() const = 0;
|
virtual bool first() const = 0;
|
||||||
|
|
||||||
//virtual bool locked() const;
|
//virtual bool locked() const;
|
||||||
//virtual IndexBase& lock(std::shared_ptr<IndexBase>& idx);
|
//virtual IndexBase& lock(std::shared_ptr<IndexBase>& idx);
|
||||||
|
|
||||||
|
|
|
@ -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
|
#endif
|
||||||
|
|
|
@ -13,7 +13,8 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
for(size_t inum = 0; inum != i->rangePtr()->dim(); ++inum){
|
for(size_t inum = 0; inum != i->rangePtr()->dim(); ++inum){
|
||||||
auto ii = i->getPtr(inum);
|
auto ii = i->getPtr(inum);
|
||||||
if(ii->type() == IndexType::MULTI){
|
if(ii->type() == IndexType::MULTI or
|
||||||
|
ii->type() == IndexType::CONT){
|
||||||
seekIndexInst(ii, ivec);
|
seekIndexInst(ii, ivec);
|
||||||
}
|
}
|
||||||
ivec.push_back(ii);
|
ivec.push_back(ii);
|
||||||
|
@ -21,7 +22,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
BTSS getBlockType(std::shared_ptr<IndexBase> i,
|
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)
|
// returning BlockType and step size is redundant (change in the future)
|
||||||
// stepSize == 0 => VALUE
|
// stepSize == 0 => VALUE
|
||||||
|
@ -32,18 +34,21 @@ namespace MultiArrayTools
|
||||||
for(size_t inum = 0; inum != lastNum; ++inum){
|
for(size_t inum = 0; inum != lastNum; ++inum){
|
||||||
auto ii = i->getPtr(inum);
|
auto ii = i->getPtr(inum);
|
||||||
if(ii == j){
|
if(ii == j){
|
||||||
|
|
||||||
if(inum == lastNum - 1 and first){
|
if(inum == lastNum - 1 and first){
|
||||||
out = BTSS(BlockType::BLOCK, 1);
|
out = BTSS(BlockType::BLOCK, 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
out = BTSS(BlockType::SPLIT, i->getStepSize(inum));
|
first = false;
|
||||||
|
out = BTSS(BlockType::SPLIT, i->getStepSize(inum) * higherStepSize + out.second);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ii->type() == IndexType::MULTI or
|
if(ii->type() == IndexType::MULTI or
|
||||||
ii->type() == IndexType::CONT){
|
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){
|
if(tmp.first != BlockType::VALUE){
|
||||||
out = tmp;
|
out = tmp;
|
||||||
}
|
}
|
||||||
|
@ -199,6 +204,7 @@ namespace MultiArrayTools
|
||||||
(*mIndex) = *index;
|
(*mIndex) = *index;
|
||||||
|
|
||||||
auto blockIndex = seekBlockIndex( mIndex, second);
|
auto blockIndex = seekBlockIndex( mIndex, second);
|
||||||
|
|
||||||
block(blockIndex);
|
block(blockIndex);
|
||||||
second.block(blockIndex);
|
second.block(blockIndex);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ namespace MultiArrayTools
|
||||||
typedef std::pair<BlockType,size_t> BTSS;
|
typedef std::pair<BlockType,size_t> BTSS;
|
||||||
|
|
||||||
BTSS getBlockType(std::shared_ptr<IndexBase> i,
|
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>
|
template <typename T>
|
||||||
std::shared_ptr<BlockBase<T> > makeBlock(const std::vector<T>& vec, size_t stepSize, size_t blockSize);
|
std::shared_ptr<BlockBase<T> > makeBlock(const std::vector<T>& vec, size_t stepSize, size_t blockSize);
|
||||||
|
|
|
@ -82,17 +82,17 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
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;
|
IB::mPos += tmp;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
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;
|
IB::mPos -= tmp;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ namespace MultiArrayTools
|
||||||
virtual MultiIndex& operator--() override;
|
virtual MultiIndex& operator--() override;
|
||||||
virtual MultiIndex& operator=(size_t pos) override;
|
virtual MultiIndex& operator=(size_t pos) override;
|
||||||
|
|
||||||
virtual size_t pp(std::shared_ptr<IndexBase>& idxPtr) override;
|
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) override;
|
||||||
virtual size_t mm(std::shared_ptr<IndexBase>& idxPtr) override;
|
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) override;
|
||||||
|
|
||||||
template <size_t DIR>
|
template <size_t DIR>
|
||||||
MultiIndex& up();
|
MultiIndex& up();
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
namespace MultiArrayHelper
|
namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
using namespace MultiArrayTools;
|
using namespace MultiArrayTools;
|
||||||
|
|
||||||
|
template <typename... T>
|
||||||
|
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp);
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
struct PackNum
|
struct PackNum
|
||||||
|
@ -80,21 +83,22 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline size_t pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::shared_ptr<IndexBase> idxPtr)
|
std::shared_ptr<IndexBase> idxPtr)
|
||||||
{
|
{
|
||||||
auto siPtr = std::get<N>(ip);
|
auto& siPtr = std::get<N>(ip);
|
||||||
if(siPtr.get() == idxPtr.get()){
|
if(siPtr.get() == idxPtr.get()){
|
||||||
return std::get<N>(bs) + PackNum<N-1>::pp(ip, bs, idxPtr);
|
return std::get<N>(bs) + PackNum<N-1>::pp(ip, bs, idxPtr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(siPtr->last()){
|
size_t tmp = siPtr->pp(idxPtr);
|
||||||
|
if(siPtr->pos() == siPtr->max()){
|
||||||
(*siPtr) = 0;
|
(*siPtr) = 0;
|
||||||
return PackNum<N-1>::pp(ip, bs, idxPtr) - siPtr->max() + 1;
|
return PackNum<N-1>::pp(ip, bs, idxPtr) - siPtr->max() + 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return siPtr->pp(idxPtr);
|
return tmp * std::get<N+1>(bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,11 +117,11 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline size_t mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::shared_ptr<IndexBase> idxPtr)
|
std::shared_ptr<IndexBase> idxPtr)
|
||||||
{
|
{
|
||||||
auto siPtr = std::get<N>(ip);
|
auto& siPtr = std::get<N>(ip);
|
||||||
if(siPtr.get() == idxPtr.get()){
|
if(siPtr.get() == idxPtr.get()){
|
||||||
return std::get<N>(bs) + PackNum<N-1>::mm(ip, bs, idxPtr);
|
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)
|
static size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
||||||
{
|
{
|
||||||
auto ID = std::get<N>(iPtrTup)->id();
|
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() +
|
return std::get<N>(iPtrTup)->pos() +
|
||||||
PackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
|
PackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
|
||||||
}
|
}
|
||||||
|
@ -283,16 +289,16 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline size_t pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::shared_ptr<IndexBase> idxPtr)
|
std::shared_ptr<IndexBase> idxPtr)
|
||||||
{
|
{
|
||||||
auto siPtr = std::get<0>(ip);
|
auto& siPtr = std::get<0>(ip);
|
||||||
if(siPtr.get() == idxPtr.get()){
|
if(siPtr.get() == idxPtr.get()){
|
||||||
return std::get<0>(bs);
|
return std::get<0>(bs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return siPtr->pp(idxPtr);
|
return siPtr->pp(idxPtr) * std::get<1>(bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,13 +310,14 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
static inline size_t mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
std::shared_ptr<IndexBase> idxPtr)
|
std::shared_ptr<IndexBase> idxPtr)
|
||||||
{
|
{
|
||||||
auto siPtr = std::get<0>(ip);
|
auto& siPtr = std::get<0>(ip);
|
||||||
if(siPtr.get() == idxPtr.get()){
|
if(siPtr.get() == idxPtr.get()){
|
||||||
return std::get<0>(bs);
|
return std::get<0>(bs);
|
||||||
|
//return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return siPtr->mm(idxPtr);
|
return siPtr->mm(idxPtr);
|
||||||
|
@ -377,6 +384,8 @@ namespace MultiArrayHelper
|
||||||
static size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
static size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
||||||
{
|
{
|
||||||
auto ID = std::get<0>(iPtrTup)->id();
|
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();
|
return std::get<0>(iPtrTup)->pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,6 +425,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
|
} // end namespace MultiArrayHelper
|
||||||
|
|
||||||
|
|
|
@ -39,14 +39,14 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
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);
|
++(*this);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
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);
|
--(*this);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -33,8 +33,8 @@ namespace MultiArrayTools
|
||||||
virtual SingleIndex& operator++() override;
|
virtual SingleIndex& operator++() override;
|
||||||
virtual SingleIndex& operator--() override;
|
virtual SingleIndex& operator--() override;
|
||||||
|
|
||||||
virtual size_t pp(std::shared_ptr<IndexBase>& idxPtr) override;
|
virtual int pp(std::shared_ptr<IndexBase>& idxPtr) override;
|
||||||
virtual size_t mm(std::shared_ptr<IndexBase>& idxPtr) override;
|
virtual int mm(std::shared_ptr<IndexBase>& idxPtr) override;
|
||||||
|
|
||||||
virtual U meta() const override;
|
virtual U meta() const override;
|
||||||
virtual SingleIndex& at(const U& metaPos) override;
|
virtual SingleIndex& at(const U& metaPos) override;
|
||||||
|
|
Loading…
Reference in a new issue