This commit is contained in:
Christian Zimmermann 2018-02-13 15:38:03 +01:00
parent 87a699a445
commit 4d8d4d31f6
4 changed files with 139 additions and 114 deletions

View file

@ -12,7 +12,7 @@
#include "base_def.h" #include "base_def.h"
#include "mbase_def.h" #include "mbase_def.h"
#include "block/block.h" //#include "block/block.h"
#include "operation_utils.h" #include "operation_utils.h"
#include "ranges/rheader.h" #include "ranges/rheader.h"
#include "pack_num.h" #include "pack_num.h"
@ -105,8 +105,8 @@ namespace MultiArrayTools
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) const;
inline void operator()(size_t start, ExtType last); inline void operator()(size_t start, ExtType last) const;
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
@ -127,14 +127,15 @@ namespace MultiArrayTools
std::shared_ptr<typename CRange::IndexType>& index, std::shared_ptr<typename CRange::IndexType>& index,
const IndexInfo* blockIndex); const IndexInfo* blockIndex);
MBlock<T>& get(); //MBlock<T>& get();
const Block<T>& get() const; //const Block<T>& get() const;
inline T& get(size_t pos); inline void set(size_t pos, T val) { mDataPtr[pos] = val };
inline T get(size_t pos);
inline const T& get(size_t pos) const; inline const T& get(size_t pos) const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; //std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const OperationMaster& block() const; //const OperationMaster& block() const;
private: private:
@ -142,7 +143,7 @@ namespace MultiArrayTools
void performAssignment(std::intptr_t blockIndexNum); void performAssignment(std::intptr_t blockIndexNum);
OpClass const& mSecond; OpClass const& mSecond;
MutableMultiArrayBase<T,Ranges...>& mArrayRef; MutableMultiArrayBase<T,Ranges...>& mArrayRef;
std::vector<T>& mData; T* mDataPtr;
std::shared_ptr<IndexType> mIndex; std::shared_ptr<IndexType> mIndex;
IndexInfo mIInfo; IndexInfo mIInfo;
mutable bType mBlock; mutable bType mBlock;
@ -168,15 +169,15 @@ 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);
const Block<T>& get() const; //const Block<T>& get() const;
template <class ET> template <class ET>
inline const T& get(const ET& pos) const; inline const T& get(const ET& pos) const;
//std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
//const ConstOperationRoot& block() const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; MExt<void> rootSteps(std::intptr_t iPtrNum = 0) const; // nullptr for simple usage with decltype
const ConstOperationRoot& block() const;
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;
@ -188,10 +189,10 @@ namespace MultiArrayTools
const std::shared_ptr<typename Ranges::IndexType>&... indices); const std::shared_ptr<typename Ranges::IndexType>&... indices);
MultiArrayBase<T,Ranges...> const& mArrayRef; MultiArrayBase<T,Ranges...> const& mArrayRef;
const std::vector<T>& mData; const T* mDataPtr;
std::shared_ptr<IndexType> mIndex; std::shared_ptr<IndexType> mIndex;
IndexInfo mIInfo; IndexInfo mIInfo;
mutable bType mBlock; //mutable bType mBlock;
}; };
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -215,8 +216,8 @@ namespace MultiArrayTools
template <class OpClass> template <class OpClass>
OperationMaster<T,OpClass,Ranges...> operator=(const OpClass& in); OperationMaster<T,OpClass,Ranges...> operator=(const OpClass& in);
const MBlock<T>& get() const; //const MBlock<T>& get() const;
MBlock<T>& get(); //MBlock<T>& get();
template <class ET> template <class ET>
inline const T& get(const ET& pos) const; inline const T& get(const ET& pos) const;
@ -224,11 +225,11 @@ namespace MultiArrayTools
template <class ET> template <class ET>
inline T& get(const ET& pos); inline T& get(const ET& pos);
OperationRoot& set(const IndexInfo* blockIndex); //OperationRoot& set(const IndexInfo* blockIndex);
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; //std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const OperationRoot& block() const; //const OperationRoot& block() const;
std::tuple<size_t> 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
template <class Expr> template <class Expr>
Expr loop(Expr exp) const; Expr loop(Expr exp) const;
@ -240,11 +241,11 @@ namespace MultiArrayTools
const std::shared_ptr<typename Ranges::IndexType>&... indices); const std::shared_ptr<typename Ranges::IndexType>&... indices);
MutableMultiArrayBase<T,Ranges...>& mArrayRef; MutableMultiArrayBase<T,Ranges...>& mArrayRef;
std::vector<T>& mData; T* mDataPtr;
std::shared_ptr<IndexType> mIndex; std::shared_ptr<IndexType> mIndex;
IndexInfo mIInfo; IndexInfo mIInfo;
mutable bType mBlock; //mutable bType mBlock;
const IndexInfo* mBlockII; // predefine to save time //const IndexInfo* mBlockII; // predefine to save time
}; };
template <class Op> template <class Op>
@ -265,7 +266,7 @@ namespace MultiArrayTools
template <class Op1, class... Ops> template <class Op1, class... Ops>
struct rs struct rs
{ {
static const size_t SIZE = Op1::SIZE + RootSumN<N-1>::template rs<Ops...>::SIZE; static constexpr size_t SIZE = Op1::SIZE + RootSumN<N-1>::template rs<Ops...>::SIZE;
}; };
}; };
@ -275,7 +276,7 @@ namespace MultiArrayTools
template <class Op1> template <class Op1>
struct rs struct rs
{ {
static const size_t SIZE = Op1::SIZE; static constexpr size_t SIZE = Op1::SIZE;
}; };
}; };
@ -283,7 +284,7 @@ namespace MultiArrayTools
template <class... Ops> template <class... Ops>
struct RootSum struct RootSum
{ {
static const size_t SIZE = RootSumN<sizeof...(Ops)-1>::template rs<Ops...>::SIZE; static constexpr size_t SIZE = RootSumN<sizeof...(Ops)-1>::template rs<Ops...>::SIZE;
}; };
@ -299,28 +300,28 @@ namespace MultiArrayTools
typedef BlockResult<T> bType; typedef BlockResult<T> bType;
static size_t rootNum() { return sumRootNum<Ops...>(); } static size_t rootNum() { return sumRootNum<Ops...>(); }
static const size_t SIZE = RootSum<Ops...>::SIZE; static constexpr size_t SIZE = RootSum<Ops...>::SIZE;
private: private:
std::tuple<Ops const&...> mOps; std::tuple<Ops...> mOps;
mutable bType mRes; mutable bType mRes;
public: public:
typedef decltype(PackNum<sizeof...(Ops)-1>::mkStepTuple(0, mOps)) ETuple; typedef decltype(PackNum<sizeof...(Ops)-1>::mkSteps(0, mOps)) ETuple;
//typedef decltype(PackNum<sizeof...(Ops)-1>::template mkLoopType<Ops...>) LType; //typedef decltype(PackNum<sizeof...(Ops)-1>::template mkLoopType<Ops...>) LType;
Operation(const Ops&... ops); Operation(const Ops&... ops);
const BlockResult<T>& get() const; //const BlockResult<T>& get() const;
template <class ET, size_t SITE> template <class ET>
inline T get(const ET& pos) const; inline T get(const ET& pos) const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; //std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const Operation& block() const; //const Operation& block() const;
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>::mkStepTuple(iPtrNum, mOps)); -> decltype(PackNum<sizeof...(Ops)-1>::mkSteps(iPtrNum, mOps));
template <class Expr> template <class Expr>
auto loop(Expr exp) const auto loop(Expr exp) const
@ -351,13 +352,13 @@ namespace MultiArrayTools
Contraction(const Op& op, std::shared_ptr<IndexType> ind); Contraction(const Op& op, std::shared_ptr<IndexType> ind);
const BlockResult<T>& get() const; //const BlockResult<T>& get() const;
template <class ET, size_t SITE> template <class ET>
inline T get(const ET& pos) const; inline T get(const ET& pos) const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const; //std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const Contraction& block() const; //const Contraction& block() const;
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));
@ -489,9 +490,9 @@ 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, ExtType last) operator()(size_t start, ExtType last) const
{ {
mM.get(start) = mSec.template get<ExtType,OpClass::SIZE-1>(last); mM.get(start) += mSec.template get<ExtType>(last);
} }
template <typename T, class OpClass, class... Ranges> template <typename T, class OpClass, class... Ranges>
@ -511,16 +512,16 @@ namespace MultiArrayTools
OperationMaster<T,OpClass,Ranges...>:: OperationMaster<T,OpClass,Ranges...>::
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second, OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index) : std::shared_ptr<typename CRange::IndexType>& index) :
mSecond(second), mArrayRef(ma), mData(mArrayRef.datav()), mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex(mkIndex(index)), mIInfo(*mIndex) mIndex(mkIndex(index)), mIInfo(*mIndex)
{ {
auto blockIndex = seekBlockIndex( &mIInfo, second); //auto blockIndex = seekBlockIndex( &mIInfo, second);
std::intptr_t blockIndexNum = blockIndex->getPtrNum(); //std::intptr_t blockIndexNum = blockIndex->getPtrNum();
block(blockIndex, true); //block(blockIndex, true);
second.block(blockIndex, true); //second.block(blockIndex, true);
performAssignment(blockIndexNum); performAssignment(0);
} }
template <typename T, class OpClass, class... Ranges> template <typename T, class OpClass, class... Ranges>
@ -528,13 +529,13 @@ namespace MultiArrayTools
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second, OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index, std::shared_ptr<typename CRange::IndexType>& index,
const IndexInfo* blockIndex) : const IndexInfo* blockIndex) :
mSecond(second), mArrayRef(ma), mData(mArrayRef.datav()), mSecond(second), mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex(mkIndex(index)), mIInfo(*mIndex) mIndex(mkIndex(index)), mIInfo(*mIndex)
{ {
std::intptr_t blockIndexNum = blockIndex->getPtrNum(); //std::intptr_t blockIndexNum = blockIndex->getPtrNum();
second.block(blockIndex, true); //second.block(blockIndex, true);
performAssignment(blockIndexNum); performAssignment(0);
} }
template <typename T, class OpClass, class... Ranges> template <typename T, class OpClass, class... Ranges>
@ -558,7 +559,7 @@ namespace MultiArrayTools
// === N E W === // === N E W ===
AssignmentExpr ae(*this, mSecond); // Expression to be executed within loop AssignmentExpr ae(*this, mSecond); // Expression to be executed within loop
//const auto hiddenLoop = mSecond.loop(AssignmentExpr(*this, mSecond)); // hidden loop within 'mSecond' e.g. contractions //const auto hiddenLoop = mSecond.loop(AssignmentExpr(*this, mSecond)); // hidden loop within 'mSecond' e.g. contractions
const auto loop = mIndex->ifor auto loop = mIndex->ifor
( mSecond.template loop<AssignmentExpr> ( mSecond.template loop<AssignmentExpr>
( std::move(ae) ) ); // init overall loop(s) ( std::move(ae) ) ); // init overall loop(s)
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
@ -570,7 +571,7 @@ namespace MultiArrayTools
} }
#endif #endif
} }
/*
template <typename T, class OpClass, class... Ranges> template <typename T, class OpClass, class... Ranges>
MBlock<T>& OperationMaster<T,OpClass,Ranges...>::get() MBlock<T>& OperationMaster<T,OpClass,Ranges...>::get()
{ {
@ -582,23 +583,23 @@ namespace MultiArrayTools
{ {
return mBlock; return mBlock;
} }
*/
template <typename T, class OpClass, class... Ranges> template <typename T, class OpClass, class... Ranges>
inline T& OperationMaster<T,OpClass,Ranges...>::get(size_t pos) inline T& OperationMaster<T,OpClass,Ranges...>::get(size_t pos)
{ {
//assert(pos < mIndex->max()); //assert(pos < mIndex->max());
//if(pos >= mIndex->max()) { VCHECK(pos); VCHECK(mIndex->max()); assert(0); } //if(pos >= mIndex->max()) { VCHECK(pos); VCHECK(mIndex->max()); assert(0); }
//VCHECK(pos); //VCHECK(pos);
return mData[pos]; return mDataPtr[pos];
} }
template <typename T, class OpClass, class... Ranges> template <typename T, class OpClass, class... Ranges>
inline const T& OperationMaster<T,OpClass,Ranges...>::get(size_t pos) const inline const T& OperationMaster<T,OpClass,Ranges...>::get(size_t pos) const
{ {
//VCHECK(pos); //VCHECK(pos);
return mData[pos]; return mDataPtr[pos];
} }
/*
template <typename T, class OpClass, class... Ranges> template <typename T, class OpClass, class... Ranges>
std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -616,7 +617,7 @@ namespace MultiArrayTools
mBlock.set( mIndex->pos() ); mBlock.set( mIndex->pos() );
return *this; return *this;
} }
*/
/**************************** /****************************
* ConstOperationRoot * * ConstOperationRoot *
@ -627,7 +628,7 @@ 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) :
//OperationTemplate<T,ConstOperationRoot<T,Ranges...> >(this), //OperationTemplate<T,ConstOperationRoot<T,Ranges...> >(this),
mArrayRef(ma), mData(mArrayRef.datav()), mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex) mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex)
{} {}
@ -641,21 +642,21 @@ namespace MultiArrayTools
(*mIndex)(indices...); (*mIndex)(indices...);
return i; return i;
} }
/*
template <typename T, class... Ranges> template <typename T, class... Ranges>
const Block<T>& ConstOperationRoot<T,Ranges...>::get() const const Block<T>& ConstOperationRoot<T,Ranges...>::get() const
{ {
block(); block();
return mBlock; return mBlock;
} }
*/
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class ET> template <class ET>
inline const T& ConstOperationRoot<T,Ranges...>::get(const ET& pos) const inline const T& ConstOperationRoot<T,Ranges...>::get(const ET& pos) const
{ {
return mData[pos.val()]; return mDataPtr[pos.val()];
} }
/*
template <typename T, class... Ranges> template <typename T, class... Ranges>
std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -672,11 +673,11 @@ namespace MultiArrayTools
mBlock.set( (*mIndex)().pos() ); mBlock.set( (*mIndex)().pos() );
return *this; return *this;
} }
*/
template <typename T, class... Ranges> template <typename T, class... Ranges>
std::tuple<size_t> ConstOperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const MExt<void> ConstOperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{ {
return std::tuple<size_t>(0ul); // !!!!!! return MExt<void>(0u); // !!!!!!
} }
@ -696,9 +697,9 @@ 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) :
//OperationTemplate<T,OperationRoot<T,Ranges...> >(this), //OperationTemplate<T,OperationRoot<T,Ranges...> >(this),
mArrayRef(ma), mData(mArrayRef.datav()), mArrayRef(ma), mDataPtr(mArrayRef.data()),
mIndex( mkIndex( ma, indices... ) ), mIInfo(*mIndex), mIndex( mkIndex( ma, indices... ) ), mIInfo(*mIndex)
mBlockII(nullptr) //mBlockII(nullptr)
{} {}
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -716,14 +717,14 @@ namespace MultiArrayTools
template <class OpClass> template <class OpClass>
OperationMaster<T,OpClass,Ranges...> OperationRoot<T,Ranges...>::operator=(const OpClass& in) OperationMaster<T,OpClass,Ranges...> OperationRoot<T,Ranges...>::operator=(const OpClass& in)
{ {
if(mBlockII != nullptr){ //if(mBlockII != nullptr){
return OperationMaster<T,OpClass,Ranges...>(mArrayRef, in, mIndex, mBlockII); // return OperationMaster<T,OpClass,Ranges...>(mArrayRef, in, mIndex, mBlockII);
} //}
else { //else {
return OperationMaster<T,OpClass,Ranges...>(mArrayRef, in, mIndex); return OperationMaster<T,OpClass,Ranges...>(mArrayRef, in, mIndex);
} //}
} }
/*
template <typename T, class... Ranges> template <typename T, class... Ranges>
const MBlock<T>& OperationRoot<T,Ranges...>::get() const const MBlock<T>& OperationRoot<T,Ranges...>::get() const
{ {
@ -737,21 +738,21 @@ namespace MultiArrayTools
block(); block();
return mBlock; return mBlock;
} }
*/
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class ET> template <class ET>
inline const T& OperationRoot<T,Ranges...>::get(const ET& pos) const inline const T& OperationRoot<T,Ranges...>::get(const ET& pos) const
{ {
return mData[pos.val()]; return mDataPtr[pos.val()];
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
template <class ET> template <class ET>
inline T& OperationRoot<T,Ranges...>::get(const ET& pos) inline T& OperationRoot<T,Ranges...>::get(const ET& pos)
{ {
return mData[pos.val()]; return mDataPtr[pos.val()];
} }
/*
template <typename T, class... Ranges> template <typename T, class... Ranges>
OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>&
OperationRoot<T,Ranges...>::set(const IndexInfo* blockIndex) OperationRoot<T,Ranges...>::set(const IndexInfo* blockIndex)
@ -759,7 +760,7 @@ namespace MultiArrayTools
mBlockII = blockIndex; mBlockII = blockIndex;
return *this; return *this;
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
std::vector<BTSS> OperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> OperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -776,11 +777,11 @@ namespace MultiArrayTools
mBlock.set( (*mIndex)().pos() ); mBlock.set( (*mIndex)().pos() );
return *this; return *this;
} }
*/
template <typename T, class... Ranges> template <typename T, class... Ranges>
std::tuple<size_t> OperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const MExt<void> OperationRoot<T,Ranges...>::rootSteps(std::intptr_t iPtrNum) const
{ {
return std::tuple<size_t>(0ul); // !!!!!! return MExt<void>(0u); // !!!!!!
} }
template <typename T, class... Ranges> template <typename T, class... Ranges>
@ -798,23 +799,23 @@ namespace MultiArrayTools
Operation<T,OpFunction,Ops...>::Operation(const Ops&... ops) : Operation<T,OpFunction,Ops...>::Operation(const Ops&... ops) :
//OperationTemplate<T,Operation<T,OpFunction,Ops...> >(this), //OperationTemplate<T,Operation<T,OpFunction,Ops...> >(this),
mOps(ops...) {} mOps(ops...) {}
/*
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
const BlockResult<T>& Operation<T,OpFunction,Ops...>::get() const const BlockResult<T>& Operation<T,OpFunction,Ops...>::get() const
{ {
PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mRes, mOps); PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mRes, mOps);
return mRes; return mRes;
} }
*/
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
template <class ET, size_t SITE> template <class ET>
inline T Operation<T,OpFunction,Ops...>::get(const ET& pos) const inline T Operation<T,OpFunction,Ops...>::get(const ET& pos) const
{ {
typedef std::tuple<Ops const&...> OpTuple; typedef std::tuple<Ops const&...> OpTuple;
return PackNum<sizeof...(Ops)-2>:: return PackNum<sizeof...(Ops)-1>::
template mkOpExpr<T,ET,OpTuple,OpFunction,SITE>(pos, mOps); template mkOpExpr<SIZE,T,ET,OpTuple,OpFunction>(pos, mOps);
} }
/*
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
std::vector<BTSS> Operation<T,OpFunction,Ops...>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> Operation<T,OpFunction,Ops...>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -833,12 +834,12 @@ namespace MultiArrayTools
//mBlock.set( mIndex->pos() ); //mBlock.set( mIndex->pos() );
return *this; return *this;
} }
*/
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
auto Operation<T,OpFunction,Ops...>::rootSteps(std::intptr_t iPtrNum) const auto Operation<T,OpFunction,Ops...>::rootSteps(std::intptr_t iPtrNum) const
-> decltype(PackNum<sizeof...(Ops)-1>::mkStepTuple(iPtrNum, mOps)) -> decltype(PackNum<sizeof...(Ops)-1>::mkSteps(iPtrNum, mOps))
{ {
return PackNum<sizeof...(Ops)-1>::mkStepTuple(iPtrNum, mOps); return PackNum<sizeof...(Ops)-1>::mkSteps(iPtrNum, mOps);
} }
template <typename T, class OpFunction, class... Ops> template <typename T, class OpFunction, class... Ops>
@ -859,7 +860,7 @@ namespace MultiArrayTools
//OperationTemplate<T,Contraction<T,Op,IndexType> >(this), //OperationTemplate<T,Contraction<T,Op,IndexType> >(this),
mOp(op), mOp(op),
mInd(ind) {} mInd(ind) {}
/*
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
const BlockResult<T>& Contraction<T,Op,IndexType>::get() const const BlockResult<T>& Contraction<T,Op,IndexType>::get() const
{ {
@ -869,15 +870,15 @@ namespace MultiArrayTools
} }
return mRes; return mRes;
} }
*/
// forward loop !!!! // forward loop !!!!
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
template <class ET, size_t SITE> template <class ET>
inline T Contraction<T,Op,IndexType>::get(const ET& pos) const inline T Contraction<T,Op,IndexType>::get(const ET& pos) const
{ {
return mOp.template get<ET,SITE>(pos); return mOp.template get<ET>(pos);
} }
/*
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
std::vector<BTSS> Contraction<T,Op,IndexType>::block(const IndexInfo* blockIndex, bool init) const std::vector<BTSS> Contraction<T,Op,IndexType>::block(const IndexInfo* blockIndex, bool init) const
{ {
@ -892,7 +893,7 @@ namespace MultiArrayTools
{ {
return *this; return *this;
} }
*/
template <typename T, class Op, class IndexType> template <typename T, class Op, class IndexType>
auto Contraction<T,Op,IndexType>::rootSteps(std::intptr_t iPtrNum) const auto Contraction<T,Op,IndexType>::rootSteps(std::intptr_t iPtrNum) const
-> decltype(mOp.rootSteps(iPtrNum)) -> decltype(mOp.rootSteps(iPtrNum))

View file

@ -14,6 +14,13 @@
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
{ {
@ -52,10 +59,10 @@ namespace MultiArrayHelper
} }
template <class... Ops> template <class... Ops>
static auto mkStepTuple(std::intptr_t ii, std::tuple<Ops const&...> otp) static auto mkSteps(std::intptr_t ii, const std::tuple<Ops const&...>& otp)
-> decltype(std::tuple_cat( PackNum<N-1>::mkStepTuple(ii, otp), std::get<N>(otp).rootSteps(ii) )) -> decltype(together(PackNum<N-1>::mkSteps(ii, otp), std::get<N>(otp).rootSteps(ii)))
{ {
return std::tuple_cat( PackNum<N-1>::mkStepTuple(ii, otp), std::get<N>(otp).rootSteps(ii) ); return together(PackNum<N-1>::mkSteps(ii, otp), std::get<N>(otp).rootSteps(ii) );
} }
template <class RootStepTuple, class IndexClass, class OpClass> template <class RootStepTuple, class IndexClass, class OpClass>
@ -67,13 +74,14 @@ namespace MultiArrayHelper
PackNum<N-1>::mkExt(out, siar, second); PackNum<N-1>::mkExt(out, siar, second);
} }
// call with -2 (instead of -1) template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
template <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)
{ {
typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType;
return PackNum<N-1>::template mkOpExpr<ETuple,OpTuple,OpFunction,decltype(std::get<N>(ops)),Args...> static_assert(LAST > NextOpType::SIZE, "inconsistent array positions");
( pos, ops, std::get<N>(ops).get(Getter<>::template get<ETuple>( pos )), args...); static constexpr size_t NEXT = LAST - NextOpType::SIZE;
return PackNum<N-1>::template mkOpExpr<NEXT,ETuple,OpTuple,OpFunction,decltype(std::get<N>(ops)),Args...>
( pos, ops, std::get<N>(ops).get(Getter<NEXT>::template get<ETuple>( pos )), args...);
} }
template <class OpTuple, class Expr> template <class OpTuple, class Expr>
@ -122,7 +130,7 @@ namespace MultiArrayHelper
} }
template <class... Ops> template <class... Ops>
static auto mkStepTuple(std::intptr_t ii, std::tuple<Ops const&...> otp) static auto mkSteps(std::intptr_t ii, const std::tuple<Ops const&...>& otp)
-> decltype(std::get<0>(otp).rootSteps(ii)) -> decltype(std::get<0>(otp).rootSteps(ii))
{ {
return std::get<0>(otp).rootSteps(ii); return std::get<0>(otp).rootSteps(ii);
@ -136,12 +144,11 @@ namespace MultiArrayHelper
std::get<0>(out) = second.rootSteps( std::get<0>(siar) ); std::get<0>(out) = second.rootSteps( std::get<0>(siar) );
} }
template <typename T, class ETuple, class OpTuple, class OpFunction, size_t START> template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops) static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args)
{ {
static constexpr size_t NEXT = START - SubOpType::SIZE; static_assert(LAST == 0, "inconsistent array positions");
return OpFunction::apply( std::get<1>(ops).template get<ETuple,START>(pos), return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template get<ETuple>( pos )), args...);
std::get<0>(ops).template get<ETuple,NEXT>(pos) );
} }
template <class OpTuple, class Expr> template <class OpTuple, class Expr>

View file

@ -26,7 +26,13 @@ namespace MultiArrayHelper
MExt& operator=(MExt&& in) = default; MExt& operator=(MExt&& in) = default;
inline MExt(size_t ext, X next); inline MExt(size_t ext, X next);
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);
@ -61,6 +67,7 @@ namespace MultiArrayHelper
inline MExt(const std::array<size_t,N>& arr); inline MExt(const std::array<size_t,N>& arr);
inline size_t val() const; inline size_t val() const;
inline size_t next() const { return 0; }
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;
@ -119,6 +126,16 @@ namespace MultiArrayHelper
inline MExt<X>::MExt(const std::array<size_t,N>& arr) : inline MExt<X>::MExt(const std::array<size_t,N>& arr) :
mExt(std::get<NUM>(arr)), mNext(arr) {} mExt(std::get<NUM>(arr)), mNext(arr) {}
template <class X>
template <class Z>
inline MExt<X>::MExt(size_t y, const Z& z) :
mExt(z.val()), mNext(z.val(), z.next()) {}
template <class X>
template <class Y, class Z>
inline MExt<X>::MExt(const Y& y, const Z& z) :
mExt(y.val()), mNext(y.next(), z) {}
template <class X> template <class X>
inline size_t MExt<X>::val() const inline size_t MExt<X>::val() const
{ {

View file

@ -116,7 +116,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, inline void For<IndexClass,Expr,FT>::operator()(size_t mlast,
const ExtType last) const ExtType last) const
{ {
for(size_t pos = mSPos; pos != mMax; ++pos){ for(size_t pos = mSPos; pos != mMax; ++pos){
const size_t mnpos = PosForward<FT>::value(mlast, mMax, pos); const size_t mnpos = PosForward<FT>::value(mlast, mMax, pos);