unit tests should all work again

This commit is contained in:
Christian Zimmermann 2018-02-14 00:38:44 +01:00
parent bcc6b98882
commit ad59b5519d
5 changed files with 73 additions and 46 deletions

View file

@ -469,7 +469,8 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
MExt<void> ConstOperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const MExt<void> ConstOperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{ {
return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); return MExt<void>(getStepSize( mIndex->info(), iPtrNum ));
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
} }
@ -520,7 +521,8 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
MExt<void> OperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const MExt<void> OperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{ {
return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); return MExt<void>(getStepSize( mIndex->info(), iPtrNum ));
//return MExt<void>(getStepSize( getRootIndices( mIndex->info() ), iPtrNum ));
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -542,7 +544,7 @@ namespace MultiArrayTools
template <class ET> template <class ET>
inline T Operation<T,OpFunction,Ops...>::get(ET pos) const inline T Operation<T,OpFunction,Ops...>::get(ET pos) const
{ {
typedef std::tuple<Ops const&...> OpTuple; typedef std::tuple<Ops...> OpTuple;
return PackNum<sizeof...(Ops)-1>:: return PackNum<sizeof...(Ops)-1>::
template mkOpExpr<SIZE,T,ET,OpTuple,OpFunction>(pos, mOps); template mkOpExpr<SIZE,T,ET,OpTuple,OpFunction>(pos, mOps);
} }

View file

@ -14,13 +14,6 @@
namespace MultiArrayHelper namespace MultiArrayHelper
{ {
template <template <typename> class X, class Y>
auto together(const X<void>& x, const Y& y)
-> X<Y>
{
return X<Y>(x, y);
}
template <size_t N> template <size_t N>
struct PackNum struct PackNum
{ {
@ -60,9 +53,9 @@ namespace MultiArrayHelper
template <class... Ops> template <class... Ops>
static auto mkSteps(std::intptr_t ii, const std::tuple<Ops...>& otp) static auto mkSteps(std::intptr_t ii, const std::tuple<Ops...>& otp)
-> decltype(together(PackNum<N-1>::mkSteps(ii, otp), std::get<N>(otp).rootSteps(ii))) -> decltype(PackNum<N-1>::mkSteps(ii, otp).extend( std::get<N>(otp).rootSteps(ii)) )
{ {
return together(PackNum<N-1>::mkSteps(ii, otp), std::get<N>(otp).rootSteps(ii) ); return PackNum<N-1>::mkSteps(ii, otp).extend( std::get<N>(otp).rootSteps(ii));
} }
template <class RootStepTuple, class IndexClass, class OpClass> template <class RootStepTuple, class IndexClass, class OpClass>
@ -80,13 +73,13 @@ namespace MultiArrayHelper
typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType; typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType;
static_assert(LAST > NextOpType::SIZE, "inconsistent array positions"); static_assert(LAST > NextOpType::SIZE, "inconsistent array positions");
static constexpr size_t NEXT = LAST - NextOpType::SIZE; static constexpr size_t NEXT = LAST - NextOpType::SIZE;
return PackNum<N-1>::template mkOpExpr<NEXT,ETuple,OpTuple,OpFunction,decltype(std::get<N>(ops)),Args...> return PackNum<N-1>::template mkOpExpr<NEXT,T,ETuple,OpTuple,OpFunction,T,Args...>
( pos, ops, std::get<N>(ops).get(Getter<NEXT>::template get<ETuple>( pos )), args...); ( pos, ops, std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos )), args...);
} }
template <class OpTuple, class Expr> template <class OpTuple, class Expr>
static auto mkLoop( const OpTuple& ot, Expr&& exp ) static auto mkLoop( const OpTuple& ot, Expr&& exp )
-> decltype(std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) ))&& -> decltype(std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) ))
{ {
return std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) ); return std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) );
} }
@ -147,13 +140,15 @@ namespace MultiArrayHelper
template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args> template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args) static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args)
{ {
static_assert(LAST == 0, "inconsistent array positions"); typedef typename std::remove_reference<decltype(std::get<0>(ops))>::type NextOpType;
return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template get<ETuple>( pos )), args...); static constexpr size_t NEXT = LAST - NextOpType::SIZE;
static_assert(NEXT == 0, "inconsistent array positions");
return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
} }
template <class OpTuple, class Expr> template <class OpTuple, class Expr>
static auto mkLoop( const OpTuple& ot, Expr&& exp ) static auto mkLoop( const OpTuple& ot, Expr&& exp )
-> decltype(std::get<0>(ot).loop( exp ))&& -> decltype(std::get<0>(ot).loop( exp ))
{ {
return std::get<0>(ot).loop( exp ); return std::get<0>(ot).loop( exp );
} }

