im com (block type scanning routines...)

This commit is contained in:
Christian Zimmermann 2017-08-28 18:28:43 +02:00
parent aa803b81f2
commit fbcdfd7580
10 changed files with 206 additions and 10 deletions

View file

@ -41,6 +41,12 @@ namespace MultiArrayTools
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
} }
template <class... Indices>
IndexType ContainerIndex<Indices...>::type() const
{
return IndexType::CONT;
}
template <class... Indices> template <class... Indices>
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator++() ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator++()
{ {
@ -116,6 +122,17 @@ namespace MultiArrayTools
{ {
return std::get<N>( mIPack ); return std::get<N>( mIPack );
} }
template <class... Indices>
std::shared_ptr<const IndexBase> ContainerIndex<Indices...>::getPtr(size_t n) const
{
if(n >= sizeof...(Indices)){
assert(0);
// throw !!
}
ContainerIndex<Indices...> const* t = this;
return PackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
}
template <class... Indices> template <class... Indices>
bool ContainerIndex<Indices...>::first() const bool ContainerIndex<Indices...>::first() const

View file

@ -38,6 +38,8 @@ namespace MultiArrayTools
template <class MRange> template <class MRange>
ContainerIndex(const std::shared_ptr<MRange>& range); ContainerIndex(const std::shared_ptr<MRange>& range);
virtual IndexType type() const override;
virtual ContainerIndex& operator++() override; virtual ContainerIndex& operator++() override;
virtual ContainerIndex& operator--() override; virtual ContainerIndex& operator--() override;
virtual ContainerIndex& operator=(size_t pos) override; virtual ContainerIndex& operator=(size_t pos) override;
@ -57,6 +59,8 @@ namespace MultiArrayTools
template <size_t N> template <size_t N>
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&; auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
virtual std::shared_ptr<const IndexBase> getPtr(size_t n) const override;
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices

View file

@ -19,6 +19,12 @@ namespace MultiArrayTools
++id; ++id;
return id; return id;
} }
enum class IndexType{
SINGLE = 0,
MULTI = 1,
CONT = 2
};
class IndexBase class IndexBase
{ {
@ -31,6 +37,8 @@ namespace MultiArrayTools
IndexBase(const std::shared_ptr<RangeBase>& range, size_t pos); IndexBase(const std::shared_ptr<RangeBase>& range, size_t pos);
virtual ~IndexBase() = default; virtual ~IndexBase() = default;
virtual IndexType type() const = 0;
virtual IndexBase& operator=(size_t pos) = 0; virtual IndexBase& operator=(size_t pos) = 0;
virtual IndexBase& operator++() = 0; virtual IndexBase& operator++() = 0;
@ -45,6 +53,8 @@ namespace MultiArrayTools
virtual bool last() const = 0; virtual bool last() const = 0;
virtual bool first() const = 0; virtual bool first() const = 0;
virtual std::shared_ptr<const IndexBase> getPtr(size_t n) const = 0;
virtual operator size_t() const; virtual operator size_t() const;

View file

@ -8,7 +8,43 @@ namespace MultiArrayTools
{ {
using namespace MultiArrayHelper; using namespace MultiArrayHelper;
} }
void seekIndexInst(std::shared_ptr<const IndexBase> i, std::vector<std::shared_ptr<const IndexBase> >& ivec)
{
for(size_t inum = 0; inum != i->range()->dim(); ++inum){
auto ii = i->getPtr(inum);
if(ii->type() == IndexType::MULTI){
seekIndexInst(ii, ivec);
}
ivec.push_back(ii);
}
}
BlockType getBlockType(std::shared_ptr<const IndexBase> i,
std::shared_ptr<const IndexBase> j, bool first)
{
BlockType out = BlockType::VALUE;
for(size_t inum = 0; inum != i->range()->dim(); ++inum){
if(ii == j){
if(inum == 0){
out = BlockType::BLOCK;
}
else {
out = BlockType::SPLIT;
}
continue;
}
if(ii->type() == IndexType::MULTI){
BlockType tmp = getBlockType(ii, j, ivec);
if(tmp != BlockType::VALUE){
out = tmp;
}
}
}
return out;
}
/********************************* /*********************************
* MultiArrayOperationBase * * MultiArrayOperationBase *
*********************************/ *********************************/
@ -86,6 +122,20 @@ namespace MultiArrayTools
{ {
return mArrayRef.data()[ mIndex->pos() ]; return mArrayRef.data()[ mIndex->pos() ];
} }
template <typename T, class... Ranges>
std::vector<BlockType> OperationMaster<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
{
// seek index with smallest number of SPLITs !!!
}
template <typename T, class... Ranges>
OperationMaster<T,Ranges...>& OperationMaster<T,Ranges...>::block() const
{
mBlockPtr->set( &mArrayRef[ (*mIndex) ] );
return *this;
}
/**************************** /****************************
* ConstOperationRoot * * ConstOperationRoot *
@ -104,7 +154,21 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
const BlockBase<T>& ConstOperationRoot<T,Ranges...>::get() const const BlockBase<T>& ConstOperationRoot<T,Ranges...>::get() const
{ {
return mArrayRef[ (*mIndex)() ]; block();
return *mBlockPtr;
}
template <typename T, class... Ranges>
std::vector<BlockType> ConstOperationRoot<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
{
// !!!
}
template <typename T, class... Ranges>
ConstOperationRoot<T,Ranges...>& ConstOperationRoot<T,Ranges...>::block() const
{
mBlockPtr->set( &mArrayRef[ (*mIndex)() ] );
return *this;
} }
/*********************** /***********************
@ -130,15 +194,30 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
const BlockBase<T>& OperationRoot<T,Ranges...>::get() const const BlockBase<T>& OperationRoot<T,Ranges...>::get() const
{ {
return mArrayRef[ (*mIndex)() ]; block();
return *mBlockPtr;
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
BlockBase<T>& OperationRoot<T,Ranges...>::get() BlockBase<T>& OperationRoot<T,Ranges...>::get()
{ {
return mArrayRef[ (*mIndex)() ]; block();
return *mBlockPtr; // issue: const !!!
} }
template <typename T, class... Ranges>
std::vector<BlockType> OperationRoot<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
{
// !!!
}
template <typename T, class... Ranges>
OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::block() const
{
mBlockPtr->set( &mArrayRef[ (*mIndex)() ] );
return *this;
}
/*********************** /***********************
* OperationRoot * * OperationRoot *
***********************/ ***********************/
@ -154,4 +233,18 @@ namespace MultiArrayTools
mRes = PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mOps); mRes = PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mOps);
return mRes; return mRes;
} }
template <typename T, class... Ranges>
std::vector<BlockType> Operation<T,Ranges...>::block(const std::shared_ptr<IndexBase>& blockIndex) const
{
// !!!
}
template <typename T, class... Ranges>
Operation<T,Ranges...>& Operation<T,Ranges...>::block() const
{
mBlockPtr->set( &mArrayRef[ (*mIndex)() ] );
return *this;
}
} }

