From 642381ecc06adb8ff799f4d798297d37f2a5c35a Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 11 Dec 2023 02:20:02 +0100 Subject: [PATCH] YRange: bug fix in deepFormat + add setFormat + array: bug fix in check format --- src/include/array/array_base.cc.h | 4 ++++ src/include/ranges/yrange.h | 1 + src/lib/ranges/yrange.cc | 38 ++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index f35b7a5..da94e41 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -206,6 +206,10 @@ namespace CNORXZ CXZ_ASSERT(f1[i1] >= f2[i2], "obtained format " << toString(f1) << ", which is incompatible to target format " << toString(f2)); } + else { + ++i1; + ++i2; + } } } diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 49dd8b6..59f03b5 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -76,6 +76,7 @@ namespace CNORXZ const DPack& pack() const; RangePtr prange(const YIndex& last) const; Vector deepFormat() const; + YIndex& setFormat(const Vector& f, const Vector& s); const YFormat& format() const; const YFormat& lexFormat() const; YIndex& setFormat(const YFormat& bs); diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 16864f2..9f7aac5 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -383,6 +383,8 @@ namespace CNORXZ SizeT osize = 0; for(SizeT j = 0; j != dfv.size(); ++j){ dfv[j] = mIs[j]->deepFormat(); + std::for_each(dfv[j].begin(), dfv[j].end(), + [&](SizeT& x) { x *= mFormat[j].val(); } ); osize += dfv[j].size(); } Vector o(osize); @@ -390,10 +392,44 @@ namespace CNORXZ for(SizeT j = 0; j != dfv.size(); ++j){ std::copy(dfv[j].begin(), dfv[j].end(), o.begin()+off); off += dfv[j].size(); - } + } return o; } + YIndex& YIndex::setFormat(const Vector& f, const Vector& s) + { + CXZ_ASSERT(f.size() == s.size(), "input error: f.size() != s.size()"); + // f: input format + // s: input sizes + SizeT j = 0; + SizeT j0 = 0; + Vector nformat(dim()); + for(SizeT i = 0; i != dim(); ++i){ + SizeT si = 1; + if(mIs[i]->lmax().val() == 1){ + continue; + } + for(; si < mIs[i]->lmax().val(); ++j){ + si *= s[i]; + CXZ_ASSERT(j < f.size(), "incompatible index formats"); + } + CXZ_ASSERT(si == mIs[i]->lmax().val(), + "incompatible index formats: " << toString(s) << " vs " //!!! + ); + Vector nf(j-j0); + Vector ns(j-j0); + std::copy(f.begin()+j0,f.begin()+j,nf.begin()); + nformat[i] = *std::min_element(nf.begin(), nf.end()); + std::for_each(nf.begin(), nf.end(), [&](SizeT& x) + { CXZ_ASSERT(x % mFormat[i].val() == 0, "incompatible"); x /= nformat[i].val(); } ); + std::copy(s.begin()+j0,s.begin()+j,ns.begin()); + CXZ_ERROR("implement for all indices!!!"); + //mIs[i]->setFormat(nf,ns); + } + mFormat = nformat; + return *this; + } + bool YIndex::formatIsTrivial() const { for(SizeT i = 0; i != mIs.size(); ++i){