test prange of prange + corresp fixes
This commit is contained in:
parent
eb5276c967
commit
2a763d67be
5 changed files with 49 additions and 6 deletions
|
@ -3,6 +3,7 @@
|
||||||
#define __cxz_prange_cc_h__
|
#define __cxz_prange_cc_h__
|
||||||
|
|
||||||
#include "prange.h"
|
#include "prange.h"
|
||||||
|
#include "urange.h"
|
||||||
|
|
||||||
namespace CNORXZ
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
@ -130,7 +131,8 @@ namespace CNORXZ
|
||||||
template <class IndexT>
|
template <class IndexT>
|
||||||
RangePtr PIndex<IndexT>::prange(const PIndex<IndexT>& last) const
|
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 oi = *orig();
|
||||||
auto olast = *last.orig();
|
auto olast = *last.orig();
|
||||||
const SizeT beginPos = oi.lex();
|
const SizeT beginPos = oi.lex();
|
||||||
|
@ -138,7 +140,8 @@ namespace CNORXZ
|
||||||
for(auto i = oi; i != olast+1; ++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);
|
auto x = CNORXZ::prange(mRangePtr->orig(), parts);
|
||||||
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexT>
|
template <class IndexT>
|
||||||
|
@ -268,7 +271,8 @@ namespace CNORXZ
|
||||||
template <class RangeT>
|
template <class RangeT>
|
||||||
void PRangeFactory<RangeT>::make()
|
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>);
|
const auto& info = typeid(PRange<RangeT>);
|
||||||
mProd = this->fromCreated(info, key);
|
mProd = this->fromCreated(info, key);
|
||||||
if(mProd == nullptr) {
|
if(mProd == nullptr) {
|
||||||
|
@ -351,7 +355,7 @@ namespace CNORXZ
|
||||||
mRange(range), mParts(_parts)
|
mRange(range), mParts(_parts)
|
||||||
{
|
{
|
||||||
const auto max = std::max_element( mParts.begin(), mParts.end() );
|
const auto max = std::max_element( mParts.begin(), mParts.end() );
|
||||||
mParts.push_back( *max );
|
mParts.push_back( *max+1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class RangeT>
|
template <class RangeT>
|
||||||
|
|
|
@ -130,7 +130,8 @@ namespace CNORXZ
|
||||||
template <typename MetaT>
|
template <typename MetaT>
|
||||||
RangePtr UIndex<MetaT>::prange(const UIndex<MetaT>& last) const
|
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();
|
const SizeT beginPos = lex();
|
||||||
Vector<SizeT> parts(last.lex()-beginPos+1);
|
Vector<SizeT> parts(last.lex()-beginPos+1);
|
||||||
for(auto i = *this; i != last+1; ++i){
|
for(auto i = *this; i != last+1; ++i){
|
||||||
|
@ -440,6 +441,12 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename MetaT>
|
||||||
|
RangePtr urange(const Vector<MetaT>& space)
|
||||||
|
{
|
||||||
|
return URangeFactory<MetaT>(space).create();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -136,6 +136,9 @@ namespace CNORXZ
|
||||||
{
|
{
|
||||||
static Sptr<URange<MetaType>> func(const RangePtr& r);
|
static Sptr<URange<MetaType>> func(const RangePtr& r);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename MetaT>
|
||||||
|
RangePtr urange(const Vector<MetaT>& space);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace CNORXZ
|
||||||
|
|
||||||
RangePtr CIndex::prange(const CIndex& last) const
|
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() << ")");
|
<< ") smaller than begin index position (" << lex() << ")");
|
||||||
const SizeT beginPos = lex();
|
const SizeT beginPos = lex();
|
||||||
Vector<SizeT> parts(last.lex() - beginPos + 1);
|
Vector<SizeT> parts(last.lex() - beginPos + 1);
|
||||||
|
|
|
@ -513,6 +513,35 @@ namespace
|
||||||
for(auto i = prx->begin(); i != prx->end(); ++i){
|
for(auto i = prx->begin(); i != prx->end(); ++i){
|
||||||
EXPECT_TRUE(*i == mkm(i.lex()));
|
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
|
// RCast_Test
|
||||||
|
|
Loading…
Reference in a new issue