still not better...

This commit is contained in:
Christian Zimmermann 2019-02-26 18:56:57 +01:00
parent 59ffd5adcc
commit 6f320fe9e9
7 changed files with 212 additions and 105 deletions

View file

@ -29,7 +29,7 @@ namespace MultiArrayTools
template <class MapF, class IndexPack, class Expr, SpaceType STYPE> template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast, inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast,
ExtType last) const ExtType last)
{ {
constexpr size_t NEXT = Op::SIZE; constexpr size_t NEXT = Op::SIZE;
const ExtType nxpos = last; const ExtType nxpos = last;
@ -42,7 +42,7 @@ namespace MultiArrayTools
} }
template <class MapF, class IndexPack, class Expr, SpaceType STYPE> template <class MapF, class IndexPack, class Expr, SpaceType STYPE>
inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast) const inline void OpExpr<MapF,IndexPack,Expr,STYPE>::operator()(size_t mlast)
{ {
const ExtType last; const ExtType last;
constexpr size_t NEXT = Op::SIZE; constexpr size_t NEXT = Op::SIZE;

View file

@ -66,8 +66,8 @@ namespace MultiArrayTools
OpExpr(const MapF& mapf, const IndexPack& ipack, const std::shared_ptr<OIType>& oind, size_t step, 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, ExtType last);
inline void operator()(size_t mlast = 0) const; inline void operator()(size_t mlast = 0);
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;

View file

@ -109,18 +109,25 @@ namespace MultiArrayTools
/***************************************** /*****************************************
* OperationMaster::AssignmentExpr * * OperationMaster::AssignmentExpr *
*****************************************/ *****************************************/
/*
template <typename T, class AOp, class OpClass, class... Ranges> template <typename T, class AOp, class OpClass, class... Ranges>
OperationMaster<T,AOp,OpClass,Ranges...>::AssignmentExpr:: OperationMaster<T,AOp,OpClass,Ranges...>::AssignmentExpr::
AssignmentExpr(OperationMaster& m, const OpClass& sec) : AssignmentExpr(OperationMaster& m, const OpClass& sec) :
mM(m), mSec(sec) {} mM(m), mSec(sec) {}
*/
template <typename T, class AOp, class OpClass, class... Ranges>
OperationMaster<T,AOp,OpClass,Ranges...>::AssignmentExpr::
AssignmentExpr(T* dataPtr, const OpClass& sec) :
mSec(sec), mDataPtr(dataPtr) {}
template <typename T, class AOp, class OpClass, class... Ranges> template <typename T, class AOp, class OpClass, class... Ranges>
inline void OperationMaster<T,AOp,OpClass,Ranges...>::AssignmentExpr:: inline void OperationMaster<T,AOp,OpClass,Ranges...>::AssignmentExpr::
operator()(size_t start, ExtType last) const operator()(size_t start, ExtType last)
{ {
//VCHECK(mSec.template get<ExtType>(last)); //VCHECK(mSec.template get<ExtType>(last));
mM.set(start, mSec.template get<ExtType>(last) ); //mM.set(start, mSec.template get<ExtType>(last) );
mDataPtr[start] = mSec.template get<ExtType>(last);
//AOp::sapply(mDataPtr[start], mSec.template get<ExtType>(last));
} }
template <typename T, class AOp, class OpClass, class... Ranges> template <typename T, class AOp, class OpClass, class... Ranges>
@ -130,7 +137,30 @@ namespace MultiArrayTools
{ {
return mSec.rootSteps(iPtrNum); return mSec.rootSteps(iPtrNum);
} }
template <typename T, class AOp, class OpClass, class... Ranges>
OperationMaster<T,AOp,OpClass,Ranges...>::AddExpr::
AddExpr(T* dataPtr, const OpClass& sec) :
mSec(sec), mDataPtr(dataPtr) {}
template <typename T, class AOp, class OpClass, class... Ranges>
inline void OperationMaster<T,AOp,OpClass,Ranges...>::AddExpr::
operator()(size_t start, ExtType last)
{
//VCHECK(mSec.template get<ExtType>(last));
//mM.set(start, mSec.template get<ExtType>(last) );
mDataPtr[start] += mSec.template get<ExtType>(last);
//AOp::sapply(mDataPtr[start], mSec.template get<ExtType>(last));
}
template <typename T, class AOp, class OpClass, class... Ranges>
typename OperationMaster<T,AOp,OpClass,Ranges...>::AddExpr::ExtType
OperationMaster<T,AOp,OpClass,Ranges...>::AddExpr::
rootSteps(std::intptr_t iPtrNum) const
{
return mSec.rootSteps(iPtrNum);
}
/************************* /*************************
* OperationMaster * * OperationMaster *
@ -159,15 +189,17 @@ namespace MultiArrayTools
template <typename T, class AOp, class OpClass, class... Ranges> template <typename T, class AOp, class OpClass, class... Ranges>
void OperationMaster<T,AOp,OpClass,Ranges...>::performAssignment(std::intptr_t blockIndexNum) void OperationMaster<T,AOp,OpClass,Ranges...>::performAssignment(std::intptr_t blockIndexNum)
{ {
/*
AssignmentExpr ae(*this, mSecond); // Expression to be executed within loop AssignmentExpr ae(*this, mSecond); // Expression to be executed within loop
if(mDoParallel){ if(mDoParallel){
const auto ploop = mIndex.pifor( 1, mSecond.loop(ae) ); auto ploop = mIndex.pifor( 1, mSecond.loop(ae) );
ploop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions ploop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions
} }
else { else {
const auto loop = mIndex.ifor( 1, mSecond.loop(ae) ); auto loop = mIndex.ifor( 1, mSecond.loop(ae) );
loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions
} }
*/
} }
template <typename T, class AOp, class OpClass, class... Ranges> template <typename T, class AOp, class OpClass, class... Ranges>
@ -186,11 +218,12 @@ namespace MultiArrayTools
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma, ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) : const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mDataPtr(ma.data()), mDataPtr(ma.data()),
mOrigDataPtr(ma.data()),
mIndex( ma.begin() ) mIndex( ma.begin() )
{ {
//VCHECK(ma.data()); //VCHECK(ma.data());
mIndex(indices...); mIndex(indices...);
mOff = mIndex.pos(); //mOff = mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -198,35 +231,37 @@ namespace MultiArrayTools
ConstOperationRoot(std::shared_ptr<MultiArrayBase<T,Ranges...> > maptr, ConstOperationRoot(std::shared_ptr<MultiArrayBase<T,Ranges...> > maptr,
const std::shared_ptr<typename Ranges::IndexType>&... indices) : const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mDataPtr(maptr->data()), mDataPtr(maptr->data()),
mOrigDataPtr(maptr->data()),
mIndex(maptr->begin()), mIndex(maptr->begin()),
mMaPtr(maptr) mMaPtr(maptr)
{ {
mIndex(indices...); mIndex(indices...);
mOff = mIndex.pos(); //mOff = mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
ConstOperationRoot<T,Ranges...>:: ConstOperationRoot<T,Ranges...>::
ConstOperationRoot(const T* data, const IndexType& ind) : ConstOperationRoot(const T* data, const IndexType& ind) :
mDataPtr(data), mDataPtr(data),
mOrigDataPtr(data),
mIndex( ind ) mIndex( ind )
{ {
mOff = mIndex.pos(); //mOff = mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class ET> template <class ET>
inline T ConstOperationRoot<T,Ranges...>::get(ET pos) const inline T ConstOperationRoot<T,Ranges...>::get(ET pos) const
{ {
return mDataPtr[pos.val()+mOff]; return mDataPtr[pos.val()/*+mOff*/];
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class ET> template <class ET>
inline const ConstOperationRoot<T,Ranges...>& ConstOperationRoot<T,Ranges...>::set(ET pos) const inline ConstOperationRoot<T,Ranges...>& ConstOperationRoot<T,Ranges...>::set(ET pos)
{ {
mIndex = pos.val(); mIndex = pos.val();
mOff = mIndex.pos(); mDataPtr = mOrigDataPtr + mIndex.pos();
return *this; return *this;
} }
@ -267,7 +302,7 @@ namespace MultiArrayTools
template <typename T, class Op> template <typename T, class Op>
template <class ET> template <class ET>
inline const StaticCast<T,Op>& StaticCast<T,Op>::set(ET pos) const inline StaticCast<T,Op>& StaticCast<T,Op>::set(ET pos)
{ {
mOp.set(pos); mOp.set(pos);
return *this; return *this;
@ -311,7 +346,7 @@ namespace MultiArrayTools
template <class Range> template <class Range>
template <class ET> template <class ET>
inline const MetaOperationRoot<Range>& MetaOperationRoot<Range>::set(ET pos) const inline MetaOperationRoot<Range>& MetaOperationRoot<Range>::set(ET pos)
{ {
assert(0); assert(0);
//(*mIndex) = pos.val(); //(*mIndex) = pos.val();
@ -342,38 +377,65 @@ namespace MultiArrayTools
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma, OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) : const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mDataPtr(ma.data()), mDataPtr(ma.data()),
mOrigDataPtr(ma.data()),
mIndex( ma.begin() ) mIndex( ma.begin() )
{ {
mIndex(indices...); mIndex(indices...);
mOff = mIndex.pos(); //mOff = mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
OperationRoot<T,Ranges...>:: OperationRoot<T,Ranges...>::
OperationRoot(T* data, const IndexType& ind) : OperationRoot(T* data, const IndexType& ind) :
mDataPtr(data), mDataPtr(data),
mOrigDataPtr(data),
mIndex( ind ) mIndex( ind )
{ {
mOff = mIndex.pos(); //mOff = mIndex.pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
OperationMaster<T,SelfIdentity<T>,OpClass,Ranges...> OperationRoot<T,Ranges...>::operator=(const OpClass& in) OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::operator=(const OpClass& in)
//OperationMaster<T,SelfIdentity<T>,OpClass,Ranges...> OperationRoot<T,Ranges...>::operator=(const OpClass& in)
{ {
return OperationMaster<T,SelfIdentity<T>,OpClass,Ranges...>(mDataPtr, in, mIndex, mDoParallel); typename OperationMaster<T,SelfIdentity<T>,OpClass,Ranges...>::AssignmentExpr ae(mDataPtr, in);
// Expression to be executed within loop
if(mDoParallel){
auto ploop = mIndex.pifor( 1, in.loop(ae) );
ploop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions
}
else {
auto loop = mIndex.ifor( 1, in.loop(ae) );
loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions
}
return *this;
//return OperationMaster<T,SelfIdentity<T>,OpClass,Ranges...>(mDataPtr, in, mIndex, mDoParallel);
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class OpClass> template <class OpClass>
OperationMaster<T,plus<T>,OpClass,Ranges...> OperationRoot<T,Ranges...>::operator+=(const OpClass& in) OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::operator+=(const OpClass& in)
//OperationMaster<T,plus<T>,OpClass,Ranges...> OperationRoot<T,Ranges...>::operator+=(const OpClass& in)
{ {
return OperationMaster<T,plus<T>,OpClass,Ranges...>(mDataPtr, in, mIndex, mDoParallel); typename OperationMaster<T,plus<T>,OpClass,Ranges...>::AddExpr ae(mDataPtr, in);
// Expression to be executed within loop
if(mDoParallel){
auto ploop = mIndex.pifor( 1, in.loop(ae) );
ploop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions
}
else {
auto loop = mIndex.ifor( 1, in.loop(ae) );
loop(); // execute overall loop(s) and so internal hidden loops and so the inherited expressions
}
return *this;
//return OperationMaster<T,plus<T>,OpClass,Ranges...>(mDataPtr, in, mIndex, mDoParallel);
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
OperationMaster<T,SelfIdentity<T>,OperationRoot<T,Ranges...>,Ranges...> OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::operator=(const OperationRoot<T,Ranges...>& in)
OperationRoot<T,Ranges...>::operator=(const OperationRoot<T,Ranges...>& in) //OperationMaster<T,SelfIdentity<T>,OperationRoot<T,Ranges...>,Ranges...>
//OperationRoot<T,Ranges...>::operator=(const OperationRoot<T,Ranges...>& in)
{ {
return operator=<OperationRoot<T,Ranges...> >(in); return operator=<OperationRoot<T,Ranges...> >(in);
} }
@ -389,15 +451,15 @@ namespace MultiArrayTools
template <class ET> template <class ET>
inline T OperationRoot<T,Ranges...>::get(ET pos) const inline T OperationRoot<T,Ranges...>::get(ET pos) const
{ {
return mDataPtr[pos.val()+mOff]; return mDataPtr[pos.val()/*+mOff*/];
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class ET> template <class ET>
inline const OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::set(ET pos) const inline OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::set(ET pos)
{ {
mIndex = pos.val(); mIndex = pos.val();
mOff = mIndex.pos(); mDataPtr = mOrigDataPtr + mIndex.pos();
return *this; return *this;
} }
@ -418,7 +480,8 @@ namespace MultiArrayTools
template <typename T, class... Ranges> template <typename T, class... Ranges>
T* OperationRoot<T,Ranges...>::data() const T* OperationRoot<T,Ranges...>::data() const
{ {
return mDataPtr + mIndex().pos(); auto i = mIndex;
return mDataPtr + i().pos();
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -448,7 +511,7 @@ namespace MultiArrayTools
template <typename T> template <typename T>
template <class ET> template <class ET>
inline const OperationValue<T>& OperationValue<T>::set(ET pos) const inline OperationValue<T>& OperationValue<T>::set(ET pos)
{ {
return *this; return *this;
} }
@ -498,7 +561,7 @@ namespace MultiArrayTools
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
template <class ET> template <class ET>
inline const Operation<T,OpFunction,Ops...>& Operation<T,OpFunction,Ops...>::set(ET pos) const inline Operation<T,OpFunction,Ops...>& Operation<T,OpFunction,Ops...>::set(ET pos)
{ {
PackNum<sizeof...(Ops)-1>::setOpPos(mOps,pos); PackNum<sizeof...(Ops)-1>::setOpPos(mOps,pos);
return *this; return *this;
@ -539,7 +602,7 @@ namespace MultiArrayTools
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
template <class ET> template <class ET>
inline const Contraction<T,Op,IndexType>& Contraction<T,Op,IndexType>::set(ET pos) const inline Contraction<T,Op,IndexType>& Contraction<T,Op,IndexType>::set(ET pos)
{ {
mOp.set(pos); mOp.set(pos);
return *this; return *this;
@ -586,7 +649,7 @@ namespace MultiArrayTools
template <typename T, class Op, class... Indices> template <typename T, class Op, class... Indices>
template <class ET> template <class ET>
inline const SliceContraction<T,Op,Indices...>& SliceContraction<T,Op,Indices...>::set(ET pos) const inline SliceContraction<T,Op,Indices...>& SliceContraction<T,Op,Indices...>::set(ET pos)
{ {
mOp.set(pos); mOp.set(pos);
return *this; return *this;

View file

@ -91,7 +91,7 @@ namespace MultiArrayTools
template <typename T> template <typename T>
struct SelfIdentity struct SelfIdentity
{ {
static inline T& sapply(T& a, const T& b) static inline T& sapply(T& a, T b)
{ {
return a = b; return a = b;
} }
@ -107,27 +107,57 @@ namespace MultiArrayTools
private: private:
AssignmentExpr() = default; AssignmentExpr() = default;
OperationMaster& mM; //OperationMaster mM;
const OpClass& mSec; OpClass mSec;
T* mDataPtr;
public: public:
static constexpr size_t LAYER = 0; static constexpr size_t LAYER = 0;
static constexpr size_t SIZE = OpClass::SIZE; static constexpr size_t SIZE = OpClass::SIZE;
typedef decltype(mSec.rootSteps()) ExtType; typedef decltype(mSec.rootSteps()) ExtType;
AssignmentExpr(OperationMaster& m, const OpClass& sec); //AssignmentExpr(OperationMaster& m, const OpClass& sec);
AssignmentExpr(T* dataPtr, const OpClass& sec);
AssignmentExpr(const AssignmentExpr& in) = default; AssignmentExpr(const AssignmentExpr& in) = default;
AssignmentExpr(AssignmentExpr&& in) = default; AssignmentExpr(AssignmentExpr&& in) = default;
inline void operator()(size_t start = 0) const; inline void operator()(size_t start = 0);
inline void operator()(size_t start, ExtType last) const; inline void operator()(size_t start, ExtType last);
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
}; };
class AddExpr
{
private:
AddExpr() = default;
//OperationMaster mM;
OpClass mSec;
T* mDataPtr;
public:
static constexpr size_t LAYER = 0;
static constexpr size_t SIZE = OpClass::SIZE;
typedef decltype(mSec.rootSteps()) ExtType;
//AssignmentExpr(OperationMaster& m, const OpClass& sec);
AddExpr(T* dataPtr, const OpClass& sec);
AddExpr(const AddExpr& in) = default;
AddExpr(AddExpr&& in) = default;
inline void operator()(size_t start = 0);
inline void operator()(size_t start, ExtType last);
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
};
typedef T value_type; typedef T value_type;
//typedef OperationBase<T> OB; //typedef OperationBase<T> OB;
typedef ContainerRange<T,Ranges...> CRange; typedef ContainerRange<T,Ranges...> CRange;
@ -180,7 +210,7 @@ namespace MultiArrayTools
inline T get(ET pos) const; inline T get(ET pos) const;
template <class ET> template <class ET>
inline const ConstOperationRoot& set(ET pos) const; inline ConstOperationRoot& set(ET pos);
MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
@ -193,8 +223,9 @@ namespace MultiArrayTools
//MultiArrayBase<T,Ranges...> const& mArrayRef; //MultiArrayBase<T,Ranges...> const& mArrayRef;
const T* mDataPtr; const T* mDataPtr;
mutable IndexType mIndex; const T* mOrigDataPtr;
mutable size_t mOff = 0; IndexType mIndex;
//size_t mOff = 0;
std::shared_ptr<MultiArrayBase<T,Ranges...> > mMaPtr; // never remove this ptr, otherwise we lose temporary container instances! std::shared_ptr<MultiArrayBase<T,Ranges...> > mMaPtr; // never remove this ptr, otherwise we lose temporary container instances!
}; };
@ -202,7 +233,7 @@ namespace MultiArrayTools
class StaticCast : public OperationTemplate<T,StaticCast<T,Op> > class StaticCast : public OperationTemplate<T,StaticCast<T,Op> >
{ {
private: private:
const Op& mOp; Op mOp;
public: public:
@ -219,7 +250,7 @@ namespace MultiArrayTools
inline T get(ET pos) const; inline T get(ET pos) const;
template <class ET> template <class ET>
inline const StaticCast& set(ET pos) const; inline StaticCast& set(ET pos);
auto rootSteps(std::intptr_t iPtrNum = 0) const auto rootSteps(std::intptr_t iPtrNum = 0) const
-> decltype(mOp.rootSteps(iPtrNum)); -> decltype(mOp.rootSteps(iPtrNum));
@ -253,7 +284,7 @@ namespace MultiArrayTools
inline value_type get(ET pos) const; inline value_type get(ET pos) const;
template <class ET> template <class ET>
inline const MetaOperationRoot& set(ET pos) const; inline MetaOperationRoot& set(ET pos);
MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
@ -284,7 +315,7 @@ namespace MultiArrayTools
const std::shared_ptr<typename Ranges::IndexType>&... indices); const std::shared_ptr<typename Ranges::IndexType>&... indices);
OperationRoot(T* data, const IndexType& ind); OperationRoot(T* data, const IndexType& ind);
/*
template <class OpClass> template <class OpClass>
OperationMaster<T,SelfIdentity<T>,OpClass,Ranges...> operator=(const OpClass& in); OperationMaster<T,SelfIdentity<T>,OpClass,Ranges...> operator=(const OpClass& in);
@ -292,14 +323,23 @@ namespace MultiArrayTools
OperationMaster<T,plus<T>,OpClass,Ranges...> operator+=(const OpClass& in); OperationMaster<T,plus<T>,OpClass,Ranges...> operator+=(const OpClass& in);
OperationMaster<T,SelfIdentity<T>,OperationRoot,Ranges...> operator=(const OperationRoot& in); OperationMaster<T,SelfIdentity<T>,OperationRoot,Ranges...> operator=(const OperationRoot& in);
*/
template <class OpClass>
OperationRoot& operator=(const OpClass& in);
template <class OpClass>
OperationRoot& operator+=(const OpClass& in);
OperationRoot& operator=(const OperationRoot& in);
OperationRoot& par(); OperationRoot& par();
template <class ET> template <class ET>
inline T get(ET pos) const; inline T get(ET pos) const;
template <class ET> template <class ET>
inline const OperationRoot& set(ET pos) const; inline OperationRoot& set(ET pos);
MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
@ -316,8 +356,9 @@ namespace MultiArrayTools
//MutableMultiArrayBase<T,Ranges...>& mArrayRef; //MutableMultiArrayBase<T,Ranges...>& mArrayRef;
T* mDataPtr; T* mDataPtr;
mutable IndexType mIndex; T* mOrigDataPtr;
mutable size_t mOff = 0; IndexType mIndex;
//size_t mOff = 0;
bool mDoParallel = false; bool mDoParallel = false;
}; };
@ -338,7 +379,7 @@ namespace MultiArrayTools
inline T get(ET pos) const; inline T get(ET pos) const;
template <class ET> template <class ET>
inline const OperationValue& set(ET pos) const; inline OperationValue& set(ET pos);
MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
@ -415,7 +456,7 @@ namespace MultiArrayTools
inline T get(ET pos) const; inline T get(ET pos) const;
template <class ET> template <class ET>
inline const Operation& set(ET pos) const; inline Operation& set(ET pos);
auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype
-> decltype(PackNum<sizeof...(Ops)-1>::mkSteps(iPtrNum, mOps)); -> decltype(PackNum<sizeof...(Ops)-1>::mkSteps(iPtrNum, mOps));
@ -473,7 +514,7 @@ namespace MultiArrayTools
private: private:
const Op& mOp; Op mOp;
std::shared_ptr<IndexType> mInd; std::shared_ptr<IndexType> mInd;
public: public:
@ -485,7 +526,7 @@ namespace MultiArrayTools
inline T get(ET pos) const; inline T get(ET pos) const;
template <class ET> template <class ET>
inline const Contraction& set(ET pos) const; inline Contraction& set(ET pos);
auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype
-> decltype(mOp.rootSteps(iPtrNum)); -> decltype(mOp.rootSteps(iPtrNum));
@ -509,7 +550,7 @@ namespace MultiArrayTools
private: private:
const Op& mOp; mutable Op mOp;
mutable std::shared_ptr<MultiArray<T,typename Indices::RangeType...> > mCont; mutable std::shared_ptr<MultiArray<T,typename Indices::RangeType...> > mCont;
mutable OperationRoot<T,typename Indices::RangeType...> mTarOp; mutable OperationRoot<T,typename Indices::RangeType...> mTarOp;
@ -522,7 +563,7 @@ namespace MultiArrayTools
inline const value_type& get(ET pos) const; inline const value_type& get(ET pos) const;
template <class ET> template <class ET>
inline const SliceContraction& set(ET pos) const; inline SliceContraction& set(ET pos);
auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype
-> decltype(mOp.rootSteps(iPtrNum)); -> decltype(mOp.rootSteps(iPtrNum));

View file

@ -71,7 +71,7 @@ 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(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, const Args&... args) static inline T mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, Args... args)
{ {
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");
@ -116,7 +116,7 @@ namespace MultiArrayHelper
} }
template <size_t LAST,class OpTuple, class ETuple> template <size_t LAST,class OpTuple, class ETuple>
static inline void setOpPos(const OpTuple& ot, const ETuple& et) static inline void setOpPos(OpTuple& ot, const ETuple& et)
{ {
typedef typename std::remove_reference<decltype(std::get<N>(ot))>::type NextOpType; typedef typename std::remove_reference<decltype(std::get<N>(ot))>::type NextOpType;
static_assert(LAST > NextOpType::SIZE, "inconsistent array positions"); static_assert(LAST > NextOpType::SIZE, "inconsistent array positions");
@ -203,7 +203,7 @@ namespace MultiArrayHelper
} }
template <size_t LAST,class OpTuple, class ETuple> template <size_t LAST,class OpTuple, class ETuple>
static inline void setOpPos(const OpTuple& ot, const ETuple& et) static inline void setOpPos(OpTuple& ot, const ETuple& et)
{ {
typedef typename std::remove_reference<decltype(std::get<0>(et))>::type NextOpType; typedef typename std::remove_reference<decltype(std::get<0>(et))>::type NextOpType;
static_assert(LAST > NextOpType::SIZE, "inconsistent array positions"); static_assert(LAST > NextOpType::SIZE, "inconsistent array positions");

View file

@ -154,7 +154,10 @@ namespace MultiArrayTools
friend OperationClass; friend OperationClass;
}; };
typedef struct v256 { alignas(32) double _x[4]; } v256; struct v256
{
alignas(32) double _x[4];
};
template <int N> template <int N>
inline void xadd(double* o, const double* a, const double* b) inline void xadd(double* o, const double* a, const double* b)
@ -173,16 +176,16 @@ namespace MultiArrayTools
o[i] += a[i]; o[i] += a[i];
} }
} }
inline v256 operator+(const v256& a, const v256& b) inline v256 operator+(v256 a, v256 b)
{ {
alignas(32) v256 o; v256 o;
xadd<4>( reinterpret_cast<double*>(&o), reinterpret_cast<const double*>(&a), xadd<4>( reinterpret_cast<double*>(&o), reinterpret_cast<const double*>(&a),
reinterpret_cast<const double*>(&b) ); reinterpret_cast<const double*>(&b) );
return o; return o;
} }
inline v256& operator+=(v256& o, const v256& a) inline v256& operator+=(v256& o, v256 a)
{ {
xsadd<4>( reinterpret_cast<double*>(&o), reinterpret_cast<const double*>(&a) ); xsadd<4>( reinterpret_cast<double*>(&o), reinterpret_cast<const double*>(&a) );
return o; return o;
@ -190,7 +193,7 @@ namespace MultiArrayTools
/* /*
inline v256 operator-(const v256& a, const v256& b) inline v256 operator-(const v256& a, const v256& b)
{ {
alignas(32) v256 out; v256 out;
#pragma omp simd aligned(outp, ap, bp: 32) #pragma omp simd aligned(outp, ap, bp: 32)
for(int i = 0; i < IN; ++i){ for(int i = 0; i < IN; ++i){
outp[i] = ap[i] - bp[i]; outp[i] = ap[i] - bp[i];
@ -200,7 +203,7 @@ namespace MultiArrayTools
inline v256 operator*(const v256& a, const v256& b) inline v256 operator*(const v256& a, const v256& b)
{ {
alignas(32) v256 out; v256 out;
#pragma omp simd aligned(outp, ap, bp: 32) #pragma omp simd aligned(outp, ap, bp: 32)
for(int i = 0; i < IN; ++i){ for(int i = 0; i < IN; ++i){
outp[i] = ap[i] * bp[i]; outp[i] = ap[i] * bp[i];
@ -210,7 +213,7 @@ namespace MultiArrayTools
inline v256 operator/(const v256& a, const v256& b) inline v256 operator/(const v256& a, const v256& b)
{ {
alignas(32) v256 out; v256 out;
#pragma omp simd aligned(outp, ap, bp: 32) #pragma omp simd aligned(outp, ap, bp: 32)
for(int i = 0; i < IN; ++i){ for(int i = 0; i < IN; ++i){
outp[i] = ap[i] / bp[i]; outp[i] = ap[i] / bp[i];

View file

@ -35,8 +35,8 @@ namespace MultiArrayHelper
ExpressionBase& operator=(const ExpressionBase& in) = default; ExpressionBase& operator=(const ExpressionBase& in) = default;
ExpressionBase& operator=(ExpressionBase&& in) = default; ExpressionBase& operator=(ExpressionBase&& in) = default;
virtual void operator()(size_t mlast, DExt last) const = 0; virtual void operator()(size_t mlast, DExt last) = 0;
virtual void operator()(size_t mlast = 0) const = 0; virtual void operator()(size_t mlast = 0) = 0;
virtual DExt dRootSteps(std::intptr_t iPtrNum = 0) const = 0; virtual DExt dRootSteps(std::intptr_t iPtrNum = 0) const = 0;
virtual DExt dExtension() const = 0; virtual DExt dExtension() const = 0;
@ -127,9 +127,9 @@ namespace MultiArrayHelper
Expr expr); Expr expr);
inline void operator()(size_t mlast, DExt last) const override final; inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) const; inline void operator()(size_t mlast, ExtType last);
inline void operator()(size_t mlast = 0) const override final; inline void operator()(size_t mlast = 0) override final;
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
DExt dExtension() const override final; DExt dExtension() const override final;
@ -176,9 +176,9 @@ namespace MultiArrayHelper
const vector<size_t>* subset, Expr expr); const vector<size_t>* subset, Expr expr);
inline void operator()(size_t mlast, DExt last) const override final; inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) const; inline void operator()(size_t mlast, ExtType last) ;
inline void operator()(size_t mlast = 0) const override final; inline void operator()(size_t mlast = 0) override final;
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
DExt dExtension() const override final; DExt dExtension() const override final;
@ -224,9 +224,9 @@ namespace MultiArrayHelper
For(const IndexClass* indPtr, For(const IndexClass* indPtr,
size_t step, Expr expr); size_t step, Expr expr);
inline void operator()(size_t mlast, DExt last) const override final; inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) const; inline void operator()(size_t mlast, ExtType last) ;
inline void operator()(size_t mlast = 0) const override final; inline void operator()(size_t mlast = 0) override final;
PFor<IndexClass,Expr> parallel() const; PFor<IndexClass,Expr> parallel() const;
@ -272,9 +272,9 @@ namespace MultiArrayHelper
PFor(const IndexClass* indPtr, PFor(const IndexClass* indPtr,
size_t step, Expr expr); size_t step, Expr expr);
inline void operator()(size_t mlast, DExt last) const override final; inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) const; inline void operator()(size_t mlast, ExtType last) ;
inline void operator()(size_t mlast = 0) const override final; inline void operator()(size_t mlast = 0) override final;
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
DExt dExtension() const override final; DExt dExtension() const override final;
@ -311,8 +311,8 @@ namespace MultiArrayHelper
template <class Expr> template <class Expr>
DynamicExpression(Expr ex) : mNext( std::make_shared<Expr>(ex) ) {} DynamicExpression(Expr ex) : mNext( std::make_shared<Expr>(ex) ) {}
inline void operator()(size_t mlast, DExt last) const override final; inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast = 0) const override final; inline void operator()(size_t mlast = 0) override final;
inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
inline DExt dExtension() const override final; inline DExt dExtension() const override final;
@ -345,9 +345,9 @@ namespace MultiArrayHelper
ExpressionHolder(DynamicExpression expr); ExpressionHolder(DynamicExpression expr);
inline void operator()(size_t mlast, DExt last) const override final; inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) const; inline void operator()(size_t mlast, ExtType last) ;
inline void operator()(size_t mlast = 0) const override final; inline void operator()(size_t mlast = 0) override final;
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
DExt dExtension() const override final; DExt dExtension() const override final;
@ -391,14 +391,14 @@ 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, DExt last) const inline void For<IndexClass,Expr,FT>::operator()(size_t mlast, DExt last)
{ {
operator()(mlast, *reinterpret_cast<ExtType const*>(last.first)); operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
} }
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,
ExtType last) const ExtType last)
{ {
typedef typename IndexClass::RangeType RangeType; typedef typename IndexClass::RangeType RangeType;
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE>(mMax); ++pos){ for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE>(mMax); ++pos){
@ -411,7 +411,7 @@ 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)
{ {
typedef typename IndexClass::RangeType RangeType; typedef typename IndexClass::RangeType RangeType;
const ExtType last; const ExtType last;
@ -484,14 +484,14 @@ namespace MultiArrayHelper
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void PFor<IndexClass,Expr>::operator()(size_t mlast, DExt last) const inline void PFor<IndexClass,Expr>::operator()(size_t mlast, DExt last)
{ {
operator()(mlast, *reinterpret_cast<ExtType const*>(last.first)); operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void PFor<IndexClass,Expr>::operator()(size_t mlast, inline void PFor<IndexClass,Expr>::operator()(size_t mlast,
ExtType last) const ExtType last)
{ {
CHECK; CHECK;
typedef typename IndexClass::RangeType RangeType; typedef typename IndexClass::RangeType RangeType;
@ -511,7 +511,7 @@ namespace MultiArrayHelper
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void PFor<IndexClass,Expr>::operator()(size_t mlast) const inline void PFor<IndexClass,Expr>::operator()(size_t mlast)
{ {
CHECK; CHECK;
typedef typename IndexClass::RangeType RangeType; typedef typename IndexClass::RangeType RangeType;
@ -588,14 +588,14 @@ namespace MultiArrayHelper
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast, DExt last) const inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast, DExt last)
{ {
operator()(mlast, *reinterpret_cast<ExtType const*>(last.first)); operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast, inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast,
ExtType last) const ExtType last)
{ {
//typedef typename IndexClass::RangeType RangeType; //typedef typename IndexClass::RangeType RangeType;
const size_t pos = mIndPtr->pos(); const size_t pos = mIndPtr->pos();
@ -605,7 +605,7 @@ namespace MultiArrayHelper
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast) const inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast)
{ {
//typedef typename IndexClass::RangeType RangeType; //typedef typename IndexClass::RangeType RangeType;
const ExtType last; const ExtType last;
@ -672,14 +672,14 @@ namespace MultiArrayHelper
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast, DExt last) const inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast, DExt last)
{ {
operator()(mlast, *reinterpret_cast<ExtType const*>(last.first)); operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast, inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast,
ExtType last) const ExtType last)
{ {
const size_t pos = (*mSubSet)[last.val()]; const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast; const size_t mnpos = mlast;
@ -688,7 +688,7 @@ namespace MultiArrayHelper
} }
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast) const inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast)
{ {
const ExtType last; const ExtType last;
const size_t pos = (*mSubSet)[last.val()]; const size_t pos = (*mSubSet)[last.val()];
@ -731,12 +731,12 @@ namespace MultiArrayHelper
* DynamicExpression * * DynamicExpression *
***************************/ ***************************/
inline void DynamicExpression::operator()(size_t mlast, DExt last) const inline void DynamicExpression::operator()(size_t mlast, DExt last)
{ {
(*mNext)(mlast,last); (*mNext)(mlast,last);
} }
inline void DynamicExpression::operator()(size_t mlast) const inline void DynamicExpression::operator()(size_t mlast)
{ {
(*mNext)(mlast); (*mNext)(mlast);
} }
@ -759,13 +759,13 @@ namespace MultiArrayHelper
ExpressionHolder<Expr>::ExpressionHolder(DynamicExpression expr) : mExpr(expr) {} ExpressionHolder<Expr>::ExpressionHolder(DynamicExpression expr) : mExpr(expr) {}
template <class Expr> template <class Expr>
inline void ExpressionHolder<Expr>::operator()(size_t mlast, DExt last) const inline void ExpressionHolder<Expr>::operator()(size_t mlast, DExt last)
{ {
mExpr(mlast,last); mExpr(mlast,last);
} }
template <class Expr> template <class Expr>
inline void ExpressionHolder<Expr>::operator()(size_t mlast, ExtType last) const inline void ExpressionHolder<Expr>::operator()(size_t mlast, ExtType last)
{ {
mExpr(mlast, mExpr(mlast,
std::make_pair<size_t const*,size_t> std::make_pair<size_t const*,size_t>
@ -774,7 +774,7 @@ namespace MultiArrayHelper
} }
template <class Expr> template <class Expr>
inline void ExpressionHolder<Expr>::operator()(size_t mlast) const inline void ExpressionHolder<Expr>::operator()(size_t mlast)
{ {
mExpr(mlast); mExpr(mlast);
} }