From 9b706c4ec0df7e148742df781e902030cc141c54 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 10 Sep 2023 14:35:53 +0200 Subject: [PATCH] check format compatibility --- src/include/array/array_base.cc.h | 44 ++++++++++++++++++++++++++----- src/include/array/array_base.h | 3 ++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index f22864e..0856c17 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -100,7 +100,7 @@ namespace CNORXZ template COpRoot CArrayBase::operator()(const Sptr& i) const { - this->checkFormatCompatibility(toVec(i->deepFormat())); + this->checkFormatCompatibility(*i); return coproot(*this, i); } @@ -109,7 +109,7 @@ namespace CNORXZ inline decltype(auto) CArrayBase::operator()(const SPack& pack) const { auto i = mindexPtr(pack); - this->checkFormatCompatibility(toVec(i->deepFormat())); + this->checkFormatCompatibility(*i); return coproot(*this, i); } @@ -117,7 +117,7 @@ namespace CNORXZ inline decltype(auto) CArrayBase::operator()(const DPack& pack) const { auto i = yindexPtr(pack); - this->checkFormatCompatibility(toVec(i->deepFormat())); + this->checkFormatCompatibility(*i); return coproot(*this, i); } @@ -142,6 +142,38 @@ namespace CNORXZ return begin() + acc.lex(); } + template + template + void CArrayBase::checkFormatCompatibility(const Acc& acc) const + { + auto j = begin(); + CXZ_ASSERT(acc.lmax().val() == j.lmax().val(), + "got index of iteration space size = " << acc.lmax().val() + << ", expected size = " << acc.lmax().val()); + Vector f1 = toVec(acc.deepFormat()); + Vector f2 = j.deepFormat(); + std::sort(f1.begin(),f1.end()); + std::sort(f2.begin(),f2.end()); + SizeT i1 = 0; + SizeT i2 = 0; + CXZ_ASSERT(f1[i1] == f2[i2], "obtained format " << toString(f1) + << ", which is incompatible to target format " << toString(f2)); + ++i1; + ++i2; + while(i1 < f1.size() and i2 < f2.size()){ + if(f1[i1] < f2[i2]) { + if(++i1 == f1.size()) break; + CXZ_ASSERT(f1[i1] <= f2[i2], "obtained format " << toString(f1) + << ", which is incompatible to target format " << toString(f2)); + } + else if(f1[i1] > f2[i2]) { + if(++i2 == f2.size()) break; + CXZ_ASSERT(f1[i1] >= f2[i2], "obtained format " << toString(f1) + << ", which is incompatible to target format " << toString(f2)); + } + } + } + /***************** * ArrayBase * *****************/ @@ -223,7 +255,7 @@ namespace CNORXZ template OpRoot ArrayBase::operator()(const Sptr& i) { - this->checkFormatCompatibility(toVec(i->deepFormat())); + this->checkFormatCompatibility(*i); return oproot(*this, i); } @@ -232,7 +264,7 @@ namespace CNORXZ inline decltype(auto) ArrayBase::operator()(const SPack& pack) { auto i = mindexPtr(pack); - this->checkFormatCompatibility(toVec(i->deepFormat())); + this->checkFormatCompatibility(*i); return oproot(*this, i); } @@ -240,7 +272,7 @@ namespace CNORXZ inline decltype(auto) ArrayBase::operator()(const DPack& pack) { auto i = yindexPtr(pack); - this->checkFormatCompatibility(toVec(i->deepFormat())); + this->checkFormatCompatibility(*i); return oproot(*this, i); } diff --git a/src/include/array/array_base.h b/src/include/array/array_base.h index 7bec6f0..55183a9 100644 --- a/src/include/array/array_base.h +++ b/src/include/array/array_base.h @@ -70,7 +70,8 @@ namespace CNORXZ template const_iterator itLexSave(const Acc& acc) const; - void checkFormatCompatibility(const Vector& f) const { CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); } + template + void checkFormatCompatibility(const Acc& acc) const; }; template