View file

@ -29,6 +29,11 @@ namespace MultiArrayTools
* OperationTemplate<...> * OperationTemplate<...>
* *
*/ */
void seekIndexInst(std::shared_ptr<const IndexBase> i, std::vector<std::shared_ptr<const IndexBase> >& ivec);
BlockType getBlockType(std::shared_ptr<const IndexBase> i,
std::shared_ptr<const IndexBase> j, bool first);
template <typename T> template <typename T>
class OperationBase class OperationBase
@ -40,7 +45,9 @@ namespace MultiArrayTools
OperationBase() = default; OperationBase() = default;
virtual ~OperationBase() = default; virtual ~OperationBase() = default;
virtual OperationBase& block(const std::shared_ptr<IndexBase>& blockIndex) = 0; // init block, return resulting type (BLOCK, VALUE, SPLIT)
virtual std::vector<BlockType> block(const std::shared_ptr<IndexBase>& blockIndex) const = 0;
virtual OperationBase& block() const = 0; // update block
//virtual size_t argNum() const = 0; //virtual size_t argNum() const = 0;
virtual const BlockBase<T>& get() const = 0; virtual const BlockBase<T>& get() const = 0;
@ -104,6 +111,9 @@ namespace MultiArrayTools
virtual BlockBase<T>& get() override; virtual BlockBase<T>& get() override;
virtual const BlockBase<T>& get() const override; virtual const BlockBase<T>& get() const override;
virtual std::vector<BlockType> block(const std::shared_ptr<IndexBase>& blockIndex) const override;
virtual OperationMaster& block() const override;
protected: protected:
//void performAssignment(const OperationBase<T>& in); //void performAssignment(const OperationBase<T>& in);
@ -129,6 +139,9 @@ namespace MultiArrayTools
const std::shared_ptr<typename Ranges::IndexType>&... indices); const std::shared_ptr<typename Ranges::IndexType>&... indices);
virtual const BlockBase<T>& get() const override; virtual const BlockBase<T>& get() const override;
virtual std::vector<BlockType> block(const std::shared_ptr<IndexBase>& blockIndex) const override;
virtual ConstOperationRoot& block() const override;
protected: protected:
@ -155,6 +168,9 @@ namespace MultiArrayTools
virtual const BlockBase<T>& get() const override; virtual const BlockBase<T>& get() const override;
virtual BlockBase<T>& get() override; virtual BlockBase<T>& get() override;
virtual std::vector<BlockType> block(const std::shared_ptr<IndexBase>& blockIndex) const override;
virtual OperationRoot& block() const override;
protected: protected:
@ -176,7 +192,10 @@ namespace MultiArrayTools
Operation(const Ops&... ops); Operation(const Ops&... ops);
virtual const BlockBase<T>& get() const override; virtual const BlockBase<T>& get() const override;
virtual std::vector<BlockType> block(const std::shared_ptr<IndexBase>& blockIndex) const override;
virtual Operation& block() const override;
protected: protected:
std::tuple<Ops...> mOps; std::tuple<Ops...> mOps;
mutable BlockResult<T> mRes; mutable BlockResult<T> mRes;

