use step size in for target -> re-ordered operations on slice should be possible now
This commit is contained in:
parent
3fd74cfc4c
commit
174cdd4bf6
7 changed files with 82 additions and 62 deletions
|
@ -49,6 +49,7 @@ namespace MultiArrayTools
|
|||
const OIType* mIndPtr;
|
||||
size_t mSPos;
|
||||
size_t mMax;
|
||||
size_t mStep;
|
||||
Expr mExpr;
|
||||
|
||||
typedef decltype(mkMapOp(std::declval<MapF>(), std::declval<IndexPack>())) Op;
|
||||
|
@ -63,7 +64,7 @@ namespace MultiArrayTools
|
|||
OpExpr& operator=(const OpExpr& in) = default;
|
||||
OpExpr& operator=(OpExpr&& in) = default;
|
||||
|
||||
OpExpr(const MapF& mapf, const IndexPack& ipack, const std::shared_ptr<OIType> oind, Expr ex);
|
||||
OpExpr(const MapF& mapf, const IndexPack& ipack, const std::shared_ptr<OIType> oind, size_t step, Expr ex);
|
||||
|
||||
inline void operator()(size_t mlast, ExtType last) const;
|
||||
inline void operator()(size_t mlast = 0) const;
|
||||
|
@ -165,10 +166,11 @@ namespace MultiArrayTools
|
|||
void print(size_t offset) const;
|
||||
|
||||
template <class Exprs>
|
||||
auto ifor(Exprs exs) const
|
||||
auto ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
|
||||
(mIPack, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, exs ) ) );
|
||||
|
||||
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, step, exs ) ) );
|
||||
// first step arg not used!
|
||||
|
||||
/*
|
||||
template <class Exprs>
|
||||
auto iforh(Exprs exs) const
|
||||
|
@ -300,8 +302,8 @@ namespace MultiArrayTools
|
|||
|
||||
template <class MapF, class IndexPack, class Expr>
|
||||
OpExpr<MapF,IndexPack,Expr>::OpExpr(const MapF& mapf, const IndexPack& ipack,
|
||||
const std::shared_ptr<OIType> oind, Expr ex) :
|
||||
mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(ex),
|
||||
const std::shared_ptr<OIType> oind, size_t step, Expr ex) :
|
||||
mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step), mExpr(ex),
|
||||
mOp(mkMapOp(mapf, ipack)),
|
||||
//mExt(ex.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||
mExt( mOp.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr) ).extend
|
||||
|
@ -559,12 +561,12 @@ namespace MultiArrayTools
|
|||
|
||||
template <class MapF, class... Indices>
|
||||
template <class Exprs>
|
||||
auto MapIndex<MapF,Indices...>::ifor(Exprs exs) const
|
||||
auto MapIndex<MapF,Indices...>::ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
|
||||
(mIPack, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, exs ) ) )
|
||||
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, step, exs ) ) )
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkForh
|
||||
(mIPack, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, exs ) );
|
||||
(step, mIPack, mBlockSizes, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, step, exs ) );
|
||||
}
|
||||
/*
|
||||
template <class MapF, class... Indices>
|
||||
|
|
|
@ -462,7 +462,7 @@ namespace MultiArrayTools
|
|||
-> decltype(mOp.rootSteps(iPtrNum));
|
||||
|
||||
template <class Expr>
|
||||
auto loop(Expr exp) const -> decltype(mInd->iforh(exp));
|
||||
auto loop(Expr exp) const -> decltype(mInd->iforh(1,exp));
|
||||
};
|
||||
|
||||
template <typename T, class Op, class... Indices>
|
||||
|
@ -632,7 +632,7 @@ namespace MultiArrayTools
|
|||
void OperationMaster<T,OpClass,Ranges...>::performAssignment(std::intptr_t blockIndexNum)
|
||||
{
|
||||
AssignmentExpr ae(*this, mSecond); // Expression to be executed within loop
|
||||
const auto loop = mSecond.template loop<decltype(mIndex.ifor(ae))>( mIndex.ifor(ae) );
|
||||
const auto loop = mSecond.template loop<decltype(mIndex.ifor(1,ae))>( mIndex.ifor(1,ae) );
|
||||
// hidden Loops outside ! -> auto vectorizable
|
||||
loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions
|
||||
}
|
||||
|
@ -989,9 +989,9 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class Op, class IndexType>
|
||||
template <class Expr>
|
||||
auto Contraction<T,Op,IndexType>::loop(Expr exp) const -> decltype(mInd->iforh(exp))
|
||||
auto Contraction<T,Op,IndexType>::loop(Expr exp) const -> decltype(mInd->iforh(1,exp))
|
||||
{
|
||||
return mInd->iforh(exp);
|
||||
return mInd->iforh(1,exp);
|
||||
}
|
||||
|
||||
/**************************
|
||||
|
|
|
@ -107,12 +107,12 @@ namespace MultiArrayTools
|
|||
void print(size_t offset);
|
||||
|
||||
template <class Exprs>
|
||||
auto ifor(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs));
|
||||
auto ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
template <class Exprs>
|
||||
auto iforh(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
||||
auto iforh(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
std::intptr_t container() const;
|
||||
ContainerIndex& format(const std::array<size_t,sizeof...(Indices)+1>& blocks);
|
||||
|
@ -433,18 +433,18 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... Indices>
|
||||
template <class Exprs>
|
||||
auto ContainerIndex<T,Indices...>::ifor(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs))
|
||||
auto ContainerIndex<T,Indices...>::ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs);
|
||||
return RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
||||
template <typename T, class... Indices>
|
||||
template <class Exprs>
|
||||
auto ContainerIndex<T,Indices...>::iforh(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
||||
auto ContainerIndex<T,Indices...>::iforh(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
||||
return RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
||||
template <typename T, class... Indices>
|
||||
|
|
|
@ -115,12 +115,12 @@ namespace MultiArrayTools
|
|||
void print(size_t offset);
|
||||
|
||||
template <class Exprs>
|
||||
auto ifor(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs));
|
||||
auto ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
template <class Exprs>
|
||||
auto iforh(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
||||
auto iforh(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
};
|
||||
|
||||
|
@ -440,18 +440,18 @@ namespace MultiArrayTools
|
|||
|
||||
template <class... Indices>
|
||||
template <class Exprs>
|
||||
auto MultiIndex<Indices...>::ifor(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs))
|
||||
auto MultiIndex<Indices...>::ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs);
|
||||
return RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <class Exprs>
|
||||
auto MultiIndex<Indices...>::iforh(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
||||
auto MultiIndex<Indices...>::iforh(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs))
|
||||
{
|
||||
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
||||
return RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
||||
/*************************
|
||||
|
|
|
@ -251,22 +251,24 @@ namespace MultiArrayHelper
|
|||
RPackNum<N-1>::template checkDefaultable<Ranges...>();
|
||||
}
|
||||
|
||||
template <class IndexPack, class Exprs>
|
||||
static auto mkFor(const IndexPack& ipack, Exprs exs)
|
||||
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)
|
||||
->ifor( RPackNum<N-1>::mkFor(ipack, exs) ) )
|
||||
->ifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) )
|
||||
{
|
||||
return std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||
->ifor( RPackNum<N-1>::mkFor(ipack, exs) );
|
||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
||||
return std::get<NN>(ipack)
|
||||
->ifor( step*std::get<NN+1>(ba), RPackNum<N-1>::mkFor(step, ipack, ba, exs) );
|
||||
}
|
||||
|
||||
template <class IndexPack, class Exprs>
|
||||
static auto mkForh(const IndexPack& ipack, Exprs exs)
|
||||
template <class IndexPack, class BlockArray, class Exprs>
|
||||
static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||
->iforh( RPackNum<N-1>::mkForh(ipack, exs) ) )
|
||||
->iforh( 0, RPackNum<N-1>::mkForh(step, ipack, ba, exs) ) )
|
||||
{
|
||||
return std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||
->iforh( RPackNum<N-1>::mkForh(ipack, exs) );
|
||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
||||
return std::get<NN>(ipack)
|
||||
->iforh( step*std::get<NN+1>(ba), RPackNum<N-1>::mkForh(step, ipack, ba, exs) );
|
||||
}
|
||||
|
||||
template <class Index>
|
||||
|
@ -485,20 +487,24 @@ namespace MultiArrayHelper
|
|||
static_assert( Range::defaultable, "not defaultable" );
|
||||
}
|
||||
|
||||
template <class IndexPack, class Exprs>
|
||||
static auto mkFor(const IndexPack& ipack, Exprs exs)
|
||||
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)
|
||||
->ifor(exs) )
|
||||
->ifor(0,exs) )
|
||||
{
|
||||
return std::get<std::tuple_size<IndexPack>::value-1>(ipack)->ifor(exs);
|
||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
||||
return std::get<NN>(ipack)
|
||||
->ifor( step*std::get<NN+1>(ba), exs);
|
||||
}
|
||||
|
||||
template <class IndexPack, class Exprs>
|
||||
static auto mkForh(const IndexPack& ipack, Exprs exs)
|
||||
template <class IndexPack, class BlockArray, class Exprs>
|
||||
static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||
->iforh(exs) )
|
||||
->iforh(0,exs) )
|
||||
{
|
||||
return std::get<std::tuple_size<IndexPack>::value-1>(ipack)->iforh(exs);
|
||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
||||
return std::get<NN>(ipack)
|
||||
->iforh( step*std::get<NN+1>(ba), exs);
|
||||
}
|
||||
|
||||
template <class Index>
|
||||
|
|
|
@ -80,11 +80,11 @@ namespace MultiArrayTools
|
|||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
auto ifor(Expr ex) const
|
||||
auto ifor(size_t step, Expr ex) const
|
||||
-> For<SingleIndex<U,TYPE>,Expr>;
|
||||
|
||||
template <class Expr>
|
||||
auto iforh(Expr ex) const
|
||||
auto iforh(size_t step, Expr ex) const
|
||||
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>;
|
||||
|
||||
private:
|
||||
|
@ -324,20 +324,20 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename U, SpaceType TYPE>
|
||||
template <class Expr>
|
||||
auto SingleIndex<U,TYPE>::ifor(Expr ex) const
|
||||
auto SingleIndex<U,TYPE>::ifor(size_t step, Expr ex) const
|
||||
-> For<SingleIndex<U,TYPE>,Expr>
|
||||
{
|
||||
//static const size_t LAYER = typename Expr::LAYER;
|
||||
return For<SingleIndex<U,TYPE>,Expr>(this, ex);
|
||||
return For<SingleIndex<U,TYPE>,Expr>(this, step, ex);
|
||||
}
|
||||
|
||||
template <typename U, SpaceType TYPE>
|
||||
template <class Expr>
|
||||
auto SingleIndex<U,TYPE>::iforh(Expr ex) const
|
||||
auto SingleIndex<U,TYPE>::iforh(size_t step, Expr ex) const
|
||||
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>
|
||||
{
|
||||
//static const size_t LAYER = typename Expr::LAYER;
|
||||
return For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>(this, ex);
|
||||
return For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>(this, step, ex);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,11 @@ namespace MultiArrayHelper
|
|||
template <ForType FT = ForType::DEFAULT>
|
||||
struct PosForward
|
||||
{
|
||||
static inline size_t valuex(size_t last, size_t step, size_t pos)
|
||||
{
|
||||
return last + pos * step;
|
||||
}
|
||||
|
||||
static inline size_t value(size_t last, size_t max, size_t pos)
|
||||
{
|
||||
return last * max + pos;
|
||||
|
@ -27,6 +32,11 @@ namespace MultiArrayHelper
|
|||
template <>
|
||||
struct PosForward<ForType::HIDDEN>
|
||||
{
|
||||
static inline size_t valuex(size_t last, size_t step, size_t pos)
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
static inline size_t value(size_t last, size_t max, size_t pos)
|
||||
{
|
||||
return last;
|
||||
|
@ -102,6 +112,7 @@ namespace MultiArrayHelper
|
|||
const IndexClass* mIndPtr;
|
||||
size_t mSPos;
|
||||
size_t mMax;
|
||||
size_t mStep;
|
||||
Expr mExpr;
|
||||
|
||||
typedef decltype(mExpr.rootSteps()) ExtType;
|
||||
|
@ -118,10 +129,10 @@ namespace MultiArrayHelper
|
|||
For& operator=(For&& in) = default;
|
||||
|
||||
For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
Expr expr);
|
||||
size_t step, Expr expr);
|
||||
|
||||
For(const IndexClass* indPtr,
|
||||
Expr expr);
|
||||
size_t step, Expr expr);
|
||||
|
||||
|
||||
inline void operator()(size_t mlast, ExtType last) const;
|
||||
|
@ -150,8 +161,8 @@ namespace MultiArrayHelper
|
|||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
For<IndexClass,Expr,FT>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
Expr expr) :
|
||||
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr),
|
||||
size_t step, Expr expr) :
|
||||
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step), mExpr(expr),
|
||||
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr.get() )))
|
||||
{
|
||||
assert(mIndPtr != nullptr);
|
||||
|
@ -161,8 +172,9 @@ namespace MultiArrayHelper
|
|||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
For<IndexClass,Expr,FT>::For(const IndexClass* indPtr,
|
||||
Expr expr) :
|
||||
size_t step, Expr expr) :
|
||||
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
|
||||
mStep(step),
|
||||
mExpr(std::forward<Expr>( expr )),
|
||||
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ) ))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue