continue...

This commit is contained in:
Christian Zimmermann 2021-05-12 17:56:35 +02:00
parent 43e8486354
commit 29f4ddc0cd
7 changed files with 81 additions and 132 deletions

View file

@ -187,7 +187,7 @@ namespace MultiArrayTools
sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(indices); return 0; } );
//RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, IB::mPos);
return *this;
}

View file

@ -68,7 +68,14 @@ namespace MultiArrayTools
mCPos(in.mCPos),
mObjPtrNum(in.mObjPtrNum)
{
RPackNum<sizeof...(Indices)-1>::copyIndex(mIPack, in);
sfor_pn<0,sizeof...(Indices)>
( [&](auto i)
{
typedef typename std::remove_reference<decltype(*std::get<i>(mIPack))>::type
SubType;
std::get<i>(mIPack) = std::make_shared<SubType>( in.template get<i>() ) ;
return true;
});
}
ContainerIndex& copy(const ContainerIndex& in)
@ -80,7 +87,14 @@ namespace MultiArrayTools
mData = in.mData;
mCPos = in.mCPos;
mObjPtrNum = in.mObjPtrNum;
RPackNum<sizeof...(Indices)-1>::copyIndex(mIPack, in);
sfor_pn<0,sizeof...(Indices)>
( [&](auto i)
{
typedef typename std::remove_reference<decltype(*std::get<i>(mIPack))>::type
SubType;
std::get<i>(mIPack) = std::make_shared<SubType>( in.template get<i>() ) ;
return true;
});
return *this;
}
@ -354,7 +368,7 @@ namespace MultiArrayTools
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator=(size_t pos)
{
IB::mPos = pos;
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, pos);
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
return *this;
}

View file

@ -13,6 +13,7 @@
#include "ranges/index_base.h"
#include "ranges/rpack_num.h"
#include "ranges/range_helper.h"
#include "ranges/multi_range_factory_product_map.h"
#include "ranges/x_to_string.h"
#include "ranges/type_map.h"
@ -337,7 +338,7 @@ namespace MultiArrayTools
{
sfor_pn<0,sizeof...(Indices)>
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(indices); return 0; } );
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, IB::mPos);
return *this;
}
@ -351,7 +352,7 @@ namespace MultiArrayTools
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
{
IB::mPos = pos;
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, pos);
return *this;
}
@ -576,7 +577,11 @@ namespace MultiArrayTools
template <class... Indices>
std::shared_ptr<RangeBase> MultiRange<Indices...>::sub(size_t num) const
{
return RPackNum<sizeof...(Indices)-1>::getSub(mSpace, num);
assert(num < sizeof...(Indices));
return sforx_p<0,sizeof...(Indices)>
( [&](auto i) { return std::dynamic_pointer_cast<RangeBase>(std::get<i>(mSpace)); },
[&](auto i) { return num != i;} );
//return RPackNum<sizeof...(Indices)-1>::getSub(mSpace, num);
}
template <class... Ranges>

View file

@ -0,0 +1,23 @@
#ifndef __range_helper_h__
#define __range_helper_h__
namespace MultiArrayTools
{
namespace RangeHelper
{
template <size_t N, class IndexPack>
void setIndexPack(IndexPack& iPack, size_t pos)
{
auto& i = *std::get<N>(iPack).get();
const size_t ownPos = pos % i.max();
i = ownPos;
if constexpr(N != 0){
setIndexPack<N-1>(iPack, (pos - ownPos) / i.max() );
}
}
} // namespace RangeHelper
} // namespace MultiArrayTools
#endif

View file

