From 7ea21da81a0f1c7bec745f5dfe7ed8db1c1d86a5 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 7 May 2023 21:46:46 +0200 Subject: [PATCH] ranges: add sub() to ranges -> returns MArray of RangePtrs --- src/include/ranges/mrange.cc.h | 8 ++++++++ src/include/ranges/mrange.h | 1 + src/include/ranges/range_base.h | 4 ++++ src/include/ranges/yrange.h | 1 + src/lib/ranges/range_base.cc | 20 ++++++++++++++++++++ src/lib/ranges/yrange.cc | 9 +++++++++ 6 files changed, 43 insertions(+) diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 396d30b..5d62a51 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -6,6 +6,7 @@ #include "operation/op_types.h" #include "operation/op_types.cc.h" // -> do .cc files #include "operation/op_utility.cc.h" // -> do .cc files +#include "array/marray.h" namespace CNORXZ { @@ -564,6 +565,13 @@ namespace CNORXZ return mA[num]; } + template + MArray MRange::sub() const + { + CXZ_ERROR("not implemented (SRange missing!!)"); //!!! + return MArray(); + } + template SizeT MRange::size() const { diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index a4b1f2e..18775f4 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -178,6 +178,7 @@ namespace CNORXZ friend MRangeFactory; virtual RangePtr sub(SizeT num) const override final; + virtual MArray sub() const override final; virtual SizeT size() const override final; virtual SizeT dim() const override final; virtual String stringMeta(SizeT pos) const override final; diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index cc1a5f5..69a1803 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -52,6 +52,7 @@ namespace CNORXZ // virtual RangePtr sub() const; // Sptr> ; range of subranges (TODO!!!) virtual RangePtr sub(SizeT num) const; + virtual MArray sub() const; virtual SizeT size() const = 0; virtual SizeT dim() const = 0; virtual const TypeInfo& type() const = 0; @@ -120,6 +121,9 @@ namespace CNORXZ RangePack operator*(const RangePtr& a, const RangePack& b); RangePack operator*(const RangePack& a, const RangePtr& b); RangePack operator*(const RangePack& a, const RangePack& b); + + RangePtr getSub(const RangePtr& r, SizeT num); + MArray getSub(const RangePtr& r); } #endif diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 2470b84..f674da4 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -120,6 +120,7 @@ namespace CNORXZ friend YRangeFactory; virtual RangePtr sub(SizeT i) const override final; + virtual MArray sub() const override final; virtual SizeT size() const override final; virtual SizeT dim() const override final; virtual String stringMeta(SizeT pos) const override final; diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index 52de19f..3b5d6fb 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -1,5 +1,6 @@ #include "ranges/ranges.h" +#include "array/array.h" namespace CNORXZ { @@ -59,6 +60,11 @@ namespace CNORXZ return nullptr; } + MArray RangeBase::sub() const + { + return MArray(); + } + bool RangeBase::operator==(const RangeBase& in) const { return this == ∈ @@ -136,4 +142,18 @@ namespace CNORXZ return o; } + RangePtr getSub(const RangePtr& r, SizeT num) + { + RangePtr o = r->sub(num); + CXZ_ASSERT(o != nullptr, "try to access empty subrange at position " << num); + return o; + } + + MArray getSub(const RangePtr& r) + { + MArray o = r->sub(); + CXZ_ASSERT(o.range() != nullptr, "try to access subrange of single range"); + return o; + } + } // end namespace CNORXZ diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 9b041b8..e7b0e29 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -1,5 +1,6 @@ #include "ranges/ranges.h" +#include "array/array.h" namespace CNORXZ { @@ -445,6 +446,14 @@ namespace CNORXZ return mRVec[i]; } + MArray YRange::sub() const + { + if(mRVec.size() == 0){ + return MArray(); + } + return MArray( CRangeFactory(mRVec.size()).create(), mRVec ); + } + SizeT YRange::size() const { SizeT out = 1;