View file

@ -48,6 +48,12 @@ 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);
} }
template <class... Indices>
IndexType MultiIndex<Indices...>::type() const
{
return IndexType::MULTI;
}
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++() MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
@ -124,6 +130,17 @@ namespace MultiArrayTools
return PackNum<sizeof...(Indices)-1>::getIndex(*t, n); return PackNum<sizeof...(Indices)-1>::getIndex(*t, n);
} }
template <class... Indices>
std::shared_ptr<const IndexBase> MultiIndex<Indices...>::getPtr(size_t n) const
{
if(n >= sizeof...(Indices)){
assert(0);
// throw !!
}
MultiIndex<Indices...> const* t = this;
return PackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
}
template <class... Indices> template <class... Indices>
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const
{ {

View file

@ -38,6 +38,8 @@ namespace MultiArrayTools
template <class MRange> template <class MRange>
MultiIndex(const std::shared_ptr<MRange>& range); MultiIndex(const std::shared_ptr<MRange>& range);
virtual IndexType type() const override;
virtual MultiIndex& operator++() override; virtual MultiIndex& operator++() override;
virtual MultiIndex& operator--() override; virtual MultiIndex& operator--() override;
@ -56,6 +58,7 @@ namespace MultiArrayTools
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&; auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
const IndexBase& get(size_t n) const; const IndexBase& get(size_t n) const;
virtual std::shared_ptr<const IndexBase> getPtr(size_t n) const override;
virtual MetaType meta() const override; virtual MetaType meta() const override;
virtual MultiIndex& at(const MetaType& metaPos) override; virtual MultiIndex& at(const MetaType& metaPos) override;

View file

@ -21,7 +21,7 @@ namespace MultiArrayHelper
static IndexBase& getIndex(IndexType& in, size_t n) static IndexBase& getIndex(IndexType& in, size_t n)
{ {
if(n == N){ if(n == N){
return in.getIndex<N>(); return in.template get<N>();
} }
else { else {
return PackNum<N-1>::getIndex(in, n); return PackNum<N-1>::getIndex(in, n);
@ -32,12 +32,23 @@ namespace MultiArrayHelper
static const IndexBase& getIndex(const IndexType& in, size_t n) static const IndexBase& getIndex(const IndexType& in, size_t n)
{ {
if(n == N){ if(n == N){
return in.getIndex<N>(); return in.template get<N>();
} }
else { else {
return PackNum<N-1>::getIndex(in, n); return PackNum<N-1>::getIndex(in, n);
} }
} }
template <class IndexType>
static std::shared_ptr<const IndexBase> getIndexPtr(const IndexType& in, size_t n)
{
if(n == N){
return in.template getPtr<N>();
}
else {
return PackNum<N-1>::getIndexPtr(in, n);
}
}
template <class... Indices> template <class... Indices>
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip) static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip)
@ -163,13 +174,19 @@ namespace MultiArrayHelper
template <class MultiIndex> template <class MultiIndex>
static IndexBase& getIndex(MultiIndex& in, size_t n) static IndexBase& getIndex(MultiIndex& in, size_t n)
{ {
return in.getIndex<0>(); return in.template get<0>();
} }
template <class MultiIndex> template <class MultiIndex>
static const IndexBase& getIndex(const MultiIndex& in, size_t n) static const IndexBase& getIndex(const MultiIndex& in, size_t n)
{ {
return in.getIndex<0>(); return in.template get<0>();
}
template <class IndexType>
static std::shared_ptr<const IndexBase> getIndexPtr(const IndexType& in, size_t n)
{
return in.template getPtr<0>();
} }
template <class... Indices> template <class... Indices>

View file

@ -11,6 +11,12 @@ namespace MultiArrayTools
SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) : SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
IndexInterface<U>(range, 0) {} IndexInterface<U>(range, 0) {}
template <typename U, RangeType TYPE>
IndexType SingleIndex<U,TYPE>::type() const
{
return IndexType::SINGLE;
}
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos) SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
{ {
@ -63,6 +69,12 @@ namespace MultiArrayTools
return IB::mPos == 0; return IB::mPos == 0;
} }
template <typename U, RangeType TYPE>
std::shared_ptr<const IndexBase> SingleIndex<U,TYPE>::getPtr(size_t n) const
{
return std::shared_ptr<const IndexBase>();
}
/******************** /********************
* SingleRange * * SingleRange *
********************/ ********************/

View file

@ -26,6 +26,8 @@ namespace MultiArrayTools
//DEFAULT_MEMBERS_X(SingleIndex); //DEFAULT_MEMBERS_X(SingleIndex);
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range); SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
virtual IndexType type() const override;
virtual SingleIndex& operator=(size_t pos) override; virtual SingleIndex& operator=(size_t pos) override;
virtual SingleIndex& operator++() override; virtual SingleIndex& operator++() override;
@ -38,6 +40,8 @@ namespace MultiArrayTools
virtual bool last() const override; virtual bool last() const override;
virtual bool first() const override; virtual bool first() const override;
virtual std::shared_ptr<const IndexBase> getPtr(size_t n) const override;
virtual std::string id() const override { return std::string("sin") + std::to_string(IB::mId); } virtual std::string id() const override { return std::string("sin") + std::to_string(IB::mId); }
}; };