From e8c8e519dc0c8a05d651805801beb5841c3d0f2d Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 11 Jan 2023 19:02:34 +0100 Subject: [PATCH] change operator* for index shared ptrs -> creates index packs instead of m/yindices --- src/include/array/array_base.cc.h | 30 +++++++++++++++ src/include/array/array_base.h | 24 ++++++++---- src/include/ranges/index_mul.cc.h | 61 +++++++++++-------------------- src/include/ranges/mrange.cc.h | 12 +++--- src/include/ranges/mrange.h | 11 ++---- src/include/ranges/yrange.h | 1 + src/lib/ranges/yrange.cc | 5 +++ src/tests/operation_unit_test.cc | 4 +- 8 files changed, 86 insertions(+), 62 deletions(-) diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index 9bfb345..aaf398c 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -104,6 +104,21 @@ namespace CNORXZ return coproot(*this, i); } + template + template + inline decltype(auto) CArrayBase::operator()(const SPack& pack) const + { + CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); + return coproot(*this, mindexPtr(pack)); + } + + template + inline decltype(auto) CArrayBase::operator()(const DPack& pack) const + { + CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); + return coproot(*this, yindexPtr(pack)); + } + /****************************** * CArrayBase (protected) * ******************************/ @@ -210,6 +225,21 @@ namespace CNORXZ return oproot(*this, i); } + template + template + inline decltype(auto) ArrayBase::operator()(const SPack& pack) + { + CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); + return oproot(*this, mindexPtr(pack)); + } + + template + inline decltype(auto) ArrayBase::operator()(const DPack& pack) + { + CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); + return oproot(*this, yindexPtr(pack)); + } + /***************************** * ArrayBase (protected) * *****************************/ diff --git a/src/include/array/array_base.h b/src/include/array/array_base.h index 7bdd25d..45016e8 100644 --- a/src/include/array/array_base.h +++ b/src/include/array/array_base.h @@ -41,7 +41,15 @@ namespace CNORXZ template Sptr> sl(const IndexInterface& i) const; - + + template + COpRoot operator()(const Sptr& i) const; + + template + inline decltype(auto) operator()(const SPack& pack) const; + + inline decltype(auto) operator()(const DPack& pack) const; + virtual const T* data() const = 0; virtual SizeT size() const; virtual RangePtr range() const; @@ -53,9 +61,6 @@ namespace CNORXZ virtual bool isView() const = 0; - template - COpRoot operator()(const Sptr& i) const; - protected: RangePtr mRange; @@ -101,6 +106,14 @@ namespace CNORXZ T& operator[](const DPack& pack); T& at(const DPack& pack); + template + OpRoot operator()(const Sptr& i); + + template + inline decltype(auto) operator()(const SPack& pack); + + inline decltype(auto) operator()(const DPack& pack); + template Sptr> sl(const IndexInterface& i); @@ -109,9 +122,6 @@ namespace CNORXZ virtual iterator begin(); virtual iterator end(); - template - OpRoot operator()(const Sptr& i); - protected: template diff --git a/src/include/ranges/index_mul.cc.h b/src/include/ranges/index_mul.cc.h index e3961e5..319ed63 100644 --- a/src/include/ranges/index_mul.cc.h +++ b/src/include/ranges/index_mul.cc.h @@ -72,6 +72,22 @@ namespace CNORXZ return a.rmul(std::make_shared(b.THIS())); } + template + inline decltype(auto) operator*(const Sptr& a, + const SPack& b) + { + static_assert(is_index::value, "got non-index type"); + return b.lmul(a); + } + + template + inline decltype(auto) operator*(const SPack& a, + const Sptr& b) + { + static_assert(is_index::value, "got non-index type"); + return a.rmul(b); + } + template inline decltype(auto) operator*(const SPack& a, const SPack& b) { @@ -102,48 +118,13 @@ namespace CNORXZ template decltype(auto) iptrMul(const Sptr& a, const Sptr& b) { - if constexpr(std::is_same::value){ - if constexpr(std::is_same::value){ - return std::make_shared({ a->xptr(), b->xptr() }); - } - else if constexpr(std::is_same::value){ - auto p = b->pack(); - p.insert(0, a->xptr()); - return std::make_shared(p); - } - } - else if constexpr(std::is_same::value){ - if constexpr(std::is_same::value){ - auto p = a->pack(); - p.push_back(b->xptr()); - return std::make_shared(p); - } - else if constexpr(std::is_same::value){ - auto p = a->pack(); - p.insert(p.end(), b->pack().begin(), b->pack().end()); - return std::make_shared(p); - } + static_assert(is_index::value and is_index::value, "got non-index type"); + if constexpr(std::is_same::value or std::is_same::value or + std::is_same::value or std::is_same::value) { + return dpackp(a, b); } else { - constexpr SizeT I1D = index_dim::value; - constexpr SizeT I2D = index_dim::value; - if constexpr(I1D == 1){ - if constexpr(index_dim::value == 1){ - return std::make_shared>(a, b); - } - else { - return MIndexSptrMul::evalXM(a, b, std::make_index_sequence{}); - } - } - else { - if constexpr(index_dim::value == 1){ - return MIndexSptrMul::evalMX(a, b, std::make_index_sequence{}); - } - else { - return MIndexSptrMul::evalMM(a, b, std::make_index_sequence{}, - std::make_index_sequence{}); - } - } + return spackp(a, b); } } diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 7c718e1..6e0a748 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -472,12 +472,6 @@ namespace CNORXZ ( bs1, e... ); } ); } - template - decltype(auto) operator*(const Sptr>& a, const Sptr>& b) - { - return iptrMul(a, b); - } - template constexpr decltype(auto) mindex(const Sptr&... is) { @@ -490,6 +484,12 @@ namespace CNORXZ return MIndex(pack); } + template + constexpr decltype(auto) mindexPtr(const SPack& pack) + { + return std::make_shared>(pack); + } + template constexpr decltype(auto) gmindexPtr(const FormatT& bs, const Sptr&... is) { diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index 9b0034b..da24aab 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -105,7 +105,6 @@ namespace CNORXZ typedef RemoveRef{}))> LexFormatT; LexFormatT mLexFormat; FormatT mFormat; - //BlockType mFormat; // -> FormatT SizeT mLex; typedef RemoveRef LMaxT; LMaxT mLMax; @@ -116,11 +115,6 @@ namespace CNORXZ template decltype(auto) replaceFormat(const BT1& bs1, const Sptr>& gmi); - template - decltype(auto) operator*(const Sptr>& a, const Sptr>& b); - - //template - //using MIndex = GMIndex; template struct index_has_const_size> { static constexpr bool value = (index_has_const_size::value and ...); }; @@ -146,7 +140,10 @@ namespace CNORXZ template constexpr decltype(auto) mindex(const SPack& pack); - + + template + constexpr decltype(auto) mindexPtr(const SPack& pack); + template constexpr decltype(auto) gmindexPtr(const FormatT& bs, const Sptr&... is); diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 579d7d8..371899f 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -89,6 +89,7 @@ namespace CNORXZ YIndex yindex(const DPack& pack); YIndex yindex(const Vector& is); + Sptr yindexPtr(const DPack& is); Sptr yindexPtr(const Vector& is); Sptr yindexPtr(const Vector& bs, const Vector& is); diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index e2c129f..5ff3c45 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -392,6 +392,11 @@ namespace CNORXZ return YIndex(is); } + Sptr yindexPtr(const DPack& pack) + { + return std::make_shared(pack.all()); + } + Sptr yindexPtr(const Vector& is) { return std::make_shared(is); diff --git a/src/tests/operation_unit_test.cc b/src/tests/operation_unit_test.cc index fcb348d..43b2a85 100644 --- a/src/tests/operation_unit_test.cc +++ b/src/tests/operation_unit_test.cc @@ -63,8 +63,8 @@ namespace mCIa2 = std::make_shared(cra); mCIb1 = std::make_shared(crb); mCIb2 = std::make_shared(crb); - mCCa1a2 = mCIa1*mCIa2; - mCCa2a1 = mCIa2*mCIa1; + mCCa1a2 = mindexPtr(mCIa1*mCIa2); + mCCa2a1 = mindexPtr(mCIa2*mCIa1); mOCa1a2.init(mCCa1a2); mORa2a1.init(mData12.data(), mCCa2a1); }