View file

@ -89,34 +89,22 @@ namespace MultiArrayTools
return out; return out;
} }
size_t getStepSize(const std::vector<IndexInfo>& iv, const IndexInfo& j) //inline size_t getStepSize(const IndexInfo& ii, std::intptr_t j)
{
size_t ss = 1;
auto ii = iv.end() - 1;
auto end = iv.begin();
while(*ii != j){
ss *= ii->max();
--ii;
if(ii == end){
break;
}
}
return ss;
}
size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j) size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j)
{ {
size_t ss = 1; size_t ss = 1;
auto ii = iv.end() - 1; for(auto ii = iv.end() - 1; ii != iv.begin(); --ii){
auto end = iv.begin(); if(ii->getPtrNum() == j){
while(ii->getPtrNum() != j){
ss *= ii->max();
--ii;
if(ii == end){
break;
}
}
return ss; return ss;
} }
ss *= ii->max();
}
if(iv.begin()->getPtrNum() == j){
return ss;
} else {
return 0;
}
}
} // end namespace MultiArrayTools } // end namespace MultiArrayTools

View file

@ -78,7 +78,24 @@ namespace MultiArrayTools
std::vector<IndexInfo> getRootIndices(const IndexInfo& info); std::vector<IndexInfo> getRootIndices(const IndexInfo& info);
size_t getStepSize(const std::vector<IndexInfo>& iv, const IndexInfo& j); inline size_t getStepSize(const IndexInfo& ii, std::intptr_t j)
{
if(ii.type() == IndexType::SINGLE){
return ii.getPtrNum() == j ? 1 : 0;
}
else {
size_t ss = 0;
size_t sx = 1;
for(size_t i = 0; i != ii.dim(); ++i){
const IndexInfo& itmp = *ii.getPtr(ii.dim()-i-1);
const size_t max = itmp.max();
const size_t tmp = getStepSize(itmp, j);
ss += tmp * sx;
sx *= max;
}
return ss;
}
}
size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j); size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j);
} // end namespace MultiArrayTools } // end namespace MultiArrayTools

View file

@ -42,6 +42,10 @@ namespace MultiArrayHelper
inline MExt operator+(const MExt& in) const; inline MExt operator+(const MExt& in) const;
inline MExt operator*(size_t in) const; inline MExt operator*(size_t in) const;
template <class Y>
auto extend(const Y& y) const -> MExt<decltype(mNext.extend(y))>
{ return MExt<decltype(mNext.extend(y))>(mExt, mNext.extend(y)); }
}; };
template <> template <>
@ -63,6 +67,12 @@ namespace MultiArrayHelper
inline MExt(size_t ext); inline MExt(size_t ext);
template <class Z>
inline MExt(size_t y, const Z& z);
template <class Y, class Z>
inline MExt(const Y& y, const Z& z);
template <size_t N> template <size_t N>
inline MExt(const std::array<size_t,N>& arr); inline MExt(const std::array<size_t,N>& arr);
@ -72,6 +82,10 @@ namespace MultiArrayHelper
inline MExt operator+(const MExt& in) const; inline MExt operator+(const MExt& in) const;
inline MExt operator*(size_t in) const; inline MExt operator*(size_t in) const;
template <class Y>
auto extend(const Y& y) const -> MExt<Y>
{ return MExt<Y>(mExt,y); }
}; };
@ -86,7 +100,7 @@ namespace MultiArrayHelper
template <class ExtType> template <class ExtType>
static inline auto getX(const ExtType& et) static inline auto getX(const ExtType& et)
-> decltype(Getter<I-1>::get(et.next())) -> decltype(Getter<I-1>::getX(et.next()))
{ {
return Getter<I-1>::getX(et.next()); return Getter<I-1>::getX(et.next());
} }
@ -103,9 +117,9 @@ namespace MultiArrayHelper
template <class ExtType> template <class ExtType>
static inline auto getX(const ExtType& et) static inline auto getX(const ExtType& et)
-> decltype(et.next()) -> ExtType
{ {
return et.next(); return et;
} }
}; };
@ -165,6 +179,17 @@ namespace MultiArrayHelper
inline MExt<void>::MExt(size_t ext) : mExt(ext) {} inline MExt<void>::MExt(size_t ext) : mExt(ext) {}
//template <>
template <class Z>
inline MExt<void>::MExt(size_t y, const Z& z) :
mExt(z.val()) {}
//template <>
template <class Y, class Z>
inline MExt<void>::MExt(const Y& y, const Z& z) :
mExt(y.val()) {}
//template <> //template <>
template <size_t N> template <size_t N>
inline MExt<void>::MExt(const std::array<size_t,N>& arr) : inline MExt<void>::MExt(const std::array<size_t,N>& arr) :