diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 376a61e..447f25b 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -16,6 +16,8 @@ namespace CNORXZ { static_assert(sizeof...(Is) == NI, "sequence size does not match number of indices"); + CXZ_ASSERT( ( (mRange->sub(Is) != nullptr) and ... ), + "no subranges available" ); return std::make_tuple( std::make_shared( mRange->sub(Is) )... ); } @@ -84,27 +86,27 @@ namespace CNORXZ template MIndex::MIndex(const MIndex& i) : IndexInterface,Tuple>(i.pos()), + mRange(rangeCast(i.range())), mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})), - mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{})), - mRange(rangeCast(i.range())) + mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{})) {} template MIndex& MIndex::operator=(const MIndex& i) { IndexInterface,Tuple>::operator=(i); + mRange = rangeCast(i.range()); mIPack = mkIPack(IB::mPos, Isqr<0,NI>{}); mBlockSizes = mkBlockSizes(mIPack,Isqr<0,NI-1>{}); - mRange = rangeCast(i.range()); return *this; } template MIndex::MIndex(const RangePtr& range, SizeT pos) : IndexInterface,Tuple>(0), + mRange(rangeCast(range)), mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})), - mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{})), - mRange(rangeCast(range)) + mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{})) { (*this) = pos; } diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index a4a2e80..e8e0c6a 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -82,10 +82,10 @@ namespace CNORXZ template constexpr decltype(auto) mkIFor(const Xpr& xpr, F&& f) const; + Sptr mRange; IndexPack mIPack; typedef RemoveRef{}))> BlockTuple; BlockTuple mBlockSizes; - Sptr mRange; }; // modified blockSizes; to be used for Slices; can be created from MIndices diff --git a/src/tests/range_unit_test.cc b/src/tests/range_unit_test.cc index 2fb7369..2cc9d9e 100644 --- a/src/tests/range_unit_test.cc +++ b/src/tests/range_unit_test.cc @@ -1,5 +1,4 @@ - #include #include @@ -114,7 +113,7 @@ namespace } SizeT cnt2 = 0; - for(auto x: *urx){ + for(const auto& x: *urx){ EXPECT_EQ(x, mMeta[cnt2++]); } } @@ -130,12 +129,53 @@ namespace EXPECT_EQ(mr->size(), mMeta.size()*mSize); EXPECT_EQ(mrx->size(), mMeta.size()*mSize); + EXPECT_EQ(mr->dim(), 2u); EXPECT_EQ(mrx->dim(), 2u); - // further tests!!! + EXPECT_TRUE(mrx->begin() != mrx->end()); + EXPECT_FALSE(mrx->begin() == mrx->end()); + EXPECT_EQ(mrx->begin().pos(), 0u); + EXPECT_EQ(mrx->end().pos(), mrx->size()); + + EXPECT_TRUE(mr->begin() != mr->end()); + EXPECT_FALSE(mr->begin() == mr->end()); + EXPECT_EQ(mr->begin().pos(), 0u); + EXPECT_EQ(mr->end().pos(), mr->size()); + + const SizeT mmsize = mMeta.size(); + auto mkm = [&](SizeT i) { return Tuple(i/mmsize,mMeta[i % mmsize]); }; + + SizeT cnt = 0; + auto endxi = mr->end(); + for(auto xi = mr->begin(); xi != endxi; ++xi){ + EXPECT_EQ(xi.pos(), cnt); + auto meta = mkm(cnt); + EXPECT_TRUE(*xi == DType(meta)); + EXPECT_EQ((*xi).str(), toString(meta)); + ++cnt; + } + + cnt = 0; + auto endxxi = mrx->end(); + for(auto xxi = mrx->begin(); xxi != endxxi; ++xxi){ + EXPECT_EQ(xxi.pos(), cnt); + auto ci = std::get<0>(xxi.pack()); + auto ui = std::get<1>(xxi.pack()); + Tuple meta(*(*ci),*(*ui)); + auto meta2 = mkm(cnt); + EXPECT_EQ(meta, meta2); + EXPECT_TRUE(*xxi == meta); + ++cnt; + } + + cnt = 0; + for(auto x: *mrx){ + auto meta = mkm(cnt); + EXPECT_EQ(x, meta); + ++cnt; + } } - // UR_Test // RCast_Test }