From 8513b6dcd30f04792f73ebe42bd1014292e36bfd Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sun, 27 Nov 2022 04:28:46 +0100 Subject: [PATCH] 2d opcont test --- src/include/ranges/index_base.cc.h | 6 ++++ src/include/ranges/index_base.h | 3 ++ src/include/xpr/for.cc.h | 4 +-- src/tests/operation_unit_test.cc | 45 ++++++++++++++++++++++++++---- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/include/ranges/index_base.cc.h b/src/include/ranges/index_base.cc.h index 91cd6de..dcd616c 100644 --- a/src/include/ranges/index_base.cc.h +++ b/src/include/ranges/index_base.cc.h @@ -137,6 +137,12 @@ namespace CNORXZ { return MIndex(a.THIS(),b.THIS()); } + + template + decltype(auto) operator*(const IndexPtr& a, const IndexPtr& b) + { + return std::make_shared>(a->THIS(), b->THIS()); + } } #endif diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index a8e02c4..5589ae8 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -98,6 +98,9 @@ namespace CNORXZ template decltype(auto) operator*(const IndexInterface& a, const IndexInterface& b); + + template + decltype(auto) operator*(const IndexPtr& a, const IndexPtr& b); } #endif diff --git a/src/include/xpr/for.cc.h b/src/include/xpr/for.cc.h index 1d2edf8..cec435b 100644 --- a/src/include/xpr/for.cc.h +++ b/src/include/xpr/for.cc.h @@ -26,7 +26,7 @@ namespace CNORXZ template inline decltype(auto) For::operator()(const PosT& last) const { - if constexpr(std::is_same::value){ + if constexpr(std::is_same::type,NoF>::value){ for(SizeT i = 0; i != mSize; ++i){ const auto pos = last + mExt * UPos(i); mXpr(pos); @@ -47,7 +47,7 @@ namespace CNORXZ template inline decltype(auto) For::operator()() const { - if constexpr(std::is_same::value){ + if constexpr(std::is_same::type,NoF>::value){ for(SizeT i = 0; i != mSize; ++i){ const auto pos = mExt * UPos(i); mXpr(pos); diff --git a/src/tests/operation_unit_test.cc b/src/tests/operation_unit_test.cc index 39d3396..b37b93d 100644 --- a/src/tests/operation_unit_test.cc +++ b/src/tests/operation_unit_test.cc @@ -47,6 +47,8 @@ namespace { protected: + typedef MIndex MCCI; + OpCont_CR_CR_Test() { mSize1 = 7; @@ -57,6 +59,16 @@ namespace mData12 = Numbers::get(off+mSize1+mSize2, mSize1*mSize2); auto cra = CRangeFactory(mSize1).create(); auto crb = CRangeFactory(mSize2).create(); + mCIa1 = std::make_shared(cra); + mCIa2 = std::make_shared(cra); + mCIb1 = std::make_shared(crb); + mCIb2 = std::make_shared(crb); + mCCa1a2 = std::make_shared(mCIa1,mCIa2); + mCCa2a1 = std::make_shared(mCIa2,mCIa1); + //mCCa1a2 = mCIa1*mCIa2; + //mCCa2a1 = mCIa2*mCIa1; + mOCa1a2.init(mCCa1a2); + mORa2a1.init(mData12.data(), mCCa2a1); } SizeT mSize1; @@ -64,12 +76,14 @@ namespace Vector mData1; Vector mData2; Vector mData12; - Sptr mCI1; - Sptr mCI2; - OpCont mOp1; - COpRoot mOp2; - OpCont mOp3; - COpRoot mOp4; + Sptr mCIa1; + Sptr mCIa2; + Sptr mCIb1; + Sptr mCIb2; + Sptr mCCa1a2; + Sptr mCCa2a1; + OpCont mOCa1a2; + COpRoot mORa2a1; }; TEST_F(OpCont_CR_Test, Basics) @@ -131,4 +145,23 @@ namespace } } + TEST_F(OpCont_CR_CR_Test, Basics) + { + EXPECT_EQ(mOCa1a2.rootSteps(mCIa1->id()).val(), mCIa2->pmax().val()); + EXPECT_EQ(mOCa1a2.rootSteps(mCIa2->id()).val(), 1u); + EXPECT_EQ(mORa2a1.rootSteps(mCIa1->id()).val(), 1u); + EXPECT_EQ(mORa2a1.rootSteps(mCIa2->id()).val(), mCIa1->pmax().val()); + } + + TEST_F(OpCont_CR_CR_Test, Assignment) + { + mOCa1a2 = mORa2a1; + for(SizeT i = 0; i != mCIa1->pmax().val(); ++i){ + for(SizeT j = 0; j != mCIa2->pmax().val(); ++j){ + const SizeT jS = mCIa2->pmax().val(); + const SizeT iS = mCIa1->pmax().val(); + EXPECT_EQ(mOCa1a2.data()[i*jS+j], mORa2a1.data()[j*iS+i]); + } + } + } }