diff --git a/src/include/ranges/prange.cc.h b/src/include/ranges/prange.cc.h index 239375d..fc41d7f 100644 --- a/src/include/ranges/prange.cc.h +++ b/src/include/ranges/prange.cc.h @@ -3,6 +3,7 @@ #define __cxz_prange_cc_h__ #include "prange.h" +#include "urange.h" namespace CNORXZ { @@ -130,7 +131,8 @@ namespace CNORXZ template RangePtr PIndex::prange(const PIndex& 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 @@ -268,7 +271,8 @@ namespace CNORXZ template void PRangeFactory::make() { - const Vector key = { mRange->id() }; + RangePtr purange = urange(mParts); + const Vector key = { mRange->id(), purange->id() }; const auto& info = typeid(PRange); 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 diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index 43fbfe3..94744c1 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -130,7 +130,8 @@ namespace CNORXZ template RangePtr UIndex::prange(const UIndex& 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 parts(last.lex()-beginPos+1); for(auto i = *this; i != last+1; ++i){ @@ -439,6 +440,12 @@ namespace CNORXZ return nullptr; } } + + template + RangePtr urange(const Vector& space) + { + return URangeFactory(space).create(); + } } diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index 0ef9c21..2eeb6a3 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -136,6 +136,9 @@ namespace CNORXZ { static Sptr> func(const RangePtr& r); }; + + template + RangePtr urange(const Vector& space); } #endif diff --git a/src/lib/ranges/crange.cc b/src/lib/ranges/crange.cc index a52e6ba..015bf67 100644 --- a/src/lib/ranges/crange.cc +++ b/src/lib/ranges/crange.cc @@ -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 parts(last.lex() - beginPos + 1); diff --git a/src/tests/range_unit_test.cc b/src/tests/range_unit_test.cc index b6c4802..ee4bfeb 100644 --- a/src/tests/range_unit_test.cc +++ b/src/tests/range_unit_test.cc @@ -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(pr2); + + EXPECT_EQ(pr2->size(), pSize2); + EXPECT_EQ(prx2->size(), pSize2); + + const SizeT mmsize2 = lastJ2-begJ2+1; + auto mkm2 = [&](SizeT i) { + return Vector({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