test prange of prange + corresp fixes

This commit is contained in:
Christian Zimmermann 2023-10-22 17:06:30 +02:00
parent eb5276c967
commit 2a763d67be
5 changed files with 49 additions and 6 deletions

View file

@ -3,6 +3,7 @@
#define __cxz_prange_cc_h__
#include "prange.h"
#include "urange.h"
namespace CNORXZ
{
@ -130,7 +131,8 @@ namespace CNORXZ
template <class IndexT>
RangePtr PIndex<IndexT>::prange(const PIndex<IndexT>& last) const
{
CXZ_ASSERT(last > *this, "got last index position smaller than begin index position");
CXZ_ASSERT(last >= *this, "got last index position (" << last.lex()
<< ") smaller than begin index position (" << lex() << ")");
auto oi = *orig();
auto olast = *last.orig();
const SizeT beginPos = oi.lex();
@ -138,7 +140,8 @@ namespace CNORXZ
for(auto i = oi; i != olast+1; ++i){
parts[i.lex()-beginPos] = i.lex();
}
return CNORXZ::prange(mRangePtr->orig(), parts);
auto x = CNORXZ::prange(mRangePtr->orig(), parts);
return x;
}
template <class IndexT>
@ -268,7 +271,8 @@ namespace CNORXZ
template <class RangeT>
void PRangeFactory<RangeT>::make()
{
const Vector<Uuid> key = { mRange->id() };
RangePtr purange = urange(mParts);
const Vector<Uuid> key = { mRange->id(), purange->id() };
const auto& info = typeid(PRange<RangeT>);
mProd = this->fromCreated(info, key);
if(mProd == nullptr) {
@ -351,7 +355,7 @@ namespace CNORXZ
mRange(range), mParts(_parts)
{
const auto max = std::max_element( mParts.begin(), mParts.end() );
mParts.push_back( *max );
mParts.push_back( *max+1 );
}
template <class RangeT>

View file

@ -130,7 +130,8 @@ namespace CNORXZ
template <typename MetaT>
RangePtr UIndex<MetaT>::prange(const UIndex<MetaT>& last) const
{
CXZ_ASSERT(last > *this, "got last 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();
Vector<SizeT> parts(last.lex()-beginPos+1);
for(auto i = *this; i != last+1; ++i){
@ -439,6 +440,12 @@ namespace CNORXZ
return nullptr;
}
}
template <typename MetaT>
RangePtr urange(const Vector<MetaT>& space)
{
return URangeFactory<MetaT>(space).create();
}
}

View file

@ -136,6 +136,9 @@ namespace CNORXZ
{
static Sptr<URange<MetaType>> func(const RangePtr& r);
};
template <typename MetaT>
RangePtr urange(const Vector<MetaT>& space);
}
#endif

View file

@ -119,7 +119,7 @@ namespace CNORXZ
RangePtr CIndex::prange(const CIndex& last) const
{
CXZ_ASSERT(last > *this, "got last index position (" << last.lex()
CXZ_ASSERT(last >= *this, "got last index position (" << last.lex()
<< ") smaller than begin index position (" << lex() << ")");
const SizeT beginPos = lex();
Vector<SizeT> parts(last.lex() - beginPos + 1);

View file

@ -513,6 +513,35 @@ namespace
for(auto i = prx->begin(); i != prx->end(); ++i){
EXPECT_TRUE(*i == mkm(i.lex()));
}
const SizeT begI2 = 1;
const SizeT lastI2 = 3;
const SizeT begJ2 = 0;
const SizeT lastJ2 = 0;
const SizeT begPos2 = begI2 * (lastJ-begJ+1) + begJ2;
const SizeT lastPos2 = lastI2 * (lastJ-begJ+1) + lastJ2;
const SizeT pSize2 = (lastI2-begI2+1)*(lastJ2-begJ2+1);
auto beg2 = prx->begin();
auto last2 = prx->begin();
beg2 = begPos2;
last2 = lastPos2;
auto pr2 = beg2.prange(last2);
auto prx2 = std::dynamic_pointer_cast<YRange>(pr2);
EXPECT_EQ(pr2->size(), pSize2);
EXPECT_EQ(prx2->size(), pSize2);
const SizeT mmsize2 = lastJ2-begJ2+1;
auto mkm2 = [&](SizeT i) {
return Vector<DType>({DType(i/mmsize2+begI2+begI),DType(mMeta[i % mmsize2+begJ2+begJ])}); };
for(auto i = prx2->begin(); i != prx2->end(); ++i){
EXPECT_TRUE(*i == mkm2(i.lex()));
}
}
// RCast_Test