From df2a8e5a0b0eb20d428bc0261ffb5592dbc3968f Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 22 Dec 2023 01:52:49 +0100 Subject: [PATCH] WIP: index reformat: mindex: do not copy single-indices --- src/include/ranges/index_base.cc.h | 12 ++++++++++++ src/include/ranges/index_base.h | 4 ++++ src/include/ranges/index_traits.h | 2 +- src/include/ranges/mrange.cc.h | 10 +++++----- src/include/ranges/yrange.h | 4 ++++ 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/include/ranges/index_base.cc.h b/src/include/ranges/index_base.cc.h index 41a7bd6..e9d5f2e 100644 --- a/src/include/ranges/index_base.cc.h +++ b/src/include/ranges/index_base.cc.h @@ -156,6 +156,18 @@ namespace CNORXZ static_assert(index_expression_exists::value, "expression for given index type does not exist"); return i->xpr(i); } + + template + decltype(auto) reformat(const Sptr& i, const Vector& f, const Vector& s) + { + if constexpr(has_sub::value){ + return moveToPtr( i->reformat(f,s) ); + } + else { + i->reformat(f,s); // checks + return i; + } + } } #endif diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index 14e0c2e..ef59ec7 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -233,6 +233,10 @@ namespace CNORXZ template decltype(auto) xpr(const Sptr& i); + + // do not copy single-indices: + template + decltype(auto) reformat(const Sptr& i, const Vector& f, const Vector& s); } #endif diff --git a/src/include/ranges/index_traits.h b/src/include/ranges/index_traits.h index 5f1f944..439337f 100644 --- a/src/include/ranges/index_traits.h +++ b/src/include/ranges/index_traits.h @@ -69,7 +69,7 @@ namespace CNORXZ { static constexpr bool value = false; }; /** ***** - check if given type is a statically multi-index-type + check if given type is a multi-index-type @tparam I type to be checked **/ diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 457cec1..621ce7b 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -550,11 +550,11 @@ namespace CNORXZ Arr nformat; auto npack = iter<0,NI>( [&](auto i) { SizeT si = 1; - //if(mIPack[i]->lmax().val() == 1){ - //std::get(npack) = mIPack[i]; - //} + if(mIPack[i]->lmax().val() == 1){ + //std::get(npack) = mIPack[i]; + return mIPack[i]; + } // CHECK!!! - // TODO: DO NOT COPY SINGLE INDEX INSTANCES!!! for(; si < mIPack[i]->lmax().val(); ++j){ si *= s[i]; CXZ_ASSERT(j < f.size(), "incompatible index formats"); @@ -569,7 +569,7 @@ namespace CNORXZ std::for_each(nf.begin(), nf.end(), [&](SizeT& x) { CXZ_ASSERT(x % nformat[i].val() == 0, "incompatible"); x /= nformat[i].val(); } ); std::copy(s.begin()+j0,s.begin()+j,ns.begin()); - return moveToPtr( mIPack[i]->reformat(nf,ns) ); + return CNORXZ::reformat(mIPack[i],nf,ns); }, [](const auto&... e) { return std::make_tuple( e... ); } ); GMIndex,Indices...> oi { MFormat(nformat),SPack(npack) }; oi = lex(); diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 444b225..f67d7a5 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -111,6 +111,10 @@ namespace CNORXZ struct index_is_multi { static constexpr bool value = true; }; + template <> + struct has_sub + { static constexpr bool value = true; }; + YIndex yindex(const DPack& pack); YIndex yindex(const Vector& is); Sptr yindexPtr(const DPack& is);