tests and fix bugs regarding prange
This commit is contained in:
parent
cf0e7c5856
commit
eb5276c967
15 changed files with 125 additions and 40 deletions
|
@ -47,7 +47,7 @@ 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;
|
RangePtr prange(const CIndex& last) const;
|
||||||
|
|
||||||
SizeT deepFormat() const;
|
SizeT deepFormat() const;
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -480,12 +480,12 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class FormatT, class... Indices>
|
template <class FormatT, class... Indices>
|
||||||
RangePtr GMIndex<FormatT,Indices...>::prange(const MIndex<Indices...>& end) const
|
RangePtr GMIndex<FormatT,Indices...>::prange(const MIndex<Indices...>& last) const
|
||||||
{
|
{
|
||||||
return iter<0,NI>
|
return iter<0,NI>
|
||||||
( [&](auto i) {
|
( [&](auto i) {
|
||||||
typedef typename std::remove_reference<decltype(*mIPack[i])>::type::RangeType RangeT;
|
typedef typename std::remove_reference<decltype(*mIPack[i])>::type::RangeType RangeT;
|
||||||
return std::dynamic_pointer_cast<RangeT>( mIPack[i]->prange( *end.pack()[i] ) );
|
return std::dynamic_pointer_cast<RangeT>( mIPack[i]->prange( *last.pack()[i] ) );
|
||||||
},
|
},
|
||||||
[](const auto&... e) { return mrange(e...); }
|
[](const auto&... e) { return mrange(e...); }
|
||||||
);
|
);
|
||||||
|
|
|
@ -81,7 +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;
|
RangePtr prange(const MIndex<Indices...>& last) const;
|
||||||
auto deepFormat() const;
|
auto deepFormat() const;
|
||||||
GMIndex& setFormat(const FormatT& bs);
|
GMIndex& setFormat(const FormatT& bs);
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,13 @@ namespace CNORXZ
|
||||||
template <class IndexT>
|
template <class IndexT>
|
||||||
PIndex<IndexT>::PIndex(const RangePtr& range, SizeT pos) :
|
PIndex<IndexT>::PIndex(const RangePtr& range, SizeT pos) :
|
||||||
IndexInterface<PIndex<IndexT>,typename IndexT::MetaType>(pos),
|
IndexInterface<PIndex<IndexT>,typename IndexT::MetaType>(pos),
|
||||||
mRangePtr(rangeCast<RangeType>(range)),
|
mRangePtr(rangeCast<RangeType>(range))//,
|
||||||
mOrig(std::make_shared<IndexT>(mRangePtr->orig(),mRangePtr->parts()[pos]))
|
//mOrig(std::make_shared<IndexT>(mRangePtr->orig(),mRangePtr->parts()[pos]))
|
||||||
{}
|
{
|
||||||
|
auto o = mRangePtr->orig();
|
||||||
|
auto p = mRangePtr->parts()[pos];
|
||||||
|
mOrig = std::make_shared<IndexT>(o,p);
|
||||||
|
}
|
||||||
|
|
||||||
template <class IndexT>
|
template <class IndexT>
|
||||||
PIndex<IndexT>& PIndex<IndexT>::operator=(SizeT lexpos)
|
PIndex<IndexT>& PIndex<IndexT>::operator=(SizeT lexpos)
|
||||||
|
@ -124,14 +128,14 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexT>
|
template <class IndexT>
|
||||||
RangePtr PIndex<IndexT>::prange(const PIndex<IndexT>& end) const
|
RangePtr PIndex<IndexT>::prange(const PIndex<IndexT>& last) const
|
||||||
{
|
{
|
||||||
CXZ_ASSERT(end > *this, "got end index position smaller than begin index position");
|
CXZ_ASSERT(last > *this, "got last index position smaller than begin index position");
|
||||||
auto oi = *orig();
|
auto oi = *orig();
|
||||||
auto oend = *end.orig();
|
auto olast = *last.orig();
|
||||||
const SizeT beginPos = oi.lex();
|
const SizeT beginPos = oi.lex();
|
||||||
Vector<SizeT> parts(oend.lex()-beginPos);
|
Vector<SizeT> parts(olast.lex()-beginPos+1);
|
||||||
for(auto i = oi; i != oend; ++i){
|
for(auto i = oi; i != olast+1; ++i){
|
||||||
parts[i.lex()-beginPos] = i.lex();
|
parts[i.lex()-beginPos] = i.lex();
|
||||||
}
|
}
|
||||||
return CNORXZ::prange(mRangePtr->orig(), parts);
|
return CNORXZ::prange(mRangePtr->orig(), parts);
|
||||||
|
@ -280,7 +284,7 @@ namespace CNORXZ
|
||||||
template <class RangeT>
|
template <class RangeT>
|
||||||
SizeT PRange<RangeT>::size() const
|
SizeT PRange<RangeT>::size() const
|
||||||
{
|
{
|
||||||
return mParts.size();
|
return mParts.size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class RangeT>
|
template <class RangeT>
|
||||||
|
@ -345,7 +349,10 @@ namespace CNORXZ
|
||||||
template <class RangeT>
|
template <class RangeT>
|
||||||
PRange<RangeT>::PRange(const Sptr<RangeT>& range, const Vector<SizeT>& _parts) :
|
PRange<RangeT>::PRange(const Sptr<RangeT>& range, const Vector<SizeT>& _parts) :
|
||||||
mRange(range), mParts(_parts)
|
mRange(range), mParts(_parts)
|
||||||
{}
|
{
|
||||||
|
const auto max = std::max_element( mParts.begin(), mParts.end() );
|
||||||
|
mParts.push_back( *max );
|
||||||
|
}
|
||||||
|
|
||||||
template <class RangeT>
|
template <class RangeT>
|
||||||
Vector<Uuid> PRange<RangeT>::key() const
|
Vector<Uuid> PRange<RangeT>::key() const
|
||||||
|
|
|
@ -41,7 +41,7 @@ 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;
|
RangePtr prange(const PIndex<IndexT>& last) const;
|
||||||
decltype(auto) deepFormat() const;
|
decltype(auto) deepFormat() const;
|
||||||
|
|
||||||
String stringMeta() const;
|
String stringMeta() const;
|
||||||
|
|
|
@ -143,12 +143,12 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaT, SizeT S>
|
template <typename MetaT, SizeT S>
|
||||||
RangePtr SIndex<MetaT,S>::prange(const SIndex<MetaType,S>& end) const
|
RangePtr SIndex<MetaT,S>::prange(const SIndex<MetaType,S>& last) const
|
||||||
{
|
{
|
||||||
CXZ_ASSERT(end > *this, "got end index position smaller than begin index position");
|
CXZ_ASSERT(last > *this, "got last index position smaller than begin index position");
|
||||||
const SizeT beginPos = lex();
|
const SizeT beginPos = lex();
|
||||||
Vector<SizeT> parts(end.lex()-beginPos);
|
Vector<SizeT> parts(last.lex()-beginPos+1);
|
||||||
for(auto i = *this; i != end; ++i){
|
for(auto i = *this; i != last+1; ++i){
|
||||||
parts[i.lex()-beginPos] = i.lex();
|
parts[i.lex()-beginPos] = i.lex();
|
||||||
}
|
}
|
||||||
return CNORXZ::prange(mRangePtr, parts);
|
return CNORXZ::prange(mRangePtr, parts);
|
||||||
|
|
|
@ -48,7 +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;
|
RangePtr prange(const SIndex<MetaType,S>& last) const;
|
||||||
SizeT deepFormat() const;
|
SizeT deepFormat() const;
|
||||||
/*
|
/*
|
||||||
template <class Index>
|
template <class Index>
|
||||||
|
|
|
@ -128,12 +128,12 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename MetaT>
|
template <typename MetaT>
|
||||||
RangePtr UIndex<MetaT>::prange(const UIndex<MetaT>& end) const
|
RangePtr UIndex<MetaT>::prange(const UIndex<MetaT>& last) const
|
||||||
{
|
{
|
||||||
CXZ_ASSERT(end > *this, "got end index position smaller than begin index position");
|
CXZ_ASSERT(last > *this, "got last index position smaller than begin index position");
|
||||||
const SizeT beginPos = lex();
|
const SizeT beginPos = lex();
|
||||||
Vector<SizeT> parts(end.lex()-beginPos);
|
Vector<SizeT> parts(last.lex()-beginPos+1);
|
||||||
for(auto i = *this; i != end; ++i){
|
for(auto i = *this; i != last+1; ++i){
|
||||||
parts[i.lex()-beginPos] = i.lex();
|
parts[i.lex()-beginPos] = i.lex();
|
||||||
}
|
}
|
||||||
return CNORXZ::prange(mRangePtr, parts);
|
return CNORXZ::prange(mRangePtr, parts);
|
||||||
|
|
|
@ -55,7 +55,7 @@ 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;
|
RangePtr prange(const UIndex<MetaType>& last) const;
|
||||||
|
|
||||||
SizeT deepFormat() const;
|
SizeT deepFormat() const;
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -128,9 +128,9 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Index, typename Meta>
|
template <class Index, typename Meta>
|
||||||
RangePtr XIndex<Index,Meta>::prange(const XIndexPtr& end) const
|
RangePtr XIndex<Index,Meta>::prange(const XIndexPtr& last) const
|
||||||
{
|
{
|
||||||
return mI->prange( *std::dynamic_pointer_cast<Index>(end) );
|
return mI->prange( std::dynamic_pointer_cast<XIndex<Index,Meta>>(last)->get() );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Index, typename Meta>
|
template <class Index, typename Meta>
|
||||||
|
|
|
@ -38,7 +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 RangePtr prange(const XIndexPtr& last) 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;
|
||||||
|
@ -93,7 +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 RangePtr prange(const XIndexPtr& last) 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,7 +66,7 @@ namespace CNORXZ
|
||||||
YIndex& operator()();
|
YIndex& operator()();
|
||||||
|
|
||||||
const DPack& pack() const;
|
const DPack& pack() const;
|
||||||
RangePtr prange(const YIndex& end) const;
|
RangePtr prange(const YIndex& last) 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;
|
||||||
|
|
|
@ -117,12 +117,13 @@ namespace CNORXZ
|
||||||
return coproot(m.data(), _this);
|
return coproot(m.data(), _this);
|
||||||
}
|
}
|
||||||
|
|
||||||
RangePtr CIndex::prange(const CIndex& end) const
|
RangePtr CIndex::prange(const CIndex& last) const
|
||||||
{
|
{
|
||||||
CXZ_ASSERT(end > *this, "got end index position smaller than begin index position");
|
CXZ_ASSERT(last > *this, "got last index position (" << last.lex()
|
||||||
|
<< ") smaller than begin index position (" << lex() << ")");
|
||||||
const SizeT beginPos = lex();
|
const SizeT beginPos = lex();
|
||||||
Vector<SizeT> parts(end.lex() - beginPos);
|
Vector<SizeT> parts(last.lex() - beginPos + 1);
|
||||||
for(auto i = *this; i != end; ++i){
|
for(auto i = *this; i != last+1; ++i){
|
||||||
parts[i.lex()-beginPos] = i.lex();
|
parts[i.lex()-beginPos] = i.lex();
|
||||||
}
|
}
|
||||||
return CNORXZ::prange(mRangePtr, parts);
|
return CNORXZ::prange(mRangePtr, parts);
|
||||||
|
|
|
@ -368,13 +368,13 @@ namespace CNORXZ
|
||||||
return mIs;
|
return mIs;
|
||||||
}
|
}
|
||||||
|
|
||||||
RangePtr YIndex::prange(const YIndex& end) const
|
RangePtr YIndex::prange(const YIndex& last) const
|
||||||
{
|
{
|
||||||
CXZ_ASSERT(dim() == end.dim(), "end index has different number of dimensions ("
|
CXZ_ASSERT(dim() == last.dim(), "end index has different number of dimensions ("
|
||||||
<< end.dim() << ") than begin index (" << dim() << ")");
|
<< last.dim() << ") than begin index (" << dim() << ")");
|
||||||
Vector<RangePtr> v(dim());
|
Vector<RangePtr> v(dim());
|
||||||
for(SizeT i = 0; i != dim(); ++i){
|
for(SizeT i = 0; i != dim(); ++i){
|
||||||
v[i] = mIs[i]->prange( end.pack()[i] );
|
v[i] = mIs[i]->prange( last.pack()[i] );
|
||||||
}
|
}
|
||||||
return YRangeFactory(v).create();
|
return YRangeFactory(v).create();
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,9 +120,32 @@ namespace
|
||||||
for(auto x: *crx){
|
for(auto x: *crx){
|
||||||
EXPECT_EQ(x, cnt2++);
|
EXPECT_EQ(x, cnt2++);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CR_Test, prange)
|
||||||
|
{
|
||||||
|
auto crx = std::dynamic_pointer_cast<CRange>(cr);
|
||||||
|
auto beg = crx->begin();
|
||||||
|
auto end = crx->end();
|
||||||
|
|
||||||
|
const SizeT begPos = 1;
|
||||||
|
const SizeT endPos = mSize-2;
|
||||||
|
const SizeT pSize = endPos - begPos;
|
||||||
|
beg += begPos;
|
||||||
|
end -= mSize-endPos+1;
|
||||||
|
auto pr = beg.prange(end);
|
||||||
|
auto prx = std::dynamic_pointer_cast<PRange<CRange>>(pr);
|
||||||
|
|
||||||
|
EXPECT_EQ(pr->size(), pSize);
|
||||||
|
EXPECT_EQ(prx->size(), pSize);
|
||||||
|
|
||||||
|
for(auto i = prx->begin(); i != prx->end(); ++i){
|
||||||
|
EXPECT_EQ(*i, i.lex()+begPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_EQ(prx->orig(),cr);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(UR_Test, Basics)
|
TEST_F(UR_Test, Basics)
|
||||||
{
|
{
|
||||||
auto urx = std::dynamic_pointer_cast<URange<String>>(ur);
|
auto urx = std::dynamic_pointer_cast<URange<String>>(ur);
|
||||||
|
@ -155,6 +178,29 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(UR_Test, prange)
|
||||||
|
{
|
||||||
|
auto urx = std::dynamic_pointer_cast<URange<String>>(ur);
|
||||||
|
auto beg = urx->begin();
|
||||||
|
auto end = urx->end();
|
||||||
|
|
||||||
|
const SizeT begPos = 1;
|
||||||
|
const SizeT endPos = mMeta.size() - 2;
|
||||||
|
const SizeT pSize = endPos - begPos;
|
||||||
|
beg += begPos;
|
||||||
|
end -= mMeta.size() - endPos + 1;
|
||||||
|
auto pr = beg.prange(end);
|
||||||
|
auto prx = std::dynamic_pointer_cast<PRange<URange<String>>>(pr);
|
||||||
|
|
||||||
|
EXPECT_EQ(pr->size(), pSize);
|
||||||
|
EXPECT_EQ(prx->size(), pSize);
|
||||||
|
|
||||||
|
for(auto i = prx->begin(); i != prx->end(); ++i){
|
||||||
|
EXPECT_EQ(*i, mMeta[i.lex()+begPos]);
|
||||||
|
}
|
||||||
|
EXPECT_EQ(prx->orig(),ur);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(MR_Test, Basics2d)
|
TEST_F(MR_Test, Basics2d)
|
||||||
{
|
{
|
||||||
auto mrx = std::dynamic_pointer_cast<MRange<CRange,URange<String>>>(mr);
|
auto mrx = std::dynamic_pointer_cast<MRange<CRange,URange<String>>>(mr);
|
||||||
|
@ -437,7 +483,38 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(YR_Test, prange)
|
||||||
|
{
|
||||||
|
auto yrx = std::dynamic_pointer_cast<YRange>(yr);
|
||||||
|
auto beg = yrx->begin();
|
||||||
|
auto last = yrx->end();
|
||||||
|
|
||||||
|
const SizeT begI = 1;
|
||||||
|
const SizeT lastI = mSize - 2 - 1;
|
||||||
|
const SizeT begJ = 1;
|
||||||
|
const SizeT lastJ = mMeta.size() - 1;
|
||||||
|
|
||||||
|
const SizeT begPos = begI * mMeta.size() + begJ;
|
||||||
|
const SizeT lastPos = lastI * mMeta.size() + lastJ;
|
||||||
|
const SizeT pSize = (lastI-begI+1)*(lastJ-begJ+1);
|
||||||
|
beg += begPos;
|
||||||
|
last = lastPos;
|
||||||
|
auto pr = beg.prange(last);
|
||||||
|
auto prx = std::dynamic_pointer_cast<YRange>(pr);
|
||||||
|
|
||||||
|
EXPECT_EQ(pr->size(), pSize);
|
||||||
|
EXPECT_EQ(prx->size(), pSize);
|
||||||
|
|
||||||
|
const SizeT mmsize = lastJ-begJ+1;
|
||||||
|
auto mkm = [&](SizeT i) {
|
||||||
|
return Vector<DType>({DType(i/mmsize+begI),DType(mMeta[i % mmsize+begJ])}); };
|
||||||
|
|
||||||
|
for(auto i = prx->begin(); i != prx->end(); ++i){
|
||||||
|
EXPECT_TRUE(*i == mkm(i.lex()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RCast_Test
|
// RCast_Test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue