+exttype (xfor_devel) ; remove references ; TODO : rootSteps problem
This commit is contained in:
parent
5c96e47f69
commit
203db8253a
8 changed files with 240 additions and 131 deletions
|
@ -95,19 +95,20 @@ namespace MultiArrayTools
|
||||||
public:
|
public:
|
||||||
static size_t layer() { return 0; }
|
static size_t layer() { return 0; }
|
||||||
|
|
||||||
static const size_t LAYER = 0;
|
static constexpr size_t LAYER = 0;
|
||||||
static const size_t SIZE = OpClass::SIZE;
|
static constexpr size_t SIZE = OpClass::SIZE;
|
||||||
typedef decltype(mSec.rootSteps()) ETuple;
|
typedef decltype(mSec.rootSteps()) ExtType;
|
||||||
|
|
||||||
AssignmentExpr(OperationMaster& m, const OpClass& sec);
|
AssignmentExpr(OperationMaster& m, const OpClass& sec);
|
||||||
|
|
||||||
|
AssignmentExpr(const AssignmentExpr& in) = default;
|
||||||
AssignmentExpr(AssignmentExpr&& in) = default;
|
AssignmentExpr(AssignmentExpr&& in) = default;
|
||||||
//AssignmentExpr& operator=(const AssignmentExpr&& in) = default;
|
//AssignmentExpr& operator=(const AssignmentExpr&& in) = default;
|
||||||
|
|
||||||
//inline void operator()(size_t start = 0);
|
inline void operator()(size_t start = 0);
|
||||||
inline void operator()(size_t start, const ETuple& last);
|
inline void operator()(size_t start, ExtType last);
|
||||||
|
|
||||||
ETuple rootSteps(std::intptr_t iPtrNum = 0);
|
auto rootSteps(std::intptr_t iPtrNum = 0) -> ExtType;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -178,7 +179,7 @@ namespace MultiArrayTools
|
||||||
std::tuple<size_t> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
|
std::tuple<size_t> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
Expr&& loop(Expr&& exp) const;
|
Expr loop(Expr exp) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -230,7 +231,7 @@ namespace MultiArrayTools
|
||||||
std::tuple<size_t> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
|
std::tuple<size_t> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
Expr&& loop(Expr&& exp) const;
|
Expr loop(Expr exp) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -322,8 +323,8 @@ namespace MultiArrayTools
|
||||||
-> decltype(PackNum<sizeof...(Ops)-1>::mkStepTuple(iPtrNum, mOps));
|
-> decltype(PackNum<sizeof...(Ops)-1>::mkStepTuple(iPtrNum, mOps));
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto loop(Expr&& exp) const
|
auto loop(Expr exp) const
|
||||||
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, std::forward<Expr>( exp ) ))&&;
|
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -488,13 +489,13 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class OpClass, class... Ranges>
|
template <typename T, class OpClass, class... Ranges>
|
||||||
inline void OperationMaster<T,OpClass,Ranges...>::AssignmentExpr::
|
inline void OperationMaster<T,OpClass,Ranges...>::AssignmentExpr::
|
||||||
operator()(size_t start, const ETuple& last)
|
operator()(size_t start, ExtType last)
|
||||||
{
|
{
|
||||||
mM.get(start) = mSec.template get<ETuple,OpClass::SIZE-1>(last);
|
mM.get(start) = mSec.template get<ExtType,OpClass::SIZE-1>(last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class OpClass, class... Ranges>
|
template <typename T, class OpClass, class... Ranges>
|
||||||
typename OperationMaster<T,OpClass,Ranges...>::AssignmentExpr::ETuple
|
typename OperationMaster<T,OpClass,Ranges...>::AssignmentExpr::ExtType
|
||||||
OperationMaster<T,OpClass,Ranges...>::AssignmentExpr::
|
OperationMaster<T,OpClass,Ranges...>::AssignmentExpr::
|
||||||
rootSteps(std::intptr_t iPtrNum)
|
rootSteps(std::intptr_t iPtrNum)
|
||||||
{
|
{
|
||||||
|
@ -681,9 +682,9 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
Expr&& ConstOperationRoot<T,Ranges...>::loop(Expr&& exp) const
|
Expr ConstOperationRoot<T,Ranges...>::loop(Expr exp) const
|
||||||
{
|
{
|
||||||
return std::forward<Expr>(exp);
|
return exp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
|
@ -784,9 +785,9 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
Expr&& OperationRoot<T,Ranges...>::loop(Expr&& exp) const
|
Expr OperationRoot<T,Ranges...>::loop(Expr exp) const
|
||||||
{
|
{
|
||||||
return std::forward<Expr>(exp);
|
return exp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
|
@ -842,13 +843,10 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto Operation<T,OpFunction,Ops...>::loop(Expr&& exp) const
|
auto Operation<T,OpFunction,Ops...>::loop(Expr exp) const
|
||||||
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, std::forward<Expr>( exp ) ))&&
|
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp ))
|
||||||
{
|
{
|
||||||
typedef decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, std::forward<Expr>( exp ) ) )
|
return PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp );
|
||||||
LType;
|
|
||||||
return std::forward<LType>
|
|
||||||
( PackNum<sizeof...(Ops)-1>::mkLoop( mOps, std::forward<Expr>( exp ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -904,11 +902,9 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class Op, class IndexType>
|
template <typename T, class Op, class IndexType>
|
||||||
template <class Expr>
|
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(exp))
|
||||||
{
|
{
|
||||||
typedef decltype(mInd->iforh(exp)) LType;
|
return mInd->iforh(exp);
|
||||||
LType&& loop = mInd->iforh(exp);
|
|
||||||
return std::forward<LType>( loop );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,11 +90,11 @@ namespace MultiArrayTools
|
||||||
void print(size_t offset);
|
void print(size_t offset);
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto ifor(Exprs&& exs) const
|
auto ifor(Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs));
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs));
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto iforh(Exprs&& exs) const
|
auto iforh(Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -377,7 +377,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto ContainerIndex<Indices...>::ifor(Exprs&& exs) const
|
auto ContainerIndex<Indices...>::ifor(Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs))
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs))
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs);
|
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs);
|
||||||
|
@ -385,7 +385,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto ContainerIndex<Indices...>::iforh(Exprs&& exs) const
|
auto ContainerIndex<Indices...>::iforh(Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
||||||
|
|
|
@ -106,11 +106,11 @@ namespace MultiArrayTools
|
||||||
void print(size_t offset);
|
void print(size_t offset);
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto ifor(Exprs&& exs) const
|
auto ifor(Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs));
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs));
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto iforh(Exprs&& exs) const
|
auto iforh(Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -422,7 +422,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto MultiIndex<Indices...>::ifor(Exprs&& exs) const
|
auto MultiIndex<Indices...>::ifor(Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs))
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs))
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs);
|
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs);
|
||||||
|
@ -430,7 +430,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto MultiIndex<Indices...>::iforh(Exprs&& exs) const
|
auto MultiIndex<Indices...>::iforh(Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs))
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
return RPackNum<sizeof...(Indices)-1>::mkForh(mIPack, exs);
|
||||||
|
|
|
@ -234,7 +234,7 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexPack, class Exprs>
|
template <class IndexPack, class Exprs>
|
||||||
static auto mkFor(const IndexPack& ipack, Exprs&& exs)
|
static auto mkFor(const IndexPack& ipack, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||||
->ifor( RPackNum<N-1>::mkFor(ipack, exs) ) )
|
->ifor( RPackNum<N-1>::mkFor(ipack, exs) ) )
|
||||||
{
|
{
|
||||||
|
@ -243,7 +243,7 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexPack, class Exprs>
|
template <class IndexPack, class Exprs>
|
||||||
static auto mkForh(const IndexPack& ipack, Exprs&& exs)
|
static auto mkForh(const IndexPack& ipack, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
||||||
->iforh( RPackNum<N-1>::mkForh(ipack, exs) ) )
|
->iforh( RPackNum<N-1>::mkForh(ipack, exs) ) )
|
||||||
{
|
{
|
||||||
|
@ -415,7 +415,7 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexPack, class Exprs>
|
template <class IndexPack, class Exprs>
|
||||||
static auto mkFor(const IndexPack& ipack, Exprs&& exs)
|
static auto mkFor(const IndexPack& ipack, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||||
->ifor(exs) )
|
->ifor(exs) )
|
||||||
{
|
{
|
||||||
|
@ -423,7 +423,7 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexPack, class Exprs>
|
template <class IndexPack, class Exprs>
|
||||||
static auto mkForh(const IndexPack& ipack, Exprs&& exs)
|
static auto mkForh(const IndexPack& ipack, Exprs exs)
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
||||||
->iforh(exs) )
|
->iforh(exs) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,11 +66,11 @@ namespace MultiArrayTools
|
||||||
void print(size_t offset);
|
void print(size_t offset);
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto ifor(Expr&& ex) const
|
auto ifor(Expr ex) const
|
||||||
-> For<SingleIndex<U,TYPE>,Expr>;
|
-> For<SingleIndex<U,TYPE>,Expr>;
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto iforh(Expr&& ex) const
|
auto iforh(Expr ex) const
|
||||||
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>;
|
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -108,7 +108,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
friend SingleRangeFactory<U,TYPE>;
|
friend SingleRangeFactory<U,TYPE>;
|
||||||
|
|
||||||
static const bool defaultable = false;
|
static constexpr bool defaultable = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -255,20 +255,20 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename U, SpaceType TYPE>
|
template <typename U, SpaceType TYPE>
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto SingleIndex<U,TYPE>::ifor(Expr&& ex) const
|
auto SingleIndex<U,TYPE>::ifor(Expr ex) const
|
||||||
-> For<SingleIndex<U,TYPE>,Expr>
|
-> For<SingleIndex<U,TYPE>,Expr>
|
||||||
{
|
{
|
||||||
//static const size_t LAYER = typename Expr::LAYER;
|
//static const size_t LAYER = typename Expr::LAYER;
|
||||||
return For<SingleIndex<U,TYPE>,Expr>(this, std::forward<Expr>( ex ));
|
return For<SingleIndex<U,TYPE>,Expr>(this, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, SpaceType TYPE>
|
template <typename U, SpaceType TYPE>
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto SingleIndex<U,TYPE>::iforh(Expr&& ex) const
|
auto SingleIndex<U,TYPE>::iforh(Expr ex) const
|
||||||
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>
|
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>
|
||||||
{
|
{
|
||||||
//static const size_t LAYER = typename Expr::LAYER;
|
//static const size_t LAYER = typename Expr::LAYER;
|
||||||
return For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>(this, std::forward<Expr>( ex ));
|
return For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>(this, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
178
src/xfor/exttype.h
Normal file
178
src/xfor/exttype.h
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
|
||||||
|
#ifndef __exttype_h__
|
||||||
|
#define __exttype_h__
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
namespace XFOR
|
||||||
|
{
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
class MExt
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
size_t mExt = 0u;
|
||||||
|
X mNext;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static constexpr size_t NUM = X::NUM + 1;
|
||||||
|
|
||||||
|
MExt() = default;
|
||||||
|
MExt(const MExt& in) = default;
|
||||||
|
MExt& operator=(const MExt& in) = default;
|
||||||
|
MExt(MExt&& in) = default;
|
||||||
|
MExt& operator=(MExt&& in) = default;
|
||||||
|
|
||||||
|
inline MExt(size_t ext, X next);
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
inline MExt(const std::array<size_t,N>& arr);
|
||||||
|
|
||||||
|
inline size_t val() const;
|
||||||
|
inline const X& next() const;
|
||||||
|
|
||||||
|
inline MExt operator+(const MExt& in) const;
|
||||||
|
inline MExt operator*(size_t in) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class MExt<void>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
size_t mExt = 0u;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static constexpr size_t NUM = 0;
|
||||||
|
|
||||||
|
MExt() = default;
|
||||||
|
MExt(const MExt& in) = default;
|
||||||
|
MExt& operator=(const MExt& in) = default;
|
||||||
|
MExt(MExt&& in) = default;
|
||||||
|
MExt& operator=(MExt&& in) = default;
|
||||||
|
|
||||||
|
inline MExt(size_t ext);
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
inline MExt(const std::array<size_t,N>& arr);
|
||||||
|
|
||||||
|
inline size_t val() const;
|
||||||
|
|
||||||
|
inline MExt operator+(const MExt& in) const;
|
||||||
|
inline MExt operator*(size_t in) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
struct Getter
|
||||||
|
{
|
||||||
|
template <class ExtType>
|
||||||
|
static inline size_t get(const ExtType& et)
|
||||||
|
{
|
||||||
|
return Getter<I-1>::get(et.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ExtType>
|
||||||
|
static inline auto getX(const ExtType& et)
|
||||||
|
-> decltype(Getter<I-1>::get(et.next()))
|
||||||
|
{
|
||||||
|
return Getter<I-1>::getX(et.next());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Getter<0>
|
||||||
|
{
|
||||||
|
template <class ExtType>
|
||||||
|
static inline size_t get(const ExtType& et)
|
||||||
|
{
|
||||||
|
return et.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ExtType>
|
||||||
|
static inline auto getX(const ExtType& et)
|
||||||
|
-> decltype(et.next())
|
||||||
|
{
|
||||||
|
return et.next();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace XFOR
|
||||||
|
|
||||||
|
/* ========================= *
|
||||||
|
* --- TEMPLATE CODE --- *
|
||||||
|
* ========================= */
|
||||||
|
|
||||||
|
namespace XFOR
|
||||||
|
{
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
inline MExt<X>::MExt(size_t ext, X next) : mExt(ext), mNext(next) {}
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
template <size_t N>
|
||||||
|
inline MExt<X>::MExt(const std::array<size_t,N>& arr) :
|
||||||
|
mExt(std::get<NUM>(arr)), mNext(arr) {}
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
inline size_t MExt<X>::val() const
|
||||||
|
{
|
||||||
|
return mExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
inline const X& MExt<X>::next() const
|
||||||
|
{
|
||||||
|
return mNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
inline MExt<X> MExt<X>::operator+(const MExt<X>& in) const
|
||||||
|
{
|
||||||
|
return MExt<X>(mExt + in.val(), mNext + in.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
inline MExt<X> MExt<X>::operator*(size_t in) const
|
||||||
|
{
|
||||||
|
return MExt<X>(mExt * in, mNext * in);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//template <>
|
||||||
|
inline MExt<void>::MExt(size_t ext) : mExt(ext) {}
|
||||||
|
|
||||||
|
|
||||||
|
//template <>
|
||||||
|
template <size_t N>
|
||||||
|
inline MExt<void>::MExt(const std::array<size_t,N>& arr) :
|
||||||
|
mExt(std::get<NUM>(arr)) {}
|
||||||
|
|
||||||
|
//template <>
|
||||||
|
inline size_t MExt<void>::val() const
|
||||||
|
{
|
||||||
|
return mExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
//template <>
|
||||||
|
inline MExt<void> MExt<void>::operator+(const MExt<void>& in) const
|
||||||
|
{
|
||||||
|
return MExt<void>(mExt + in.val());
|
||||||
|
}
|
||||||
|
|
||||||
|
//template <>
|
||||||
|
inline MExt<void> MExt<void>::operator*(size_t in) const
|
||||||
|
{
|
||||||
|
return MExt<void>(mExt * in);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // end namespace XFOR
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,63 +0,0 @@
|
||||||
|
|
||||||
#ifndef __for_params_h__
|
|
||||||
#define __for_params_h__
|
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
|
||||||
{
|
|
||||||
|
|
||||||
template <typename P>
|
|
||||||
class ForParam
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
size_t mVal;
|
|
||||||
P mNext;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ForParam(const ForParam& last, const ForParam& ext, size_t pos);
|
|
||||||
inline const P& next() const;
|
|
||||||
inline const size_t& val() const;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
class ForParam<void>
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
size_t mVal;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ForParam(const ForParam& last, const ForParam& ext, size_t pos);
|
|
||||||
inline const size_t& val() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename P>
|
|
||||||
ForParam<P>::ForParam(const ForParam& last, const ForParam& ext, size_t pos) :
|
|
||||||
mVal(last.val() + pos * ext.val()), mNext(last.next(), ext.next(), pos) {}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
ForParam<void>::ForParam(const ForParam& last, const ForParam& ext, size_t pos) :
|
|
||||||
mVal(last.val() + pos * ext.val()) {}
|
|
||||||
|
|
||||||
template <typename P>
|
|
||||||
inline const P& ForParam<P>::next() const
|
|
||||||
{
|
|
||||||
return mNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename P>
|
|
||||||
inline const size_t& ForParam<P>::val() const
|
|
||||||
{
|
|
||||||
return mVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
inline const size_t& ForParam<void>::val() const
|
|
||||||
{
|
|
||||||
return mVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include "xfor/for_utils.h"
|
#include "xfor/for_utils.h"
|
||||||
#include "xfor/for_type.h"
|
#include "xfor/for_type.h"
|
||||||
#include "xfor/for_params.h"
|
#include "xfor/exttype.h"
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
|
@ -46,29 +46,30 @@ namespace MultiArrayHelper
|
||||||
size_t mMax;
|
size_t mMax;
|
||||||
Expr mExpr;
|
Expr mExpr;
|
||||||
|
|
||||||
typedef decltype(mExpr.rootSteps()) FParType;
|
typedef decltype(mExpr.rootSteps()) ExtType;
|
||||||
FParType mExt;
|
ExtType mExt;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static size_t layer() { return Expr::layer() + 1; }
|
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||||
static const size_t LAYER = Expr::LAYER + 1;
|
static constexpr size_t SIZE = Expr::SIZE;
|
||||||
static const size_t SIZE = std::remove_reference<Expr>::type::SIZE;
|
|
||||||
|
For(const For& in) = default;
|
||||||
|
For& operator=(const For& in) = default;
|
||||||
For(For&& in) = default;
|
For(For&& in) = default;
|
||||||
For& operator=(For&& in) = default;
|
For& operator=(For&& in) = default;
|
||||||
|
|
||||||
For(const std::shared_ptr<IndexClass>& indPtr,
|
For(const std::shared_ptr<IndexClass>& indPtr,
|
||||||
Expr&& expr);
|
Expr expr);
|
||||||
|
|
||||||
For(const IndexClass* indPtr,
|
For(const IndexClass* indPtr,
|
||||||
Expr&& expr);
|
Expr expr);
|
||||||
|
|
||||||
|
|
||||||
inline void operator()(size_t mlast, const FParType& last) const;
|
inline void operator()(size_t mlast, ExtType last) const;
|
||||||
inline void operator()(size_t mlast = 0) const;
|
inline void operator()(size_t mlast = 0) const;
|
||||||
|
|
||||||
FParType rootSteps(std::intptr_t iPtrNum = 0) const;
|
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT>
|
||||||
For<IndexClass,Expr,FT>::For(const std::shared_ptr<IndexClass>& indPtr,
|
For<IndexClass,Expr,FT>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||||
Expr&& expr) :
|
Expr expr) :
|
||||||
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr),
|
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr),
|
||||||
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr.get() )))
|
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr.get() )))
|
||||||
{
|
{
|
||||||
|
@ -103,7 +104,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT>
|
||||||
For<IndexClass,Expr,FT>::For(const IndexClass* indPtr,
|
For<IndexClass,Expr,FT>::For(const IndexClass* indPtr,
|
||||||
Expr&& expr) :
|
Expr expr) :
|
||||||
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
|
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
|
||||||
mExpr(std::forward<Expr>( expr )),
|
mExpr(std::forward<Expr>( expr )),
|
||||||
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ) ))
|
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ) ))
|
||||||
|
@ -115,13 +116,11 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT>
|
||||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast,
|
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast,
|
||||||
const FParType& last) const
|
const ExtType last) const
|
||||||
{
|
{
|
||||||
for(size_t pos = mSPos; pos != mMax; ++pos){
|
for(size_t pos = mSPos; pos != mMax; ++pos){
|
||||||
//const size_t mnpos = mlast * max + pos;
|
|
||||||
const size_t mnpos = PosForward<FT>::value(mlast, mMax, pos);
|
const size_t mnpos = PosForward<FT>::value(mlast, mMax, pos);
|
||||||
//const FParType npos = std::move( XFPackNum<SIZE-1>::mkPos(pos, mExt, last) );
|
const ExtType npos = last + mExt*pos;
|
||||||
const FParType npos(mlast, mExt, pos);
|
|
||||||
mExpr(mnpos, npos);
|
mExpr(mnpos, npos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,18 +128,17 @@ namespace MultiArrayHelper
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT>
|
||||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast) const
|
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast) const
|
||||||
{
|
{
|
||||||
const FParType last;
|
const ExtType last;
|
||||||
for(size_t pos = mSPos; pos != mMax; ++pos){
|
for(size_t pos = mSPos; pos != mMax; ++pos){
|
||||||
//const size_t mnpos = mlast * max + pos;
|
|
||||||
const size_t mnpos = PosForward<FT>::value(mlast, mMax, pos);
|
const size_t mnpos = PosForward<FT>::value(mlast, mMax, pos);
|
||||||
//const FParType npos = std::move( XFPackNum<SIZE-1>::mkPos(pos, mExt, last) );
|
const ExtType npos = last + mExt*pos;
|
||||||
const FParType npos(mlast, mExt, pos);
|
|
||||||
mExpr(mnpos, npos);
|
mExpr(mnpos, npos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT>
|
||||||
typename For<IndexClass,Expr,FT>::FParType For<IndexClass,Expr,FT>::rootSteps(std::intptr_t iPtrNum) const
|
auto For<IndexClass,Expr,FT>::rootSteps(std::intptr_t iPtrNum) const
|
||||||
|
-> ExtType
|
||||||
{
|
{
|
||||||
return mExpr.rootSteps(iPtrNum);
|
return mExpr.rootSteps(iPtrNum);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue