diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index b875a63..5bdbf44 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -31,7 +31,7 @@ namespace MultiArrayTools template struct plus { - static T&& apply(T&& a1, T&& a2) + static T apply(const T& a1, const T& a2) { return a1 + a2; } @@ -40,7 +40,7 @@ namespace MultiArrayTools template struct minus { - static T&& apply(T&& a1, T&& a2) + static T apply(const T& a1, const T& a2) { return a1 - a2; } @@ -49,7 +49,7 @@ namespace MultiArrayTools template struct multiplies { - static T&& apply(T&& a1, T&& a2) + static T apply(const T& a1, const T& a2) { return a1 * a2; } @@ -58,7 +58,7 @@ namespace MultiArrayTools template struct divides { - static T&& apply(T&& a1, T&& a2) + static T apply(const T& a1, const T& a2) { return a1 / a2; } @@ -350,7 +350,7 @@ namespace MultiArrayTools const BlockResult& get() const; template - inline T&& get(const ET& pos) const; + inline T get(const ET& pos) const; std::vector block(const IndexInfo* blockIndex, bool init = false) const; const Operation& block() const; @@ -390,7 +390,7 @@ namespace MultiArrayTools const BlockResult& get() const; template - inline T&& get(const ET& pos) const; + inline T get(const ET& pos) const; std::vector block(const IndexInfo* blockIndex, bool init = false) const; const Contraction& block() const; @@ -527,7 +527,7 @@ namespace MultiArrayTools inline void OperationMaster::AssignmentExpr:: operator()(size_t start, const ETuple& last) { - mM.get(start) = mSec.template get(last); + mM.get(start) = mSec.template get(last); } template @@ -622,12 +622,14 @@ namespace MultiArrayTools template T& OperationMaster::get(size_t pos) { + VCHECK(pos); return mData[pos]; } template const T& OperationMaster::get(size_t pos) const { + VCHECK(pos); return mData[pos]; } @@ -840,11 +842,11 @@ namespace MultiArrayTools template template - inline T&& Operation::get(const ET& pos) const + inline T Operation::get(const ET& pos) const { typedef std::tuple OpTuple; - return std::forward( PackNum:: - template mkOpExpr(pos, mOps) ); + return PackNum:: + template mkOpExpr(pos, mOps); } template @@ -908,9 +910,9 @@ namespace MultiArrayTools // forward loop !!!! template template - inline T&& Contraction::get(const ET& pos) const + inline T Contraction::get(const ET& pos) const { - return std::forward( mOp.template get(pos) ); + return mOp.template get(pos); } template diff --git a/src/pack_num.h b/src/pack_num.h index 4e585f3..e0cc991 100644 --- a/src/pack_num.h +++ b/src/pack_num.h @@ -68,12 +68,13 @@ namespace MultiArrayHelper // call with -2 (instead of -1) template - static T&& mkOpExpr(const ETuple& pos, const OpTuple& ops) + static T mkOpExpr(const ETuple& pos, const OpTuple& ops) { - static const size_t NEXT = START - std::tuple_element::type::SIZE; - return std::forward - ( OpFunction::apply( std::get(ops).template get(pos), - PackNum::template mkOpExpr(pos, ops) ) ); + typedef typename std::tuple_element::type SubOpTypeRef; + typedef typename std::remove_reference::type SubOpType; + static const size_t NEXT = START - SubOpType::SIZE; + return OpFunction::apply( std::get(ops).template get(pos), + PackNum::template mkOpExpr(pos, ops) ); } template @@ -137,12 +138,13 @@ namespace MultiArrayHelper } template - static T&& mkOpExpr(const ETuple& pos, const OpTuple& ops) + static T mkOpExpr(const ETuple& pos, const OpTuple& ops) { - static const size_t NEXT = START - std::tuple_element<1,OpTuple>::type::SIZE; - return std::forward - ( OpFunction::apply( std::get<1>(ops).template get(pos), - std::get<0>(ops).template get(pos) ) ); + typedef typename std::tuple_element<1,OpTuple>::type SubOpTypeRef; + typedef typename std::remove_reference::type SubOpType; + static const size_t NEXT = START - SubOpType::SIZE; + return OpFunction::apply( std::get<1>(ops).template get(pos), + std::get<0>(ops).template get(pos) ); } template diff --git a/src/ranges/container_range.h b/src/ranges/container_range.h index 249b512..4998e59 100644 --- a/src/ranges/container_range.h +++ b/src/ranges/container_range.h @@ -86,7 +86,7 @@ namespace MultiArrayTools std::vector infoVec() const; - std::string id(); + std::string id() const; void print(size_t offset); template @@ -354,7 +354,7 @@ namespace MultiArrayTools } template - std::string ContainerIndex::id() + std::string ContainerIndex::id() const { return std::string("con") + std::to_string(IB::mId); } diff --git a/src/ranges/multi_range.h b/src/ranges/multi_range.h index 8be899c..cc55e8b 100644 --- a/src/ranges/multi_range.h +++ b/src/ranges/multi_range.h @@ -102,7 +102,7 @@ namespace MultiArrayTools std::vector infoVec() const; - std::string id(); + std::string id() const; void print(size_t offset); template @@ -398,7 +398,7 @@ namespace MultiArrayTools } template - std::string MultiIndex::id() + std::string MultiIndex::id() const { return std::string("mul") + std::to_string(IB::mId); } diff --git a/src/ranges/single_range.h b/src/ranges/single_range.h index f7ac16d..be532e0 100644 --- a/src/ranges/single_range.h +++ b/src/ranges/single_range.h @@ -62,7 +62,7 @@ namespace MultiArrayTools std::vector infoVec() const; - std::string id(); + std::string id() const; void print(size_t offset); template @@ -232,7 +232,7 @@ namespace MultiArrayTools } template - std::string SingleIndex::id() + std::string SingleIndex::id() const { return std::string("sin") + std::to_string(IB::mId); } diff --git a/src/xfor/xfor.h b/src/xfor/xfor.h index f1dd6ff..6fb3412 100644 --- a/src/xfor/xfor.h +++ b/src/xfor/xfor.h @@ -9,6 +9,9 @@ namespace MultiArrayHelper { + + // 'HIDDEN FOR' CLASS for nested for loops in contractions a.s.o. + // (NO COUNTING OF MASTER POSITION !!!!!) template class For @@ -60,6 +63,8 @@ namespace MultiArrayHelper * --- TEMPLATE CODE --- * * ========================= */ +#include + namespace MultiArrayHelper { @@ -67,19 +72,20 @@ namespace MultiArrayHelper For::For(const std::shared_ptr& indPtr, Expr&& expr) : mIndPtr(indPtr.get()), mExpr(expr), - mExt(expr.rootSteps( reinterpret_cast( mIndPtr.get() ))) {} + mExt(expr.rootSteps( reinterpret_cast( mIndPtr.get() ))) { assert(mIndPtr != nullptr); } template For::For(const IndexClass* indPtr, Expr&& expr) : mIndPtr(indPtr), mExpr(std::forward( expr )), - mExt(expr.rootSteps( reinterpret_cast( mIndPtr ) )) {} + mExt(expr.rootSteps( reinterpret_cast( mIndPtr ) )) { assert(mIndPtr != nullptr); } template inline void For::operator()(size_t mlast, const ETuple& last) const { auto& ind = *mIndPtr; + std::cout << mIndPtr << std::endl; const size_t max = ind.max(); // blocking for(size_t pos = ind.pos(); pos != max; ++pos){ const size_t mnpos = mlast * max + pos; @@ -93,6 +99,7 @@ namespace MultiArrayHelper { const ETuple last; auto& ind = *mIndPtr; + std::cout << mIndPtr << std::endl; const size_t max = ind.max(); // blocking for(size_t pos = ind.pos(); pos != max; ++pos){ const size_t mnpos = mlast * max + pos;