index: add prange member function
This commit is contained in:
parent
db6b0a14ec
commit
301967288f
18 changed files with 223 additions and 147 deletions
|
@ -69,7 +69,7 @@ namespace CNORXZ
|
||||||
{
|
{
|
||||||
auto ai = itLexSave(begin);
|
auto ai = itLexSave(begin);
|
||||||
auto aj = itLexSave(end);
|
auto aj = itLexSave(end);
|
||||||
return std::make_shared<CSlice>(subcube(ai,aj), this, ai.format(), ai.pos());
|
return std::make_shared<CSlice>(ai.prange(aj), this, ai.format(), ai.pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -47,6 +47,8 @@ namespace CNORXZ
|
||||||
CIndex& at(const SizeT& metaPos);
|
CIndex& at(const SizeT& metaPos);
|
||||||
COpRoot<SizeT,CIndex> xpr(const Sptr<CIndex>& _this) const;
|
COpRoot<SizeT,CIndex> xpr(const Sptr<CIndex>& _this) const;
|
||||||
|
|
||||||
|
RangePtr prange(const CIndex& end) const;
|
||||||
|
|
||||||
SizeT deepFormat() const;
|
SizeT deepFormat() const;
|
||||||
/*
|
/*
|
||||||
template <class Index>
|
template <class Index>
|
||||||
|
|
|
@ -54,6 +54,7 @@ namespace CNORXZ
|
||||||
DType meta() const;
|
DType meta() const;
|
||||||
DIndex& at(const DType& meta);
|
DIndex& at(const DType& meta);
|
||||||
DXpr<SizeT> xpr(const Sptr<DIndex>& _this) const;
|
DXpr<SizeT> xpr(const Sptr<DIndex>& _this) const;
|
||||||
|
RangePtr prange(const DIndex& end) const;
|
||||||
Vector<SizeT> deepFormat() const;
|
Vector<SizeT> deepFormat() const;
|
||||||
|
|
||||||
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;
|
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;
|
||||||
|
|
|
@ -54,6 +54,8 @@ namespace CNORXZ
|
||||||
decltype(auto) meta() const { return THIS().meta(); }
|
decltype(auto) meta() const { return THIS().meta(); }
|
||||||
I& at(const MetaType& meta) { return THIS().at(meta); }
|
I& at(const MetaType& meta) { return THIS().at(meta); }
|
||||||
decltype(auto) xpr(const Sptr<I>& _this) const { return THIS().xpr(_this); }
|
decltype(auto) xpr(const Sptr<I>& _this) const { return THIS().xpr(_this); }
|
||||||
|
|
||||||
|
RangePtr prange(const IndexInterface& end) const { return THIS().prange(end.THIS()); }
|
||||||
/*
|
/*
|
||||||
template <class Index>
|
template <class Index>
|
||||||
decltype(auto) formatTo(const Sptr<Index>& ind) const { return ind->formatFrom(THIS()); }
|
decltype(auto) formatTo(const Sptr<Index>& ind) const { return ind->formatFrom(THIS()); }
|
||||||
|
|
|
@ -479,6 +479,22 @@ namespace CNORXZ
|
||||||
return mLexFormat;
|
return mLexFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class FormatT, class... Indices>
|
||||||
|
RangePtr GMIndex<FormatT,Indices...>::prange(const MIndex<Indices...>& end) const
|
||||||
|
{
|
||||||
|
CXZ_ERROR("IMPLEMENT!!!");
|
||||||
|
return nullptr;
|
||||||
|
/*
|
||||||
|
return ifor<0,NI>
|
||||||
|
( [&](auto i) {
|
||||||
|
typedef typename std::remove_reference<decltype(mIPack[i])>::type::RangeType RangeT;
|
||||||
|
return std::dynamic_pointer_cast<RangeT>( mIPack[i]->prange( *end.pack()[i] ) );
|
||||||
|
},
|
||||||
|
[](const auto&... e) { return mrange(e...); }
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
template <class FormatT, class... Indices>
|
template <class FormatT, class... Indices>
|
||||||
auto GMIndex<FormatT,Indices...>::deepFormat() const
|
auto GMIndex<FormatT,Indices...>::deepFormat() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,6 +81,7 @@ namespace CNORXZ
|
||||||
const SPack<Indices...>& pack() const;
|
const SPack<Indices...>& pack() const;
|
||||||
const auto& format() const;
|
const auto& format() const;
|
||||||
const auto& lexFormat() const;
|
const auto& lexFormat() const;
|
||||||
|
RangePtr prange(const MIndex<Indices...>& end) const;
|
||||||
auto deepFormat() const;
|
auto deepFormat() const;
|
||||||
GMIndex& setFormat(const FormatT& bs);
|
GMIndex& setFormat(const FormatT& bs);
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,19 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class IndexT>
|
||||||
|
RangePtr PIndex<IndexT>::prange(const PIndex<IndexT>& end) const
|
||||||
|
{
|
||||||
|
CXZ_ERROR("IMPLEMENT!!!");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class IndexT>
|
||||||
|
decltype(auto) PIndex<IndexT>::deepFormat() const
|
||||||
|
{
|
||||||
|
return mOrig->deepFormat();
|
||||||
|
}
|
||||||
|
|
||||||
template <class IndexT>
|
template <class IndexT>
|
||||||
String PIndex<IndexT>::stringMeta() const
|
String PIndex<IndexT>::stringMeta() const
|
||||||
{
|
{
|
||||||
|
@ -208,7 +221,7 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
++IB::mPos;
|
++IB::mPos;
|
||||||
}
|
}
|
||||||
CXZ_ERROR("meta position '" << mOrig->meta() << "' not part of range");
|
CXZ_ERROR("meta position '" << toString(mOrig->meta()) << "' not part of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************
|
/***************************
|
||||||
|
@ -327,22 +340,16 @@ namespace CNORXZ
|
||||||
return Vector<Uuid> { mRange->id() };
|
return Vector<Uuid> { mRange->id() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
* non-member functions *
|
* non-member functions *
|
||||||
****************************/
|
****************************/
|
||||||
|
|
||||||
template <class I, typename M>
|
template <class RangeT>
|
||||||
RangePtr prange(const IndexInterface<I,M>& begin, const IndexInterface<I,M>& end)
|
RangePtr prange(const Sptr<RangeT>& range, const Vector<SizeT>& parts)
|
||||||
{
|
{
|
||||||
Vector<SizeT> parts(end-begin);
|
return PRangeFactory<RangeT>(range,parts).create();
|
||||||
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
|
||||||
|
|
|
@ -41,6 +41,8 @@ namespace CNORXZ
|
||||||
|
|
||||||
template <SizeT I>
|
template <SizeT I>
|
||||||
UPos stepSize(const IndexId<I>& id) const;
|
UPos stepSize(const IndexId<I>& id) const;
|
||||||
|
RangePtr prange(const PIndex<IndexT>& end) const;
|
||||||
|
decltype(auto) deepFormat() const;
|
||||||
|
|
||||||
String stringMeta() const;
|
String stringMeta() const;
|
||||||
decltype(auto) meta() const;
|
decltype(auto) meta() const;
|
||||||
|
@ -118,8 +120,8 @@ namespace CNORXZ
|
||||||
Vector<SizeT> mParts;
|
Vector<SizeT> mParts;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class I, typename M>
|
template <class RangeT>
|
||||||
RangePtr prange(const IndexInterface<I,M>& begin, const IndexInterface<I,M>& end);
|
RangePtr prange(const Sptr<RangeT>& range, const Vector<SizeT>& parts);
|
||||||
|
|
||||||
} // namespace CNORXZ
|
} // namespace CNORXZ
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,13 @@ namespace CNORXZ
|
||||||
return coproot(mMetaPtr,_this);
|
return coproot(mMetaPtr,_this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename MetaT, SizeT S>
|
||||||
|
RangePtr SIndex<MetaT,S>::prange(const SIndex<MetaType,S>& end) const
|
||||||
|
{
|
||||||
|
CXZ_ERROR("IMPLEMENT!!!");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename MetaT, SizeT S>
|
template <typename MetaT, SizeT S>
|
||||||
SizeT SIndex<MetaT,S>::deepFormat() const
|
SizeT SIndex<MetaT,S>::deepFormat() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace CNORXZ
|
||||||
SIndex& at(const MetaT& metaPos);
|
SIndex& at(const MetaT& metaPos);
|
||||||
decltype(auto) xpr(const Sptr<SIndex<MetaType,S>>& _this) const;
|
decltype(auto) xpr(const Sptr<SIndex<MetaType,S>>& _this) const;
|
||||||
|
|
||||||
|
RangePtr prange(const SIndex<MetaType,S>& end) const;
|
||||||
SizeT deepFormat() const;
|
SizeT deepFormat() const;
|
||||||
/*
|
/*
|
||||||
template <class Index>
|
template <class Index>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "urange.h"
|
#include "urange.h"
|
||||||
|
#include "prange.h"
|
||||||
#include "index_mul.h"
|
#include "index_mul.h"
|
||||||
#include "xpr/for.h"
|
#include "xpr/for.h"
|
||||||
#include "operation/op_types.h"
|
#include "operation/op_types.h"
|
||||||
|
@ -17,136 +18,148 @@ namespace CNORXZ
|
||||||
* UIndex *
|
* UIndex *
|
||||||
*****************/
|
*****************/
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType>::UIndex(const RangePtr& range, SizeT pos) :
|
UIndex<MetaT>::UIndex(const RangePtr& range, SizeT pos) :
|
||||||
IndexInterface<UIndex<MetaType>,MetaType>(pos),
|
IndexInterface<UIndex<MetaT>,MetaT>(pos),
|
||||||
mRangePtr(rangeCast<RangeType>(range)),
|
mRangePtr(rangeCast<RangeType>(range)),
|
||||||
mMetaPtr(&mRangePtr->get(0))
|
mMetaPtr(&mRangePtr->get(0))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType>& UIndex<MetaType>::operator=(size_t lexpos)
|
UIndex<MetaT>& UIndex<MetaT>::operator=(size_t lexpos)
|
||||||
{
|
{
|
||||||
IB::mPos = lexpos;
|
IB::mPos = lexpos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType>& UIndex<MetaType>::operator++()
|
UIndex<MetaT>& UIndex<MetaT>::operator++()
|
||||||
{
|
{
|
||||||
++IB::mPos;
|
++IB::mPos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType>& UIndex<MetaType>::operator--()
|
UIndex<MetaT>& UIndex<MetaT>::operator--()
|
||||||
{
|
{
|
||||||
--IB::mPos;
|
--IB::mPos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType> UIndex<MetaType>::operator+(Int n) const
|
UIndex<MetaT> UIndex<MetaT>::operator+(Int n) const
|
||||||
{
|
{
|
||||||
return UIndex(mRangePtr, IB::mPos + n);
|
return UIndex(mRangePtr, IB::mPos + n);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType> UIndex<MetaType>::operator-(Int n) const
|
UIndex<MetaT> UIndex<MetaT>::operator-(Int n) const
|
||||||
{
|
{
|
||||||
return UIndex(mRangePtr, IB::mPos - n);
|
return UIndex(mRangePtr, IB::mPos - n);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType>& UIndex<MetaType>::operator+=(Int n)
|
UIndex<MetaT>& UIndex<MetaT>::operator+=(Int n)
|
||||||
{
|
{
|
||||||
IB::mPos += n;
|
IB::mPos += n;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType>& UIndex<MetaType>::operator-=(Int n)
|
UIndex<MetaT>& UIndex<MetaT>::operator-=(Int n)
|
||||||
{
|
{
|
||||||
IB::mPos -= n;
|
IB::mPos -= n;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
SizeT UIndex<MetaType>::lex() const
|
SizeT UIndex<MetaT>::lex() const
|
||||||
{
|
{
|
||||||
return IB::mPos;
|
return IB::mPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UPos UIndex<MetaType>::pmax() const
|
UPos UIndex<MetaT>::pmax() const
|
||||||
{
|
{
|
||||||
return UPos(mRangePtr->size());
|
return UPos(mRangePtr->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UPos UIndex<MetaType>::lmax() const
|
UPos UIndex<MetaT>::lmax() const
|
||||||
{
|
{
|
||||||
return UPos(mRangePtr->size());
|
return UPos(mRangePtr->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
IndexId<0> UIndex<MetaType>::id() const
|
IndexId<0> UIndex<MetaT>::id() const
|
||||||
{
|
{
|
||||||
return IndexId<0>(this->ptrId());
|
return IndexId<0>(this->ptrId());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
const MetaType& UIndex<MetaType>::operator*() const
|
const MetaT& UIndex<MetaT>::operator*() const
|
||||||
{
|
{
|
||||||
return mMetaPtr[IB::mPos];
|
return mMetaPtr[IB::mPos];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
String UIndex<MetaType>::stringMeta() const
|
String UIndex<MetaT>::stringMeta() const
|
||||||
{
|
{
|
||||||
return toString(this->meta());
|
return toString(this->meta());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
const MetaType& UIndex<MetaType>::meta() const
|
const MetaT& UIndex<MetaT>::meta() const
|
||||||
{
|
{
|
||||||
return mMetaPtr[IB::mPos];
|
return mMetaPtr[IB::mPos];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
UIndex<MetaType>& UIndex<MetaType>::at(const MetaType& metaPos)
|
UIndex<MetaT>& UIndex<MetaT>::at(const MetaT& metaPos)
|
||||||
{
|
{
|
||||||
(*this) = mRangePtr->getMeta(metaPos);
|
(*this) = mRangePtr->getMeta(metaPos);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
decltype(auto) UIndex<MetaType>::xpr(const Sptr<UIndex<MetaType>>& _this) const
|
decltype(auto) UIndex<MetaT>::xpr(const Sptr<UIndex<MetaT>>& _this) const
|
||||||
{
|
{
|
||||||
return coproot(mMetaPtr,_this);
|
return coproot(mMetaPtr,_this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
SizeT UIndex<MetaType>::deepFormat() const
|
RangePtr UIndex<MetaT>::prange(const UIndex<MetaT>& end) const
|
||||||
|
{
|
||||||
|
CXZ_ASSERT(end > *this, "got end index position smaller than begin index position");
|
||||||
|
const SizeT beginPos = lex();
|
||||||
|
Vector<SizeT> parts(end.lex()-beginPos);
|
||||||
|
for(auto i = *this; i != end; ++i){
|
||||||
|
parts[i.lex()-beginPos] = i.lex();
|
||||||
|
}
|
||||||
|
return CNORXZ::prange(mRangePtr, parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename MetaT>
|
||||||
|
SizeT UIndex<MetaT>::deepFormat() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
size_t UIndex<MetaType>::dim() const // = 1
|
size_t UIndex<MetaT>::dim() const // = 1
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
Sptr<URange<MetaType>> UIndex<MetaType>::range() const
|
Sptr<URange<MetaT>> UIndex<MetaT>::range() const
|
||||||
{
|
{
|
||||||
return mRangePtr;
|
return mRangePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
template <SizeT I>
|
template <SizeT I>
|
||||||
decltype(auto) UIndex<MetaType>::stepSize(const IndexId<I>& id) const
|
decltype(auto) UIndex<MetaT>::stepSize(const IndexId<I>& id) const
|
||||||
{
|
{
|
||||||
if constexpr(I != 0){
|
if constexpr(I != 0){
|
||||||
return SPos<0>();
|
return SPos<0>();
|
||||||
|
@ -156,34 +169,34 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
template <class Index>
|
template <class Index>
|
||||||
decltype(auto) UIndex<MetaType>::formatFrom(const Index& ind) const
|
decltype(auto) UIndex<MetaT>::formatFrom(const Index& ind) const
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
template <class Index>
|
template <class Index>
|
||||||
decltype(auto) UIndex<MetaType>::slice(const Sptr<Index>& ind) const
|
decltype(auto) UIndex<MetaT>::slice(const Sptr<Index>& ind) const
|
||||||
{
|
{
|
||||||
if(ind != nullptr){
|
if(ind != nullptr){
|
||||||
if(ind->dim() != 0) {
|
if(ind->dim() != 0) {
|
||||||
return Sptr<UIndex<MetaType>>();
|
return Sptr<UIndex<MetaT>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::make_shared<UIndex<MetaType>>(*this);
|
return std::make_shared<UIndex<MetaT>>(*this);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
template <class Xpr, class F>
|
template <class Xpr, class F>
|
||||||
decltype(auto) UIndex<MetaType>::ifor(const Xpr& xpr, F&& f) const
|
decltype(auto) UIndex<MetaT>::ifor(const Xpr& xpr, F&& f) const
|
||||||
{
|
{
|
||||||
return For<0,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward<F>(f));
|
return For<0,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward<F>(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType, class I1>
|
template <typename MetaT, class I1>
|
||||||
decltype(auto) operator*(const Sptr<UIndex<MetaType>>& a, const Sptr<I1>& b)
|
decltype(auto) operator*(const Sptr<UIndex<MetaT>>& a, const Sptr<I1>& b)
|
||||||
{
|
{
|
||||||
return iptrMul(a, b);
|
return iptrMul(a, b);
|
||||||
}
|
}
|
||||||
|
@ -192,32 +205,32 @@ namespace CNORXZ
|
||||||
* URangeFactory *
|
* URangeFactory *
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
URangeFactory<MetaType>::URangeFactory(const Vector<MetaType>& space) :
|
URangeFactory<MetaT>::URangeFactory(const Vector<MetaT>& space) :
|
||||||
mSpace(space) {}
|
mSpace(space) {}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
URangeFactory<MetaType>::URangeFactory(Vector<MetaType>&& space) :
|
URangeFactory<MetaT>::URangeFactory(Vector<MetaT>&& space) :
|
||||||
mSpace(space) {}
|
mSpace(space) {}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
URangeFactory<MetaType>::URangeFactory(const Vector<MetaType>& space, const RangePtr& ref) :
|
URangeFactory<MetaT>::URangeFactory(const Vector<MetaT>& space, const RangePtr& ref) :
|
||||||
mSpace(space), mRef(ref) {}
|
mSpace(space), mRef(ref) {}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
URangeFactory<MetaType>::URangeFactory(Vector<MetaType>&& space, const RangePtr& ref) :
|
URangeFactory<MetaT>::URangeFactory(Vector<MetaT>&& space, const RangePtr& ref) :
|
||||||
mSpace(space), mRef(ref) {}
|
mSpace(space), mRef(ref) {}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
void URangeFactory<MetaType>::make()
|
void URangeFactory<MetaT>::make()
|
||||||
{
|
{
|
||||||
const auto& info = typeid(URange<MetaType>);
|
const auto& info = typeid(URange<MetaT>);
|
||||||
if(mRef != nullptr) {
|
if(mRef != nullptr) {
|
||||||
mProd = this->fromCreated(info, {mRef->id()});
|
mProd = this->fromCreated(info, {mRef->id()});
|
||||||
}
|
}
|
||||||
if(mProd == nullptr){
|
if(mProd == nullptr){
|
||||||
RangePtr key = mProd = std::shared_ptr<URange<MetaType>>
|
RangePtr key = mProd = std::shared_ptr<URange<MetaT>>
|
||||||
( new URange<MetaType>( std::move(mSpace) ) );
|
( new URange<MetaT>( std::move(mSpace) ) );
|
||||||
if(mRef != nullptr) { key = mRef; }
|
if(mRef != nullptr) { key = mRef; }
|
||||||
this->addToCreated(info, { key->id() }, mProd);
|
this->addToCreated(info, { key->id() }, mProd);
|
||||||
}
|
}
|
||||||
|
@ -227,88 +240,88 @@ namespace CNORXZ
|
||||||
* URange *
|
* URange *
|
||||||
***************/
|
***************/
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
URange<MetaType>::URange(const Vector<MetaType>& space) :
|
URange<MetaT>::URange(const Vector<MetaT>& space) :
|
||||||
RangeInterface<URange<MetaType>>(),
|
RangeInterface<URange<MetaT>>(),
|
||||||
mSpace(space)
|
mSpace(space)
|
||||||
{
|
{
|
||||||
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
|
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaT>());
|
||||||
auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
|
auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
|
||||||
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl);
|
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
URange<MetaType>::URange(Vector<MetaType>&& space) :
|
URange<MetaT>::URange(Vector<MetaT>&& space) :
|
||||||
RangeInterface<URange<MetaType>>(),
|
RangeInterface<URange<MetaT>>(),
|
||||||
mSpace(space)
|
mSpace(space)
|
||||||
{
|
{
|
||||||
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
|
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaT>());
|
||||||
auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
|
auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
|
||||||
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << toString(*itdupl));
|
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << toString(*itdupl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
const MetaType& URange<MetaType>::get(SizeT pos) const
|
const MetaT& URange<MetaT>::get(SizeT pos) const
|
||||||
{
|
{
|
||||||
return mSpace[pos];
|
return mSpace[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
const MetaType* URange<MetaType>::get() const
|
const MetaT* URange<MetaT>::get() const
|
||||||
{
|
{
|
||||||
return mSpace.data();
|
return mSpace.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
SizeT URange<MetaType>::getMeta(const MetaType& meta) const
|
SizeT URange<MetaT>::getMeta(const MetaT& meta) const
|
||||||
{
|
{
|
||||||
auto b = mSpace.begin();
|
auto b = mSpace.begin();
|
||||||
auto e = mSpace.end();
|
auto e = mSpace.end();
|
||||||
return std::lower_bound(b, e, meta, std::less<MetaType>()) - b;
|
return std::lower_bound(b, e, meta, std::less<MetaT>()) - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
SizeT URange<MetaType>::size() const
|
SizeT URange<MetaT>::size() const
|
||||||
{
|
{
|
||||||
return mSpace.size();
|
return mSpace.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
SizeT URange<MetaType>::dim() const
|
SizeT URange<MetaT>::dim() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
String URange<MetaType>::stringMeta(SizeT pos) const
|
String URange<MetaT>::stringMeta(SizeT pos) const
|
||||||
{
|
{
|
||||||
return toString(this->get(pos));
|
return toString(this->get(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
const TypeInfo& URange<MetaType>::type() const
|
const TypeInfo& URange<MetaT>::type() const
|
||||||
{
|
{
|
||||||
return typeid(URange<MetaType>);
|
return typeid(URange<MetaT>);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
const TypeInfo& URange<MetaType>::metaType() const
|
const TypeInfo& URange<MetaT>::metaType() const
|
||||||
{
|
{
|
||||||
return typeid(MetaType);
|
return typeid(MetaT);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
RangePtr URange<MetaType>::extend(const RangePtr& r) const
|
RangePtr URange<MetaT>::extend(const RangePtr& r) const
|
||||||
{
|
{
|
||||||
auto rx = rangeCast<URange<MetaType>>(r);
|
auto rx = rangeCast<URange<MetaT>>(r);
|
||||||
auto space = mSpace;
|
auto space = mSpace;
|
||||||
space.insert(space.end(), rx->mSpace.begin(), rx->mSpace.end());
|
space.insert(space.end(), rx->mSpace.begin(), rx->mSpace.end());
|
||||||
return URangeFactory<MetaType>( space ).create();
|
return URangeFactory<MetaT>( space ).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
Vector<Uuid> URange<MetaType>::key() const
|
Vector<Uuid> URange<MetaT>::key() const
|
||||||
{
|
{
|
||||||
return Vector<Uuid> { this->id() };
|
return Vector<Uuid> { this->id() };
|
||||||
}
|
}
|
||||||
|
@ -317,30 +330,30 @@ namespace CNORXZ
|
||||||
* Range Casts *
|
* Range Casts *
|
||||||
*******************/
|
*******************/
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
struct URangeCast
|
struct URangeCast
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static inline Sptr<URange<MetaType>> transform(const RangePtr& r)
|
static inline Sptr<URange<MetaT>> transform(const RangePtr& r)
|
||||||
{
|
{
|
||||||
if(r->type() == typeid(URange<T>)){
|
if(r->type() == typeid(URange<T>)){
|
||||||
auto rr = std::dynamic_pointer_cast<URange<T>>(r);
|
auto rr = std::dynamic_pointer_cast<URange<T>>(r);
|
||||||
Vector<MetaType> v(rr->size());
|
Vector<MetaT> v(rr->size());
|
||||||
std::transform(rr->begin(), rr->end(), v.begin(),
|
std::transform(rr->begin(), rr->end(), v.begin(),
|
||||||
[](const T& x) { return static_cast<MetaType>(x); } );
|
[](const T& x) { return static_cast<MetaT>(x); } );
|
||||||
return std::dynamic_pointer_cast<URange<MetaType>>
|
return std::dynamic_pointer_cast<URange<MetaT>>
|
||||||
( URangeFactory<MetaType>(std::move(v)).create() );
|
( URangeFactory<MetaT>(std::move(v)).create() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Sptr<URange<MetaType>> cast(const RangePtr& r)
|
static inline Sptr<URange<MetaT>> cast(const RangePtr& r)
|
||||||
{
|
{
|
||||||
static_assert(std::is_fundamental<MetaType>::value, "got non-fundamental type");
|
static_assert(std::is_fundamental<MetaT>::value, "got non-fundamental type");
|
||||||
CXZ_ASSERT(r->dim() == 1, "range cast into URange<Int>: source range must have dim = 1, got " << r->dim());
|
CXZ_ASSERT(r->dim() == 1, "range cast into URange<Int>: source range must have dim = 1, got " << r->dim());
|
||||||
Sptr<URange<MetaType>> o = nullptr;
|
Sptr<URange<MetaT>> o = nullptr;
|
||||||
o = transform<SizeT>(r); if(o) return o;
|
o = transform<SizeT>(r); if(o) return o;
|
||||||
o = transform<Int>(r); if(o) return o;
|
o = transform<Int>(r); if(o) return o;
|
||||||
o = transform<LInt>(r); if(o) return o;
|
o = transform<LInt>(r); if(o) return o;
|
||||||
|
@ -415,11 +428,11 @@ namespace CNORXZ
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
Sptr<URange<MetaType>> RangeCast<URange<MetaType>>::func(const RangePtr& r)
|
Sptr<URange<MetaT>> RangeCast<URange<MetaT>>::func(const RangePtr& r)
|
||||||
{
|
{
|
||||||
if constexpr(std::is_fundamental<MetaType>::value or is_vector<MetaType>::value){
|
if constexpr(std::is_fundamental<MetaT>::value or is_vector<MetaT>::value){
|
||||||
return URangeCast<MetaType>::cast(r);
|
return URangeCast<MetaT>::cast(r);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CXZ_ERROR("no range cast available for input range '" << r->type().name() << "'");
|
CXZ_ERROR("no range cast available for input range '" << r->type().name() << "'");
|
||||||
|
|
|
@ -55,6 +55,8 @@ namespace CNORXZ
|
||||||
UIndex& at(const MetaT& metaPos);
|
UIndex& at(const MetaT& metaPos);
|
||||||
decltype(auto) xpr(const Sptr<UIndex<MetaType>>& _this) const;
|
decltype(auto) xpr(const Sptr<UIndex<MetaType>>& _this) const;
|
||||||
|
|
||||||
|
RangePtr prange(const UIndex<MetaType>& end) const;
|
||||||
|
|
||||||
SizeT deepFormat() const;
|
SizeT deepFormat() const;
|
||||||
/*
|
/*
|
||||||
template <class Index>
|
template <class Index>
|
||||||
|
@ -94,12 +96,13 @@ namespace CNORXZ
|
||||||
RangePtr mRef;
|
RangePtr mRef;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename MetaType>
|
template <typename MetaT>
|
||||||
class URange : public RangeInterface<URange<MetaType>>
|
class URange : public RangeInterface<URange<MetaT>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef RangeBase RB;
|
typedef RangeBase RB;
|
||||||
typedef UIndex<MetaType> IndexType;
|
typedef UIndex<MetaT> IndexType;
|
||||||
|
typedef MetaT MetaType;
|
||||||
|
|
||||||
friend URangeFactory<MetaType>;
|
friend URangeFactory<MetaType>;
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,12 @@ namespace CNORXZ
|
||||||
return mI->stepSize(id);
|
return mI->stepSize(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Index, typename Meta>
|
||||||
|
RangePtr XIndex<Index,Meta>::prange(const XIndexPtr& end) const
|
||||||
|
{
|
||||||
|
return mI->prange( *std::dynamic_pointer_cast<Index>(end) );
|
||||||
|
}
|
||||||
|
|
||||||
template <class Index, typename Meta>
|
template <class Index, typename Meta>
|
||||||
Vector<SizeT> XIndex<Index,Meta>::deepFormat() const
|
Vector<SizeT> XIndex<Index,Meta>::deepFormat() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,6 +38,7 @@ namespace CNORXZ
|
||||||
virtual SizeT dim() const = 0;
|
virtual SizeT dim() const = 0;
|
||||||
virtual RangePtr range() const = 0;
|
virtual RangePtr range() const = 0;
|
||||||
virtual UPos stepSize(const IndexId<0>& id) const = 0;
|
virtual UPos stepSize(const IndexId<0>& id) const = 0;
|
||||||
|
virtual RangePtr prange(const XIndexPtr& end) const = 0;
|
||||||
virtual Vector<SizeT> deepFormat() const = 0;
|
virtual Vector<SizeT> deepFormat() const = 0;
|
||||||
//virtual Vector<XIndexPtr> pack() const = 0;
|
//virtual Vector<XIndexPtr> pack() const = 0;
|
||||||
//virtual Vector<SizeT> format() const = 0;
|
//virtual Vector<SizeT> format() const = 0;
|
||||||
|
@ -92,6 +93,7 @@ namespace CNORXZ
|
||||||
virtual SizeT dim() const override final;
|
virtual SizeT dim() const override final;
|
||||||
virtual RangePtr range() const override final;
|
virtual RangePtr range() const override final;
|
||||||
virtual UPos stepSize(const IndexId<0>& id) const override final;
|
virtual UPos stepSize(const IndexId<0>& id) const override final;
|
||||||
|
virtual RangePtr prange(const XIndexPtr& end) const override final;
|
||||||
virtual Vector<SizeT> deepFormat() const override final;
|
virtual Vector<SizeT> deepFormat() const override final;
|
||||||
//virtual Vector<XIndexPtr> pack() const override final;
|
//virtual Vector<XIndexPtr> pack() const override final;
|
||||||
//virtual Vector<SizeT> format() const override final;
|
//virtual Vector<SizeT> format() const override final;
|
||||||
|
|
|
@ -66,6 +66,7 @@ namespace CNORXZ
|
||||||
YIndex& operator()();
|
YIndex& operator()();
|
||||||
|
|
||||||
const DPack& pack() const;
|
const DPack& pack() const;
|
||||||
|
RangePtr prange(const YIndex& end) const;
|
||||||
Vector<SizeT> deepFormat() const;
|
Vector<SizeT> deepFormat() const;
|
||||||
const YFormat& format() const;
|
const YFormat& format() const;
|
||||||
const YFormat& lexFormat() const;
|
const YFormat& lexFormat() const;
|
||||||
|
@ -160,9 +161,6 @@ 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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "ranges/ranges.h"
|
#include "ranges/ranges.h"
|
||||||
|
#include "ranges/prange.h"
|
||||||
#include "operation/operation.h"
|
#include "operation/operation.h"
|
||||||
|
|
||||||
namespace CNORXZ
|
namespace CNORXZ
|
||||||
|
@ -116,6 +117,17 @@ namespace CNORXZ
|
||||||
return coproot(m.data(), _this);
|
return coproot(m.data(), _this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RangePtr CIndex::prange(const CIndex& end) const
|
||||||
|
{
|
||||||
|
CXZ_ASSERT(end > *this, "got end index position smaller than begin index position");
|
||||||
|
const SizeT beginPos = lex();
|
||||||
|
Vector<SizeT> parts(end.lex() - beginPos);
|
||||||
|
for(auto i = *this; i != end; ++i){
|
||||||
|
parts[i.lex()-beginPos] = i.lex();
|
||||||
|
}
|
||||||
|
return CNORXZ::prange(mRangePtr, parts);
|
||||||
|
}
|
||||||
|
|
||||||
SizeT CIndex::deepFormat() const
|
SizeT CIndex::deepFormat() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -167,6 +167,11 @@ namespace CNORXZ
|
||||||
return mI->xpr(_this->xptr());
|
return mI->xpr(_this->xptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RangePtr DIndex::prange(const DIndex& end) const
|
||||||
|
{
|
||||||
|
return mI->prange( end.xptr() );
|
||||||
|
}
|
||||||
|
|
||||||
Vector<SizeT> DIndex::deepFormat() const
|
Vector<SizeT> DIndex::deepFormat() const
|
||||||
{
|
{
|
||||||
return mI->deepFormat();
|
return mI->deepFormat();
|
||||||
|
|
|
@ -368,6 +368,17 @@ namespace CNORXZ
|
||||||
return mIs;
|
return mIs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RangePtr YIndex::prange(const YIndex& end) const
|
||||||
|
{
|
||||||
|
CXZ_ASSERT(dim() == end.dim(), "end index has different number of dimensions ("
|
||||||
|
<< end.dim() << ") than begin index (" << dim() << ")");
|
||||||
|
Vector<RangePtr> v(dim());
|
||||||
|
for(SizeT i = 0; i != dim(); ++i){
|
||||||
|
v[i] = mIs[i]->prange( end.pack()[i] );
|
||||||
|
}
|
||||||
|
return YRangeFactory(v).create();
|
||||||
|
}
|
||||||
|
|
||||||
Vector<SizeT> YIndex::deepFormat() const
|
Vector<SizeT> YIndex::deepFormat() const
|
||||||
{
|
{
|
||||||
Vector<Vector<SizeT>> dfv(mIs.size());
|
Vector<Vector<SizeT>> dfv(mIs.size());
|
||||||
|
@ -561,17 +572,4 @@ 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue