From bcc6b98882467a93bf98fff0da05546bfa7d0e47 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 13 Feb 2018 21:36:41 +0100 Subject: [PATCH] im com (re-enabling oputest) --- src/multi_array_operation.h | 6 ++--- src/pack_num.h | 4 ++-- src/ranges/index_base.h | 6 +++-- src/ranges/index_info.cc | 48 +++++++++++++++++++++++++++++++++++++ src/ranges/index_info.h | 10 +++++--- 5 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 52fb76b..88a7b79 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -254,7 +254,7 @@ namespace MultiArrayTools std::tuple mOps; public: - typedef decltype(PackNum::mkSteps(0, mOps)) ETuple; + typedef decltype(PackNum::template mkSteps(0, mOps)) ETuple; Operation(const Ops&... ops); @@ -469,7 +469,7 @@ namespace MultiArrayTools template MExt ConstOperationRoot::rootSteps(std::intptr_t iPtrNum) const { - return MExt(0u); // !!!!!! + return MExt(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); } @@ -520,7 +520,7 @@ namespace MultiArrayTools template MExt OperationRoot::rootSteps(std::intptr_t iPtrNum) const { - return MExt(0u); // !!!!!! + return MExt(getStepSize( getRootIndices( mIndex->info() ), iPtrNum )); } template diff --git a/src/pack_num.h b/src/pack_num.h index 303537a..9bf257b 100644 --- a/src/pack_num.h +++ b/src/pack_num.h @@ -59,7 +59,7 @@ namespace MultiArrayHelper } template - static auto mkSteps(std::intptr_t ii, const std::tuple& otp) + static auto mkSteps(std::intptr_t ii, const std::tuple& otp) -> decltype(together(PackNum::mkSteps(ii, otp), std::get(otp).rootSteps(ii))) { return together(PackNum::mkSteps(ii, otp), std::get(otp).rootSteps(ii) ); @@ -130,7 +130,7 @@ namespace MultiArrayHelper } template - static auto mkSteps(std::intptr_t ii, const std::tuple& otp) + static auto mkSteps(std::intptr_t ii, const std::tuple& otp) -> decltype(std::get<0>(otp).rootSteps(ii)) { return std::get<0>(otp).rootSteps(ii); diff --git a/src/ranges/index_base.h b/src/ranges/index_base.h index ab32ee3..99b6b0f 100644 --- a/src/ranges/index_base.h +++ b/src/ranges/index_base.h @@ -73,13 +73,15 @@ namespace MultiArrayTools void print(size_t offset = 0) const { THIS().print(offset); } + IndexInfo info() const { return IndexInfo(THIS()); } + // CHECK / IMPLEMENT !!!!!! template - auto ifor(const Expr&& ex) const -> decltype(THIS().template ifor(ex)) + auto ifor(const Expr ex) const -> decltype(THIS().template ifor(ex)) { return THIS().template ifor(ex); } template - auto iforh(const Expr&& ex) const -> decltype(THIS().template iforh(ex)) + auto iforh(const Expr ex) const -> decltype(THIS().template iforh(ex)) { return THIS().template iforh(ex); } private: diff --git a/src/ranges/index_info.cc b/src/ranges/index_info.cc index 824051f..e5372d9 100644 --- a/src/ranges/index_info.cc +++ b/src/ranges/index_info.cc @@ -70,5 +70,53 @@ namespace MultiArrayTools { return mType; } + + + std::vector getRootIndices(const IndexInfo& info) + { + std::vector out; + out.reserve(info.dim()); + + if(info.type() == IndexType::SINGLE){ + out.push_back(info); + } + else { + for(size_t i = 0; i != info.dim(); ++i){ + auto vv = getRootIndices(*info.getPtr(i)); + out.insert(out.end(), vv.begin(), vv.end()); + } + } + return out; + } + + size_t getStepSize(const std::vector& iv, const IndexInfo& 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& iv, std::intptr_t j) + { + size_t ss = 1; + auto ii = iv.end() - 1; + auto end = iv.begin(); + while(ii->getPtrNum() != j){ + ss *= ii->max(); + --ii; + if(ii == end){ + break; + } + } + return ss; + } } // end namespace MultiArrayTools diff --git a/src/ranges/index_info.h b/src/ranges/index_info.h index 93dc4ca..82f6743 100644 --- a/src/ranges/index_info.h +++ b/src/ranges/index_info.h @@ -20,8 +20,8 @@ namespace MultiArrayTools IndexInfo(IndexInfo&& in) = default; IndexInfo& operator=(IndexInfo&& in) = default; - //IndexInfo(const IndexInfo& in) = default; - //IndexInfo& operator=(const IndexInfo& in) = default; + IndexInfo(const IndexInfo& in) = default; + IndexInfo& operator=(const IndexInfo& in) = default; template IndexInfo(const IndexClass& ind, size_t stepSize = 1); @@ -76,7 +76,11 @@ namespace MultiArrayTools return *this; } - + std::vector getRootIndices(const IndexInfo& info); + + size_t getStepSize(const std::vector& iv, const IndexInfo& j); + + size_t getStepSize(const std::vector& iv, std::intptr_t j); } // end namespace MultiArrayTools #endif