slice code seems to compile
This commit is contained in:
parent
10f6f75552
commit
4df82f263e
9 changed files with 117 additions and 41 deletions
|
@ -3,6 +3,7 @@
|
|||
#define __helper_tools_h__
|
||||
|
||||
#include "base_def.h"
|
||||
#include "slice.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
@ -23,7 +24,9 @@ namespace MultiArrayTools
|
|||
auto mkMIndex(std::shared_ptr<IndexTypes>... indices)
|
||||
-> decltype( getIndex( mkMulti( indices.range()... ) ) );
|
||||
|
||||
|
||||
template <class... RangeTypes>
|
||||
auto mkMulti(std::tuple<std::shared_ptr<RangeTypes>...> rangesTuple)
|
||||
-> MultiRange<RangeTypes...>;
|
||||
}
|
||||
|
||||
/* ========================= *
|
||||
|
@ -66,6 +69,15 @@ namespace MultiArrayTools
|
|||
(*mi)( indices... );
|
||||
return mi;
|
||||
}
|
||||
|
||||
template <class... RangeTypes>
|
||||
auto mkMulti(std::tuple<std::shared_ptr<RangeTypes>...> rangesTuple)
|
||||
-> MultiRange<RangeTypes...>
|
||||
{
|
||||
MultiRangeFactory<RangeTypes...> mrf( rangesTuple );
|
||||
return std::dynamic_pointer_cast<MultiRange<RangeTypes...> >( mrf.create() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -54,8 +54,6 @@ namespace MultiArrayTools
|
|||
operator()(std::shared_ptr<typename SRanges::IndexType>&... inds) const;
|
||||
|
||||
virtual bool isInit() const;
|
||||
|
||||
// slice function !!!!!
|
||||
|
||||
protected:
|
||||
bool mInit = false;
|
||||
|
@ -116,7 +114,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
ContainerRangeFactory<T,SRanges...> crf(ranges...);
|
||||
mRange = std::dynamic_pointer_cast<ContainerRange<T,SRanges...> >( crf.create() );
|
||||
mProtoI = std::make_shared<IndexType>( mRange );
|
||||
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
|
@ -124,7 +122,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
ContainerRangeFactory<T,SRanges...> crf(space);
|
||||
mRange = std::dynamic_pointer_cast<ContainerRange<T,SRanges...> >( crf.create() );
|
||||
mProtoI = std::make_shared<IndexType>( mRange );
|
||||
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace MultiArrayTools
|
|||
IndexPack mIPack;
|
||||
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
|
||||
const T* mData;
|
||||
std::intptr_t mObjPtrNum;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -48,10 +49,12 @@ namespace MultiArrayTools
|
|||
ContainerIndex& operator=(const ContainerIndex& in) = default;
|
||||
|
||||
template <class MRange>
|
||||
ContainerIndex(const std::shared_ptr<MRange>& range);
|
||||
ContainerIndex(const std::shared_ptr<MRange>& range,
|
||||
std::intptr_t objPtrNum);
|
||||
|
||||
template <class MRange>
|
||||
ContainerIndex(const std::shared_ptr<MRange>& range,
|
||||
std::intptr_t objPtrNum,
|
||||
const std::array<size_t,sizeof...(Indices)+1>& blockSizes);
|
||||
|
||||
template <size_t N>
|
||||
|
@ -104,6 +107,9 @@ namespace MultiArrayTools
|
|||
auto iforh(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
||||
|
||||
std::intptr_t container() const;
|
||||
ContainerIndex& format(const std::array<size_t,sizeof...(Indices)+1>& blocks);
|
||||
|
||||
// Iterator Stuff
|
||||
|
||||
ContainerIndex& setData(const T* data);
|
||||
|
@ -212,8 +218,10 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... Indices>
|
||||
template <class MRange>
|
||||
ContainerIndex<T,Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range) :
|
||||
IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
||||
ContainerIndex<T,Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range,
|
||||
std::intptr_t objPtrNum) :
|
||||
IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
|
||||
mObjPtrNum(objPtrNum)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
||||
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
||||
|
@ -224,8 +232,10 @@ namespace MultiArrayTools
|
|||
template <typename T, class... Indices>
|
||||
template <class MRange>
|
||||
ContainerIndex<T,Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range,
|
||||
std::intptr_t objPtrNum,
|
||||
const std::array<size_t,sizeof...(Indices)+1>& blockSizes) :
|
||||
IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
||||
IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
|
||||
mObjPtrNum(objPtrNum)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
||||
mBlockSizes = blockSizes;
|
||||
|
@ -421,6 +431,20 @@ namespace MultiArrayTools
|
|||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
||||
}
|
||||
|
||||
template <typename T, class... Indices>
|
||||
std::intptr_t ContainerIndex<T,Indices...>::container() const
|
||||
{
|
||||
return mObjPtrNum;
|
||||
}
|
||||
|
||||
template <typename T, class... Indices>
|
||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::
|
||||
format(const std::array<size_t,sizeof...(Indices)+1>& blocks)
|
||||
{
|
||||
mBlockSizes = blocks;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class... Indices>
|
||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::setData(const T* data)
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace MultiArrayTools
|
|||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
||||
typedef MultiRange<typename Indices::RangeType...> RangeType;
|
||||
typedef MultiIndex IType;
|
||||
|
||||
static constexpr IndexType sType() { return IndexType::MULTI; }
|
||||
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||
|
@ -143,7 +144,8 @@ namespace MultiArrayTools
|
|||
public:
|
||||
typedef RangeBase RB;
|
||||
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
|
||||
typedef MultiIndex<typename Ranges::IndexType...> IndexType;
|
||||
typedef MultiIndex<typename Ranges::IndexType...> IndexType;
|
||||
typedef MultiRange RangeType;
|
||||
//typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace MultiArrayTools
|
|||
public:
|
||||
typedef RangeBase RB;
|
||||
typedef typename RangeInterface<SingleIndex<size_t,SpaceType::NONE> >::IndexType IndexType;
|
||||
typedef SingleRange<size_t,SpaceType::NONE> RangeType;
|
||||
|
||||
virtual size_t size() const override;
|
||||
virtual size_t dim() const override;
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace MultiArrayTools
|
|||
public:
|
||||
typedef RangeBase RB;
|
||||
typedef typename RangeInterface<SingleIndex<size_t,SpaceType::SPIN> >::IndexType IndexType;
|
||||
typedef SingleRange<size_t,SpaceType::SPIN> RangeType;
|
||||
|
||||
virtual size_t size() const override;
|
||||
virtual size_t dim() const override;
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace MultiArrayTools
|
|||
typedef IndexInterface<SingleIndex<U,TYPE>,U> IB;
|
||||
typedef U MetaType;
|
||||
typedef SingleRange<U,TYPE> RangeType;
|
||||
typedef SingleIndex IType;
|
||||
|
||||
//DEFAULT_MEMBERS_X(SingleIndex);
|
||||
|
||||
|
@ -92,6 +93,7 @@ namespace MultiArrayTools
|
|||
public:
|
||||
typedef RangeBase RB;
|
||||
typedef SingleIndex<U,TYPE> IndexType;
|
||||
typedef SingleRange RangeType;
|
||||
//typedef typename RangeInterface<SingleIndex<U,TYPE> >::IndexType IndexType;
|
||||
|
||||
virtual size_t size() const override;
|
||||
|
|
|
@ -14,30 +14,30 @@ namespace MultiArrayTools
|
|||
|
||||
typedef ContainerRange<T,SRanges...> CRange;
|
||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
typedef typename CRange::IndexType IType;
|
||||
|
||||
DEFAULT_MEMBERS(Slice);
|
||||
|
||||
template <class... RITypes> // Range / Index <-> open / const
|
||||
Slice(T* data, const RITypes&... ris);
|
||||
// RITypes = Range XOR Index depending on whether const XOR opern
|
||||
template <class... RITypes>
|
||||
Slice(MutableMultiArrayBase<T,typename RITypes::RangeType...>& ma,
|
||||
const std::shared_ptr<RITypes>&... ris);
|
||||
|
||||
virtual const T& operator[](const IndexType& i) const override;
|
||||
virtual T& operator[](const IndexType& i) override;
|
||||
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const override;
|
||||
virtual T& at(const typename CRange::IndexType::MetaType& meta) override;
|
||||
virtual const T& operator[](const IType& i) const override;
|
||||
virtual T& operator[](const IType& i) override;
|
||||
virtual const T& at(const typename IType::MetaType& meta) const override;
|
||||
virtual T& at(const typename IType::MetaType& meta) override;
|
||||
|
||||
virtual const T* data() const override;
|
||||
virtual T* data() override;
|
||||
|
||||
virtual bool isSlice() const override;
|
||||
|
||||
virtual IndexType begin() const override;
|
||||
virtual IndexType end() const override;
|
||||
virtual auto begin() const -> IType override;
|
||||
virtual auto end() const -> IType override;
|
||||
|
||||
private:
|
||||
T* mData;
|
||||
size_t mStartPos;
|
||||
std::array<size_t,sizeof...(SRange)+1> mBlockSizes;
|
||||
};
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
|
@ -52,6 +52,17 @@ namespace MultiArrayTools
|
|||
namespace
|
||||
{
|
||||
|
||||
//size_t sum(size_t arg)
|
||||
//{
|
||||
// return arg;
|
||||
//}
|
||||
|
||||
template <typename... SizeTypes>
|
||||
size_t sum(size_t arg, SizeTypes... args)
|
||||
{
|
||||
return arg + sum(args...);
|
||||
}
|
||||
|
||||
template <bool ISINDEX>
|
||||
struct XX
|
||||
{
|
||||
|
@ -61,6 +72,12 @@ namespace MultiArrayTools
|
|||
{
|
||||
return std::make_tuple(ri);
|
||||
}
|
||||
|
||||
template <class RI>
|
||||
static size_t ri_to_start_pos(const std::shared_ptr<RI>& ri)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
|
@ -72,52 +89,69 @@ namespace MultiArrayTools
|
|||
{
|
||||
return std::make_tuple();
|
||||
}
|
||||
|
||||
template <class RI>
|
||||
static size_t ri_to_start_pos(const std::shared_ptr<RI>& ri)
|
||||
{
|
||||
return ri->pos();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <class... RITypes>
|
||||
auto mkSliceRange(const std::shared_ptr<RITypes>&... ris)
|
||||
-> decltype(std::tuple_cat(XX<RITypes::ISINDEX>::ri_to_tuple(ris)...))
|
||||
{
|
||||
return std::tuple_cat(XX<RITypes::ISINDEX>::ri_to_tuple(ris)...);
|
||||
}
|
||||
|
||||
template <class... RITypes>
|
||||
size_t mkStartPos(const std::shared_ptr<RITypes>&... ris)
|
||||
{
|
||||
return sum(ri_to_start_pos(ris)...);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*************
|
||||
* Slice *
|
||||
*************/
|
||||
/*
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
Slice<T,SRanges...>::Slice(T* data, const RITypes&... ris) :
|
||||
template <class... RITypes>
|
||||
Slice<T,SRanges...>::Slice(MutableMultiArrayBase<T,typename RITypes::RangeType...>& ma,
|
||||
const std::shared_ptr<RITypes>&... ris) :
|
||||
MutableMultiArrayBase<T,SRanges...>( mkSliceRange(ris...) ),
|
||||
mData(data),
|
||||
mStartPos(mkSliceStart(ris...)),
|
||||
mBlockSizes(mkSliceBlocks(ris...)) {}
|
||||
*/ //!!!!!
|
||||
mData(ma.data() + mkStartPos(ris...))
|
||||
{
|
||||
MAB::mProtoI.format( mBlockSizes(mkSliceBlocks(ris...)) );
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
const T& Slice<T,SRanges...>::operator[](const IndexType& i) const
|
||||
const T& Slice<T,SRanges...>::operator[](const IType& i) const
|
||||
{
|
||||
assert(i.sliceMode()); // -> compare objects !!!!!
|
||||
assert(i.container() == reinterpret_cast<std::intptr_t>(this));
|
||||
return mData[ i.pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
T& Slice<T,SRanges...>::operator[](const IndexType& i)
|
||||
T& Slice<T,SRanges...>::operator[](const IType& i)
|
||||
{
|
||||
assert(i.sliceMode());
|
||||
assert(i.container() == reinterpret_cast<std::intptr_t>(this));
|
||||
return mData[ i.pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
const T& Slice<T,SRanges...>::at(const typename CRange::IndexType::MetaType& meta) const
|
||||
const T& Slice<T,SRanges...>::at(const typename IType::MetaType& meta) const
|
||||
{
|
||||
assert(i.sliceMode());
|
||||
return mData[ begin().at(meta).pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
T& Slice<T,SRanges...>::at(const typename CRange::IndexType::MetaType& meta)
|
||||
T& Slice<T,SRanges...>::at(const typename IType::MetaType& meta)
|
||||
{
|
||||
assert(i.sliceMode());
|
||||
return mData[ begin().at(meta).pos() ];
|
||||
}
|
||||
|
||||
|
@ -140,18 +174,20 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
IndexType Slice<T,SRanges...>::begin() const
|
||||
auto Slice<T,SRanges...>::begin() const -> Slice<T,SRanges...>::IType
|
||||
{
|
||||
IndexType i(mRange, mBlockSizes);
|
||||
i = mStartPos;
|
||||
IType i = MAB::mProtoI;
|
||||
i = 0;
|
||||
//i = mStartPos;
|
||||
return i.setData(data());
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
IndexType Slice<T,SRanges...>::end() const
|
||||
auto Slice<T,SRanges...>::end() const -> Slice<T,SRanges...>::IType
|
||||
{
|
||||
IndexType i(mRange, mBlockSizes);
|
||||
i = std::get<sizeof...(SRanges)>(mBlockSizes);
|
||||
IType i = MAB::mProtoI;
|
||||
i = i.max(); // CHECK !!!
|
||||
//i = std::get<sizeof...(SRanges)>(mBlockSizes);
|
||||
return i.setData(data());
|
||||
}
|
||||
|
||||
|
|
|
@ -184,10 +184,10 @@ namespace {
|
|||
|
||||
auto mi = mstrptr->begin();
|
||||
//auto ci1 = cr1ptr->begin();
|
||||
CIndex ci1(cr1ptr);
|
||||
CIndex ci1(cr1ptr, 0);
|
||||
ci1 = 0;
|
||||
//auto ci2 = cr2ptr->begin();
|
||||
CIndex ci2(cr2ptr);
|
||||
CIndex ci2(cr2ptr, 0);
|
||||
ci2 = 0;
|
||||
|
||||
EXPECT_EQ(ci1.max(), 16u);
|
||||
|
|
Loading…
Reference in a new issue