From c72fbc329d9b1838aa3f20afee2b9516b72d5fdd Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 28 Dec 2023 00:25:44 +0100 Subject: [PATCH] WIP: index format test + fixes... --- src/include/ranges/dindex.cc.h | 7 ++++++ src/include/ranges/dindex.h | 5 +++- src/include/ranges/index_format.cc.h | 4 ++-- src/include/ranges/mrange.cc.h | 23 +++++++++++++++--- src/tests/index_format_test.cc | 35 ++++++++++++++++++++++++++-- 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/include/ranges/dindex.cc.h b/src/include/ranges/dindex.cc.h index 6a6d0a0..5d8451c 100644 --- a/src/include/ranges/dindex.cc.h +++ b/src/include/ranges/dindex.cc.h @@ -39,6 +39,13 @@ namespace CNORXZ return DXpr( bufxpr([&](auto x){ return mI->ifor( DXpr( assignxpr(x, xpr) ), NoF {} ); }) ); } } + + template + I indexAs(const DIndex& i) + { + static_assert(is_index::value, "expected index type"); + return std::dynamic_pointer_cast>( i.xptr() )->get(); + } } #endif diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index 5511625..7a87fe1 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -73,7 +73,7 @@ namespace CNORXZ decltype(auto) ifor(const Xpr& xpr, F&& f) const; const XIndexPtr& xptr() const; - + /** @copydoc IndexInterface::formatIsTrivial() */ bool formatIsTrivial() const; @@ -84,6 +84,9 @@ namespace CNORXZ template <> struct has_sub { static constexpr bool value = true; }; + + template + I indexAs(const DIndex& i); } #endif diff --git a/src/include/ranges/index_format.cc.h b/src/include/ranges/index_format.cc.h index 2d5b691..b5fa845 100644 --- a/src/include/ranges/index_format.cc.h +++ b/src/include/ranges/index_format.cc.h @@ -30,8 +30,8 @@ namespace CNORXZ template constexpr MFormat::MFormat(const FormatT& f) { - static_assert(f.size() == N, "try to assign format of wrong dimension"); - iter<0,N>( [&](auto i) { mB[i] = f[i]; }, NoF{} ); + CXZ_ASSERT(f.size() == N, "try to assign format of wrong dimension"); + iter<0,N>( [&](auto i) { mB[i] = f[i].val(); }, NoF{} ); } template diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 7fb78b7..198fbae 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -187,6 +187,9 @@ namespace CNORXZ mLMax(mkLMax(mIPack)), mPMax(mkPMax(mIPack,mFormat)) { + if constexpr(not std::is_same::value){ + mFormat = mLexFormat; + } mkPos(); } @@ -213,6 +216,9 @@ namespace CNORXZ mLMax(mkLMax(mIPack)), mPMax(mkPMax(mIPack,mFormat)) { + if constexpr(not std::is_same::value){ + mFormat = mLexFormat; + } mkPos(); } @@ -240,6 +246,9 @@ namespace CNORXZ mLMax(mkLMax(mIPack)), mPMax(mkPMax(mIPack,mFormat)) { + if constexpr(not std::is_same::value){ + mFormat = mLexFormat; + } *this = lexpos; } @@ -364,7 +373,7 @@ namespace CNORXZ template constexpr decltype(auto) GMIndex::lmax() const { - return mPMax; + return mLMax; } template @@ -554,7 +563,13 @@ namespace CNORXZ SizeT j = 0; SizeT j0 = 0; typename FormatT::InputType nformat; - auto npack = iter<0,NI>( [&](auto i) { + auto mkFv = [&]() { + Vector o(NI); + SizeT i = 0; + for(const auto& y:mFormat.all()) { o[i++] = y.val(); } + return o; + }; + iter<0,NI>( [&](auto i) { SizeT si = 1; if(mIPack[i]->lmax().val() != 1){ // CHECK!!! @@ -563,7 +578,9 @@ namespace CNORXZ CXZ_ASSERT(j < f.size(), "incompatible index formats"); } CXZ_ASSERT(si == mIPack[i]->lmax().val(), - "incompatible index formats: " << toString(s) << " vs " /*!!!*/); + "incompatible index formats: " << toString(f) << " vs " + << toString(mkFv()) << " ( " << si << " != " + << mIPack[i]->lmax().val() << " ) "); Vector nf(j-j0); Vector ns(j-j0); std::copy(f.begin()+j0,f.begin()+j,nf.begin()); diff --git a/src/tests/index_format_test.cc b/src/tests/index_format_test.cc index 9325108..cc2d245 100644 --- a/src/tests/index_format_test.cc +++ b/src/tests/index_format_test.cc @@ -28,19 +28,24 @@ namespace auto mr105 = mrange(ur3x,ur7x,cr5x); auto cr11 = CRangeFactory(11).create(); auto cr13 = CRangeFactory(13).create(); + auto cr17 = CRangeFactory(17).create(); mRange = yrange({cr11,mr105,cr13,sr2}); + mRange2 = yrange({cr11,mr105,cr13,cr17,sr2}); } Vector mMeta7; RangePtr mRange; + RangePtr mRange2; }; TEST_F(Format_Test, RangeCheck) { EXPECT_EQ(mRange->size(), 2*105*11*13); + EXPECT_EQ(mRange2->size(), 2*105*11*13*17); auto yi = mRange->begin(); EXPECT_EQ(yi.lmax().val(), mRange->size()); EXPECT_EQ(yi.pmax().val(), mRange->size()); + EXPECT_EQ(mRange->dim(), 4u); } TEST_F(Format_Test, CFormat) @@ -48,9 +53,35 @@ namespace CIndex ci(mRange); EXPECT_EQ(ci.lmax().val(), mRange->size()); auto yi = mRange->begin(); - auto rfi = ci.reformat( yi.deepFormat(), yi.deepMax() ); + auto yi2 = mRange2->begin(); + ci.reformat( yi.deepFormat(), yi.deepMax() ); VCHECK(toString(yi.deepFormat())); VCHECK(toString(yi.deepMax())); - EXPECT_EQ(rfi.lmax().val(), mRange->size()); + VCHECK(toString(yi2.deepFormat())); + VCHECK(toString(yi2.deepMax())); + EXPECT_EQ(ci.lmax().val(), mRange->size()); + } + + TEST_F(Format_Test, XFormat) + { + GMIndex,CIndex,CIndex,CIndex,CIndex> mi(mRange); + MIndex mi2(mRange2); + EXPECT_EQ(mi.lmax().val(), mRange->size()); + EXPECT_EQ(mi2.lmax().val(), mRange2->size()); + auto yi = indexAs( mRange->begin() ); + mi.reformat( yi.deepFormat(), yi.deepMax() ); + EXPECT_EQ(mi.lmax().val(), mRange->size()); + VCHECK(toString(mi.deepFormat())); + VCHECK(toString(mi.deepMax())); + VCHECK(toString(mi2.deepFormat())); + VCHECK(toString(mi2.deepMax())); + + + yi.setFormat( YFormat( Vector{ mi2.format()[CSizeT<0>{}].val(), mi2.format()[CSizeT<1>{}].val(), mi2.format()[CSizeT<2>{}].val(), mi2.format()[CSizeT<4>{}].val() } ) ); + VCHECK(toString(yi.deepFormat())); + + mi.reformat( yi.deepFormat(), yi.deepMax() ); + VCHECK(toString(mi.deepFormat())); + VCHECK(toString(mi.deepMax())); } }