ranges: add sub() to ranges -> returns MArray of RangePtrs

This commit is contained in:
Christian Zimmermann 2023-05-07 21:46:46 +02:00
parent 862697edef
commit 7ea21da81a
6 changed files with 43 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include "operation/op_types.h" #include "operation/op_types.h"
#include "operation/op_types.cc.h" // -> do .cc files #include "operation/op_types.cc.h" // -> do .cc files
#include "operation/op_utility.cc.h" // -> do .cc files #include "operation/op_utility.cc.h" // -> do .cc files
#include "array/marray.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -564,6 +565,13 @@ namespace CNORXZ
return mA[num]; return mA[num];
} }
template <class... Ranges>
MArray<RangePtr> MRange<Ranges...>::sub() const
{
CXZ_ERROR("not implemented (SRange missing!!)"); //!!!
return MArray<RangePtr>();
}
template <class... Ranges> template <class... Ranges>
SizeT MRange<Ranges...>::size() const SizeT MRange<Ranges...>::size() const
{ {

View file

@ -178,6 +178,7 @@ namespace CNORXZ
friend MRangeFactory<Ranges...>; friend MRangeFactory<Ranges...>;
virtual RangePtr sub(SizeT num) const override final; virtual RangePtr sub(SizeT num) const override final;
virtual MArray<RangePtr> sub() const override final;
virtual SizeT size() const override final; virtual SizeT size() const override final;
virtual SizeT dim() const override final; virtual SizeT dim() const override final;
virtual String stringMeta(SizeT pos) const override final; virtual String stringMeta(SizeT pos) const override final;

View file

@ -52,6 +52,7 @@ namespace CNORXZ
// virtual RangePtr sub() const; // Sptr<URange<RangePtr>> ; range of subranges (TODO!!!) // virtual RangePtr sub() const; // Sptr<URange<RangePtr>> ; range of subranges (TODO!!!)
virtual RangePtr sub(SizeT num) const; virtual RangePtr sub(SizeT num) const;
virtual MArray<RangePtr> sub() const;
virtual SizeT size() const = 0; virtual SizeT size() const = 0;
virtual SizeT dim() const = 0; virtual SizeT dim() const = 0;
virtual const TypeInfo& type() 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 RangePtr& a, const RangePack& b);
RangePack operator*(const RangePack& a, const RangePtr& b); RangePack operator*(const RangePack& a, const RangePtr& b);
RangePack operator*(const RangePack& a, const RangePack& b); RangePack operator*(const RangePack& a, const RangePack& b);
RangePtr getSub(const RangePtr& r, SizeT num);
MArray<RangePtr> getSub(const RangePtr& r);
} }
#endif #endif

View file

@ -120,6 +120,7 @@ namespace CNORXZ
friend YRangeFactory; friend YRangeFactory;
virtual RangePtr sub(SizeT i) const override final; virtual RangePtr sub(SizeT i) const override final;
virtual MArray<RangePtr> sub() const override final;
virtual SizeT size() const override final; virtual SizeT size() const override final;
virtual SizeT dim() const override final; virtual SizeT dim() const override final;
virtual String stringMeta(SizeT pos) const override final; virtual String stringMeta(SizeT pos) const override final;

View file

@ -1,5 +1,6 @@
#include "ranges/ranges.h" #include "ranges/ranges.h"
#include "array/array.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -59,6 +60,11 @@ namespace CNORXZ
return nullptr; return nullptr;
} }
MArray<RangePtr> RangeBase::sub() const
{
return MArray<RangePtr>();
}
bool RangeBase::operator==(const RangeBase& in) const bool RangeBase::operator==(const RangeBase& in) const
{ {
return this == &in; return this == &in;
@ -136,4 +142,18 @@ namespace CNORXZ
return o; 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<RangePtr> getSub(const RangePtr& r)
{
MArray<RangePtr> o = r->sub();
CXZ_ASSERT(o.range() != nullptr, "try to access subrange of single range");
return o;
}
} // end namespace CNORXZ } // end namespace CNORXZ

View file

@ -1,5 +1,6 @@
#include "ranges/ranges.h" #include "ranges/ranges.h"
#include "array/array.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -445,6 +446,14 @@ namespace CNORXZ
return mRVec[i]; return mRVec[i];
} }
MArray<RangePtr> YRange::sub() const
{
if(mRVec.size() == 0){
return MArray<RangePtr>();
}
return MArray<RangePtr>( CRangeFactory(mRVec.size()).create(), mRVec );
}
SizeT YRange::size() const SizeT YRange::size() const
{ {
SizeT out = 1; SizeT out = 1;