@ -40,47 +40,6 @@ namespace MultiArrayHelper
return std::get<N>(rt)->size() * RPackNum<N-1>::getSize(rt);
}
template <size_t N>
template <class SpaceClass>
inline std::shared_ptr<RangeBase> RPackNum<N>::getSub(const SpaceClass& space, size_t num)
{
if(num == N){
return std::get<N>(space);
}
else {
return RPackNum<N-1>::getSub(space, num);
}
}
template <size_t N>
template <class IndexPack>
void RPackNum<N>::setIndexPack(IndexPack& iPack, size_t pos)
{
auto& i = *std::get<N>(iPack).get();
const size_t ownPos = pos % i.max();
i = ownPos;
RPackNum<N-1>::setIndexPack(iPack, (pos - ownPos) / i.max() );
}
template <size_t N>
template <class IndexType, class... Indices>
void RPackNum<N>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind)
{
std::get<N>(ip) = ind.template getPtr<N>() ;
RPackNum<N-1>::copyInst(ip, ind);
}
template <size_t N>
template <class IndexType, class... Indices>
void RPackNum<N>::copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind)
{
typedef typename std::remove_reference<decltype(*std::get<N>(ip))>::type SubType;
std::get<N>(ip) = std::make_shared<SubType>( ind.template get<N>() ) ;
RPackNum<N-1>::copyIndex(ip, ind);
}
template <size_t N>
template <class... Indices>
inline size_t RPackNum<N>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
@ -132,14 +91,6 @@ namespace MultiArrayHelper
RPackNum<N-1>::RangesToVec(rst, v);
}
template <size_t N>
template <class Range, class... Ranges>
void RPackNum<N>::checkDefaultable()
{
static_assert( Range::defaultable, "not defaultable" );
RPackNum<N-1>::template checkDefaultable<Ranges...>();
}
template <size_t N>
template <class IndexPack, class BlockArray, class Exprs>
auto RPackNum<N>::mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
@ -291,41 +242,6 @@ namespace MultiArrayHelper
return std::get<0>(rt)->size();
}
template <class SpaceClass>
inline std::shared_ptr<RangeBase> RPackNum<0>::getSub(const SpaceClass& space, size_t num)
{
if(num == 0){
return std::get<0>(space);
}
else {
assert(0);
return std::shared_ptr<RangeBase>();
}
}
template <class IndexPack>
void RPackNum<0>::setIndexPack(IndexPack& iPack, size_t pos)
{
auto& i = *std::get<0>(iPack);
const size_t ownPos = pos % i.max();
i = ownPos;
}
template <class IndexType, class... Indices>
void RPackNum<0>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind)
{
std::get<0>(ip) = ind.template getPtr<0>();
}
template <class IndexType, class... Indices>
void RPackNum<0>::copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind)
{
typedef typename std::remove_reference<decltype(*std::get<0>(ip))>::type SubType;
std::get<0>(ip) = std::make_shared<SubType>( ind.template get<0>() ) ;
}
template <class... Indices>
inline size_t RPackNum<0>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
@ -365,12 +281,6 @@ namespace MultiArrayHelper
setRangeToVec(v, std::get<0>(rst));
}
template <class Range>
void RPackNum<0>::checkDefaultable()
{
static_assert( Range::defaultable, "not defaultable" );
}
template <class IndexPack, class BlockArray, class Exprs>
auto RPackNum<0>::mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)

View file

@ -105,20 +105,6 @@ namespace MultiArrayHelper
template <class RangeTuple>
static size_t getSize(const RangeTuple& rt);
template <class SpaceClass>
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num);
template <class IndexPack>
static void setIndexPack(IndexPack& iPack, size_t pos);
template <class IndexType, class... Indices>
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind);
template <class IndexType, class... Indices>
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind);
template <class... Indices>
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
const std::array<size_t,sizeof...(Indices)+1>& blockSize);
@ -142,9 +128,6 @@ namespace MultiArrayHelper
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
vector<std::intptr_t>& v);
template <class Range, class... Ranges>
static void checkDefaultable();
template <class IndexPack, class BlockArray, class Exprs>
static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
@ -208,20 +191,6 @@ namespace MultiArrayHelper
template <class RangeTuple>
static size_t getSize(const RangeTuple& rt);
template <class SpaceClass>
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num);
template <class IndexPack>
static void setIndexPack(IndexPack& iPack, size_t pos);
template <class IndexType, class... Indices>
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind);
template <class IndexType, class... Indices>
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType& ind);
template <class... Indices>
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
const std::array<size_t,sizeof...(Indices)+1>& blockSize);
@ -243,9 +212,6 @@ namespace MultiArrayHelper
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
vector<std::shared_ptr<RangeBase> >& v);
template <class Range>
static void checkDefaultable();
template <class IndexPack, class BlockArray, class Exprs>
static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)

View file

@ -19,7 +19,26 @@ namespace MultiArrayTools
}
}
}
template <size_t BEG, size_t END, int OFF, typename Incr, typename F, typename Cond>
inline auto sforx(Incr incr, F f, Cond cond)
{
constexpr auto idx = std::integral_constant<size_t, BEG>{};
constexpr auto idxm = std::integral_constant<size_t, BEG+OFF>{};
if constexpr(incr(idx) != END){
if(cond(idx)){
return sforx<incr(idx),END,OFF>(incr,f,cond);
}
else {
return f(idxm);
}
}
else {
return f(idxm);
}
}
template <size_t BEG, size_t END, int OFF, typename Incr, typename F, typename Conc>
inline auto sfor(Incr incr, F f, Conc conc)
{
@ -88,6 +107,18 @@ namespace MultiArrayTools
return sfor<BEG,END,-1>(MA_DEC,f);
}
template <size_t BEG, size_t END, typename F, typename Cond>
inline auto sforx_p(F f, Cond cond)
{
return sforx<BEG,END,0>(MA_INC,f,cond);
}
template <size_t BEG, size_t END, typename F, typename Cond>
inline auto sforx_m(F f, Cond cond)
{
return sforx<BEG,END,-1>(MA_DEC,f,cond);
}
template <size_t BEG, size_t END, typename F, typename Conc>
inline auto sfor_p(F f, Conc conc)
{