From 944db31e02b65c9f40924e5f96e7293dabaa86d0 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sat, 9 Sep 2023 11:14:03 +0200 Subject: [PATCH] WIP: deepFormat + check format compatibility --- src/include/array/array_base.cc.h | 18 ++++++++++-------- src/include/base/utils.h | 6 +++--- src/include/ranges/dindex.h | 2 ++ src/include/ranges/index_base.h | 2 ++ src/include/ranges/mrange.cc.h | 4 ++-- src/include/ranges/srange.cc.h | 6 ++++++ src/include/ranges/srange.h | 2 ++ src/include/ranges/yrange.h | 2 +- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index 90db3ce..f22864e 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(i->deepFormat()); + this->checkFormatCompatibility(toVec(i->deepFormat())); 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(i->deepFormat()); + this->checkFormatCompatibility(toVec(i->deepFormat())); 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(i->deepFormat()); + this->checkFormatCompatibility(toVec(i->deepFormat())); return coproot(*this, i); } @@ -223,7 +223,7 @@ namespace CNORXZ template OpRoot ArrayBase::operator()(const Sptr& i) { - //CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); + this->checkFormatCompatibility(toVec(i->deepFormat())); return oproot(*this, i); } @@ -231,15 +231,17 @@ namespace CNORXZ template inline decltype(auto) ArrayBase::operator()(const SPack& pack) { - //CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); - return oproot(*this, mindexPtr(pack)); + auto i = mindexPtr(pack); + this->checkFormatCompatibility(toVec(i->deepFormat())); + return oproot(*this, i); } template inline decltype(auto) ArrayBase::operator()(const DPack& pack) { - //CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); - return oproot(*this, yindexPtr(pack)); + auto i = yindexPtr(pack); + this->checkFormatCompatibility(toVec(i->deepFormat())); + return oproot(*this, i); } /***************************** diff --git a/src/include/base/utils.h b/src/include/base/utils.h index 8646cfa..74df958 100644 --- a/src/include/base/utils.h +++ b/src/include/base/utils.h @@ -39,7 +39,7 @@ namespace CNORXZ { return iter<0,N1> ( [&](auto i) { return std::get(a1); }, - [](const auto&... e) { return Arr { e..., a2 }; } ); + [&](const auto&... e) { return Arr { e..., a2 }; } ); } template @@ -47,7 +47,7 @@ namespace CNORXZ { return iter<0,N1> ( [&](auto i) { return std::get(a2); }, - [](const auto&... e) { return Arr { a1, e... }; } ); + [&](const auto&... e) { return Arr { a1, e... }; } ); } template @@ -113,7 +113,7 @@ namespace CNORXZ template constexpr Arr mul(const Arr& a, const T& b) { - return iter<0,N>( [&](auto i) { return std::get(a) * b }, + return iter<0,N>( [&](auto i) { return std::get(a) * b; }, [](const auto&... e) { return Arr { e... }; } ); } diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index f5cbfde..54ead2f 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -54,6 +54,8 @@ namespace CNORXZ DType meta() const; DIndex& at(const DType& meta); DXpr xpr(const Sptr& _this) const; + + Vector deepFormat() const { return mI->deepFormat(); } DXpr ifor(const DXpr& xpr, std::function&& f) const; diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index 8abc4d8..5a3753b 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -62,6 +62,8 @@ namespace CNORXZ decltype(auto) formatFrom(const Index& ind) const // yes this is const, // changes only MIndex/YIndex format, in this case we can just copy the pointers to the sub-index instances { return THIS().formatFrom(ind); } + + decltype(auto) deepFormat() const { return THIS().deepFormat(); } //template //decltype(auto) slice(const Sptr& ind) const { return THIS().slice(ind); } diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 2a5efbc..42ae67e 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -482,8 +482,8 @@ namespace CNORXZ template auto GMIndex::deepFormat() const { - return iter<0,NI>( [&](auto i) { return mul(std::get(mIPack)->deepFormat(), mFormat[i]); }, - [&](const auto&... e) { return concat(e, ...); } ); + return iter<0,NI>( [&](auto i) { return mul(mIPack[i]->deepFormat(), format()[i].val()); }, + [&](const auto&... e) { return concat(e...); } ); } template diff --git a/src/include/ranges/srange.cc.h b/src/include/ranges/srange.cc.h index 41ecba6..60dde3c 100644 --- a/src/include/ranges/srange.cc.h +++ b/src/include/ranges/srange.cc.h @@ -141,6 +141,12 @@ namespace CNORXZ return coproot(mMetaPtr,_this); } + template + SizeT SIndex::deepFormat() const + { + return 1; + } + template template decltype(auto) SIndex::formatFrom(const Index& ind) const diff --git a/src/include/ranges/srange.h b/src/include/ranges/srange.h index 2a8ab0b..868537c 100644 --- a/src/include/ranges/srange.h +++ b/src/include/ranges/srange.h @@ -48,6 +48,8 @@ namespace CNORXZ SIndex& at(const MetaT& metaPos); decltype(auto) xpr(const Sptr>& _this) const; + SizeT deepFormat() const; + template decltype(auto) formatFrom(const Index& ind) const; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 4104a5a..b5da566 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -65,7 +65,7 @@ namespace CNORXZ YIndex& operator()(); const DPack& pack() const; - Vector deepFormat() const; + Vector deepFormat() const { CXZ_ERROR("implement!!!"); return Vector {1}; } const YFormat& format() const; const YFormat& lexFormat() const; YIndex& setFormat(const YFormat& bs);