WIP: slicing + partial ranges
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Christian Zimmermann 2023-09-18 00:01:27 +02:00
parent 9b706c4ec0
commit db6b0a14ec
7 changed files with 47 additions and 6 deletions

View file

@ -64,12 +64,12 @@ namespace CNORXZ
template <typename T> template <typename T>
template <typename I, typename M> template <typename I, typename M>
Sptr<CArrayBase<T>> CArrayBase<T>::sl(const IndexInterface<I,M>& i) const Sptr<CArrayBase<T>> CArrayBase<T>::sl(const IndexInterface<I,M>& begin,
const IndexInterface<I,M>& end) const
{ {
auto beg = std::make_shared<const_iterator>(this->begin()); auto ai = itLexSave(begin);
auto si = i.slice(beg); auto aj = itLexSave(end);
auto it = *beg + i.lex(); return std::make_shared<CSlice>(subcube(ai,aj), this, ai.format(), ai.pos());
return std::make_shared<CSlice>(this, *si, it.pos());
} }
template <typename T> template <typename T>

View file

@ -40,7 +40,8 @@ namespace CNORXZ
const T& at(const DPack& pack) const; const T& at(const DPack& pack) const;
template <typename I, typename M> template <typename I, typename M>
Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& i) const; Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& begin,
const IndexInterface<I,M>& end) const;
template <class Index> template <class Index>
COpRoot<T,Index> operator()(const Sptr<Index>& i) const; COpRoot<T,Index> operator()(const Sptr<Index>& i) const;

View file

@ -326,6 +326,23 @@ namespace CNORXZ
{ {
return Vector<Uuid> { mRange->id() }; return Vector<Uuid> { mRange->id() };
} }
/****************************
* non-member functions *
****************************/
template <class I, typename M>
RangePtr prange(const IndexInterface<I,M>& begin, const IndexInterface<I,M>& end)
{
Vector<SizeT> parts(end-begin);
const SizeT off = begin.pos();
for(auto i = begin.THIS(); i != end.THIS(); ++i){
parts[i.pos()-off] = i.pos();
}
return begin.range()->partial(parts); // implement!!!!
//return PRangeFactory<typename I::RangeType>(begin.range(), parts).create();
}
} }
#endif #endif

View file

@ -117,6 +117,9 @@ namespace CNORXZ
Sptr<RangeT> mRange; Sptr<RangeT> mRange;
Vector<SizeT> mParts; Vector<SizeT> mParts;
}; };
template <class I, typename M>
RangePtr prange(const IndexInterface<I,M>& begin, const IndexInterface<I,M>& end);
} // namespace CNORXZ } // namespace CNORXZ

View file

@ -124,6 +124,7 @@ namespace CNORXZ
RangePtr getSub(const RangePtr& r, SizeT num); RangePtr getSub(const RangePtr& r, SizeT num);
MArray<RangePtr> getSub(const RangePtr& r); MArray<RangePtr> getSub(const RangePtr& r);
} }
#endif #endif

View file

@ -9,6 +9,7 @@
#include "xpr/xpr.h" #include "xpr/xpr.h"
#include "index_format.h" #include "index_format.h"
#include "index_pack.h" #include "index_pack.h"
#include "prange.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -159,6 +160,10 @@ namespace CNORXZ
static Sptr<YRange> func(const RangePtr& r); static Sptr<YRange> func(const RangePtr& r);
}; };
template <>
RangePtr prange(const IndexInterface<YIndex,Vector<DType>>& begin,
const IndexInterface<YIndex,Vector<DType>>& end);
} }
#endif #endif

View file

@ -560,4 +560,18 @@ namespace CNORXZ
{ {
return std::dynamic_pointer_cast<YRange>( YRangeFactory({r}).create() ); return std::dynamic_pointer_cast<YRange>( YRangeFactory({r}).create() );
} }
template <>
RangePtr prange(const IndexInterface<YIndex,Vector<DType>>& begin,
const IndexInterface<YIndex,Vector<DType>>& end)
{
CXZ_WARNING("YRange specialization"); // test
const SizeT dim = begin.range()->dim();
Vector<RangePtr> v(dim);
for(SizeT i = 0; i != dim; ++i){
v[i] = prange( DIndex(begin.THIS().pack()[i]), DIndex(end.THIS().pack()[i]) );
}
return YRangeFactory(v).create();
}
} }