From 79535c496ff30d09fb150c041bd47365b4a3457d Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 13 Dec 2022 00:37:59 +0100 Subject: [PATCH] add get/set block sizes function for gmindex, yindex, xindex and dindex --- src/include/array/array_base.cc.h | 36 ---------------------- src/include/array/array_base.h | 7 ----- src/include/ranges/dindex.h | 2 ++ src/include/ranges/mrange.cc.h | 18 +++++++++++ src/include/ranges/mrange.h | 4 +++ src/include/ranges/xindex.cc.h | 51 ++++++++++++++++++++++++++++--- src/include/ranges/xindex.h | 6 +++- src/include/ranges/yrange.h | 1 + src/lib/ranges/dindex.cc | 11 +++++++ src/lib/ranges/yrange.cc | 7 +++++ 10 files changed, 95 insertions(+), 48 deletions(-) diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index 719da84..0bab4b2 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -81,42 +81,6 @@ namespace CNORXZ } */ - /****************************** - * CArrayBase (protected) * - ******************************/ - - template - template - inline Vector CArrayBase::mkSliceBlockSize(const IPack1& ip1, const IPack2& ip2) const - { - const SizeT ip1dim = indexPackDim(ip1); - const SizeT ip2dim = indexPackDim(ip2); - if(ip1dim > ip2dim){ - //const SizeT ip1sdim = indexPackSDim(ip1); - const SizeT ip2sdim = indexPackSDim(ip2); - CXZ_ASSERT(ip1dim == ip2sdim or ip2sdim == ip2dim, - "") - } - else if(ip1dim < ip2dim){ - - } - else { - - } - } - - template - inline RangePtr CArrayBase::mkSliceRange(const RangePtr& r) const - { - - } - - template - inline void CArrayBase::assertCompatible() const - { - - } - /***************** * ArrayBase * *****************/ diff --git a/src/include/array/array_base.h b/src/include/array/array_base.h index 8fc1d14..c84af8a 100644 --- a/src/include/array/array_base.h +++ b/src/include/array/array_base.h @@ -22,13 +22,6 @@ namespace CNORXZ protected: RangePtr mRange; - template - inline Vector mkSliceBlockSize(const I1& i, const I2& beg) const; - - inline RangePtr mkSliceRange(const RangePtr& r) const; - - inline void assertCompatible() const; - public: CArrayBase(const RangePtr& range); diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index 0e26f74..2681337 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -47,6 +47,8 @@ namespace CNORXZ UPos stepSize(const IndexId<0>& id) const; Vector pack() const; + Vector blockSizes() const; + DIndex& setBlockSizes(const Vector& bs); String stringMeta() const; DType meta() const; diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 188234c..5264383 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -451,6 +451,24 @@ namespace CNORXZ return mLexBlockSizes; } + template + GMIndex& GMIndex::setBlockSizes(const BlockType& bs) + { + if constexpr(not std::is_same::value){ + mBlockSizes = bs; + } + return *this; + } + + template + decltype(auto) replaceBlockSize(const BT1& bs1, const Sptr>& gmi) + { + return iter<0,sizeof...(Indices)> + ( [&](auto i) { return std::get(gmi.pack()); }, + [&](const auto&... e) { return std::make_shared> + ( bs1, e... ); } ); + } + template decltype(auto) operator*(const Sptr>& a, const Sptr>& b) { diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index 0ea1d03..3a9db8b 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -73,6 +73,7 @@ namespace CNORXZ const IndexPack& pack() const; const auto& blockSizes() const; const auto& lexBlockSizes() const; + GMIndex& setBlockSizes(const BlockType& bs); private: template @@ -108,6 +109,9 @@ namespace CNORXZ PMaxT mPMax; }; + template + decltype(auto) replaceBlockSize(const BT1& bs1, const Sptr>& gmi); + template decltype(auto) operator*(const Sptr>& a, const Sptr>& b); diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index 0302fa0..f4dc5a5 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -130,20 +130,63 @@ namespace CNORXZ template Vector XIndex::pack() const { - constexpr SizeT D = index_dim::value; - // replace by traits: has_sub, has_static_sub (-> to be implemented!!!) - if constexpr(D > 1){ + if constexpr(has_static_sub::value){ + constexpr SizeT D = index_dim::value; return iter<0,D> ( [&](auto i) { return mkXIndex(std::get(mI->pack())); }, [](const auto&... e) { return { e ... }; } ); } - else if constexpr(std::is_same::value){ + else if constexpr(has_sub::value){ return mI->pack(); } else { return {}; } } + + template + Vector XIndex::blockSizes() const + { + if constexpr(has_static_sub::value){ + constexpr SizeT D = index_dim::value; + return iter<0,D> + ( [&](auto i) { return std::get(mI->blockSizes()); }, + [](const auto&... e) { return Vector( { e... } ); } ); + } + else if constexpr(has_sub::value) { + return mI->blockSizes(); + } + else { + return {}; + } + } + + template + XIndexPtr XIndex::setBlockSizes(const Vector& bs) + { + if constexpr(has_static_sub::value){ + constexpr SizeT D = index_dim::value; + CXZ_ASSERT(bs.size() == D, + "got block sizes of wrong dimension: " << bs.size() << " vs " << D); + typedef decltype(mI->blockSizes()) BT; + Arr arr; + std::copy_n(bs.begin(), D, arr.begin()); + if constexpr(std::is_same>::value){ + mI->setBlockSizes(arr); + return nullptr; + } + else { + return replaceBlockSizes(arr, mI); + } + } + else if constexpr(has_sub::value) { + mI->setBlockSizes(bs); + return nullptr; + } + else { + return nullptr; + } + } template String XIndex::stringMeta() const diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index 0c32577..987d675 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -37,7 +37,9 @@ namespace CNORXZ virtual RangePtr range() const = 0; virtual UPos stepSize(const IndexId<0>& id) const = 0; virtual Vector pack() const = 0; - + virtual Vector blockSizes() const = 0; + virtual XIndexPtr setBlockSizes(const Vector& bs) = 0; + virtual String stringMeta() const = 0; virtual DType meta() const = 0; virtual XIndexBase& at(const DType& meta) = 0; @@ -86,6 +88,8 @@ namespace CNORXZ virtual RangePtr range() const override final; virtual UPos stepSize(const IndexId<0>& id) const override final; virtual Vector pack() const override final; + virtual Vector blockSizes() const override final; + virtual XIndexPtr setBlockSizes(const Vector& bs) override final; virtual String stringMeta() const override final; virtual DType meta() const override final; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 9709246..0abe012 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -60,6 +60,7 @@ namespace CNORXZ const Vector& pack() const; const Vector& blockSizes() const; const Vector& lexBlockSizes() const; + YIndex& setBlockSizes(const Vector& bs); private: inline Vector mkBlockSizes() const; diff --git a/src/lib/ranges/dindex.cc b/src/lib/ranges/dindex.cc index 9e50e93..dda7a95 100644 --- a/src/lib/ranges/dindex.cc +++ b/src/lib/ranges/dindex.cc @@ -134,6 +134,17 @@ namespace CNORXZ return mI->pack(); } + Vector DIndex::blockSizes() const + { + return mI->blockSizes(); + } + + DIndex& DIndex::setBlockSizes(const Vector& bs) + { + mI->setBlockSizes(bs); + return *this; + } + String DIndex::stringMeta() const { return mI->stringMeta(); diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 1c736ab..dfc97e2 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -371,6 +371,13 @@ namespace CNORXZ { return mLexBlockSizes; } + + YIndex& YIndex::setBlockSizes(const Vector& bs) + { + mBlockSizes = bs; + return *this; + } + /********************** * YRangeFactory *