From adfb0fda677702c54dba09ac9c265c82d195705b Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 15 Apr 2024 19:19:21 +0200 Subject: [PATCH] WIP: reorder mpi code + map xpr + pos op --- src/include/operation/op_types.cc.h | 40 +++---- src/include/operation/op_types.h | 20 ++-- src/include/xpr/map_xpr.cc.h | 99 +++++++++++++++++ src/include/xpr/map_xpr.h | 69 ++++++++++++ src/include/xpr/pos_type.cc.h | 31 ++++++ src/include/xpr/pos_type.h | 6 ++ src/include/xpr/xpr.cc.h | 1 + src/include/xpr/xpr.h | 1 + src/opt/mpi/include/rarray.cc.h | 12 ++- src/opt/mpi/tests/l_unit_test.cc | 136 ----------------------- src/opt/mpi/tests/rindex_exp.cc | 160 ---------------------------- src/tests/CMakeLists.txt | 5 - src/tests/l_unit_test.cc | 136 ----------------------- src/tests/xpr_unit_test.cc | 6 -- 14 files changed, 242 insertions(+), 480 deletions(-) create mode 100644 src/include/xpr/map_xpr.cc.h create mode 100644 src/include/xpr/map_xpr.h delete mode 100644 src/opt/mpi/tests/l_unit_test.cc delete mode 100644 src/tests/l_unit_test.cc diff --git a/src/include/operation/op_types.cc.h b/src/include/operation/op_types.cc.h index 6bd647f..9df3034 100644 --- a/src/include/operation/op_types.cc.h +++ b/src/include/operation/op_types.cc.h @@ -509,41 +509,35 @@ namespace CNORXZ return i->xpr(i); } - /*============+ - | MapOp | - +============*/ + /*==============+ + | PosOp | + +==============*/ - template - constexpr MapOp::MapOp(const Sptr& i, F&& f) : - mI(i), - mF(std::forward(f)) + template + constexpr PosOp::PosOp(const Sptr& i) : + mI(i) {} - template + template template - constexpr decltype(auto) MapOp::operator()(const PosT& pos) const + constexpr decltype(auto) PosOp::operator()(const PosT& pos) const { - return mF(pos.val()); - } - - template - constexpr decltype(auto) MapOp::operator()() const - { - return mF(SPos<0>()); + return static_cast(pos); } - template + template + constexpr decltype(auto) PosOp::operator()() const + { + return static_cast(0); + } + + template template - constexpr decltype(auto) MapOp::rootSteps(const IndexId& id) const + constexpr decltype(auto) PosOp::rootSteps(const IndexId& id) const { return mI->stepSize(id); } - template - constexpr decltype(auto) mapop(const Sptr& i, F&& f) - { - return MapOp(i, std::forward(f)); - } } #endif diff --git a/src/include/operation/op_types.h b/src/include/operation/op_types.h index 8404070..8d8293e 100644 --- a/src/include/operation/op_types.h +++ b/src/include/operation/op_types.h @@ -294,15 +294,14 @@ namespace CNORXZ template constexpr decltype(auto) indexOp(const Sptr& i); - template - class MapOp : public OpInterface> + template + class PosOp : public COpInterface> { public: - typedef OpInterface> OI; + typedef COpInterface> OI; - constexpr MapOp() = default; - - constexpr MapOp(const Sptr& i, F&& f); + constexpr PosOp() = default; + constexpr PosOp(const Sptr& i); template constexpr decltype(auto) operator()(const PosT& pos) const; @@ -314,11 +313,14 @@ namespace CNORXZ private: Sptr mI; - F mF; }; - template - constexpr decltype(auto) mapop(const Sptr& i, F&& f); + template + constexpr decltype(auto) posop(const Sptr& i) + { + return PosOp(i); + } + } #endif diff --git a/src/include/xpr/map_xpr.cc.h b/src/include/xpr/map_xpr.cc.h new file mode 100644 index 0000000..211484e --- /dev/null +++ b/src/include/xpr/map_xpr.cc.h @@ -0,0 +1,99 @@ +// -*- C++ -*- +/** + + @file include/xpr/map_xpr.cc.h + @brief Map xpression template implementations. + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + +**/ + +#ifndef __cxz_map_xpr_cc_h__ +#define __cxz_map_xpr_cc_h__ + +#include "map_xpr.h" + +namespace CNORXZ +{ + template + static void setupMap(const Sptr& ti, const Sptr& si, + const F& f, const Sptr>& m) + { + auto six = *si; + auto sie = si->range()->end(); + auto tix = *ti; + for(six = 0; six != sie; ++six){ + tix.at( f(*six) ); + if(six.rank() == getRankNumber()){ + (*m)[six.local()->lex()] = tix.pos(); + } + } + } + + template + static Sptr> setupMap(const Sptr& ti, const Sptr& si, + const F& f) + { + auto o = std::make_shared>(si->local()->lmax().val()); + setupMap(ti,si,f,o); + return o; + } + + template + template + MapXpr::MapXpr(const Sptr& ti, const Sptr& si, + const F& f, Xpr&& xpr) : + mTi(ti), mSi(si), + mMap(std::make_shared>(mSi->local()->lmax().val())), + mXpr(std::forward(xpr)), + mExt(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() )) + { + setupMap(ti,si,f,mMap); + } + + template + MapXpr::MapXpr(const Sptr& ti, const Sptr& si, + const Sptr>& m, Xpr&& xpr) : + mTi(ti), mSi(si), + mMap(m), mXpr(std::forward(xpr)), + mExt(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() )) + {} + + + template + template + decltype(auto) MapXpr::operator()(const PosT& last) const + { + return mXpr( last.next() + mExt( last ) ); + } + + template + decltype(auto) MapXpr::operator()() const + { + return mXpr( mExt( UPos(0) ) ); + } + + template + template + decltype(auto) MapXpr::rootSteps(const IndexId& id) const + { + return mSi->stepSize(id) << mXpr.rootSteps(id); + } + + template + decltype(auto) mapXpr(const Sptr& ti, const Sptr& si, const F& f, Xpr&& xpr) + { + return MapXpr(ti,si,f,std::forward(xpr)); + } + + template + decltype(auto) mapXpr(const Sptr& ti, const Sptr& si, + const Sptr>& m, Xpr&& xpr) + { + return MapXpr(ti,si,m,std::forward(xpr)); + } + +} + +#endif diff --git a/src/include/xpr/map_xpr.h b/src/include/xpr/map_xpr.h new file mode 100644 index 0000000..cbd8282 --- /dev/null +++ b/src/include/xpr/map_xpr.h @@ -0,0 +1,69 @@ +// -*- C++ -*- +/** + + @file include/xpr/map_xpr.h + @brief Map expression declarations. + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + + **/ + +#ifndef __cxz_map_xpr_h__ +#define __cxz_map_xpr_h__ + +#include "xpr_base.h" + +namespace CNORXZ +{ + template + static void setupMap(const Sptr& ti, const Sptr& si, + const F& f, const Sptr>& m); + + template + static Sptr> setupMap(const Sptr& ti, const Sptr& si, + const F& f); + + template + class MapXpr : public XprInterface> + { + private: + Sptr mTi; + Sptr mSi; + Sptr> mMap; + Xpr mXpr; + typedef decltype(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() )) Ext; + Ext mExt; + + public: + + MapXpr() = default; + + // src local + template + MapXpr(const Sptr& ti, const Sptr& si, const F& f, Xpr&& xpr); + + MapXpr(const Sptr& ti, const Sptr& si, + const Sptr>& m, Xpr&& xpr); + + + template + decltype(auto) operator()(const PosT& last) const; + + decltype(auto) operator()() const; + + template + decltype(auto) rootSteps(const IndexId& id) const; + }; + + template + decltype(auto) mapXpr(const Sptr& ti, const Sptr& si, const F& f, Xpr&& xpr); + + template + decltype(auto) mapXpr(const Sptr& ti, const Sptr& si, + const Sptr>& m, Xpr&& xpr); + + +} + +#endif diff --git a/src/include/xpr/pos_type.cc.h b/src/include/xpr/pos_type.cc.h index b201807..bd5ec9c 100644 --- a/src/include/xpr/pos_type.cc.h +++ b/src/include/xpr/pos_type.cc.h @@ -239,6 +239,31 @@ namespace CNORXZ { return mMax; } + + template + struct MkFPos + { + static constexpr decltype(auto) mk(const PosT& pos, const SizeT* map) + { + return FPos(pos.val(), map); + } + }; + + template + struct MkFPos> + { + static constexpr decltype(auto) mk(const MPos& pos, const SizeT* map) + { + return mkMPos( MkFPos::mk( pos, map ), MkFPos::mk( pos.next(), map ) ); + } + }; + + template + constexpr decltype(auto) mkFPos(const PosT& pos, const SizeT* map) + { + return MkFPos::mk(pos, map); + } + /*===========+ | SFPos | @@ -423,6 +448,12 @@ namespace CNORXZ return extend(a); } + template + constexpr decltype(auto) mkMPos(const BPosT& bpos, const NPosT& npos) + { + return MPos(bpos, npos); + } + /*==========+ | DPos | +==========*/ diff --git a/src/include/xpr/pos_type.h b/src/include/xpr/pos_type.h index 6d524d9..bf73c06 100644 --- a/src/include/xpr/pos_type.h +++ b/src/include/xpr/pos_type.h @@ -126,6 +126,9 @@ namespace CNORXZ constexpr const SizeT* map() const { return mMap; } }; + template + constexpr decltype(auto) mkFPos(const PosT& pos, const SizeT* map); + template class SFPos { @@ -197,6 +200,9 @@ namespace CNORXZ constexpr decltype(auto) operator<<(const PosT& a) const; }; + template + constexpr decltype(auto) mkMPos(const BPosT& bpos, const NPosT& npos); + // treat as scalar pos! class DPos : public ObjHandle { diff --git a/src/include/xpr/xpr.cc.h b/src/include/xpr/xpr.cc.h index 87f3dc4..dab4606 100644 --- a/src/include/xpr/xpr.cc.h +++ b/src/include/xpr/xpr.cc.h @@ -15,3 +15,4 @@ #include "for.cc.h" #include "index_id.cc.h" #include "func.cc.h" +#include "map_xpr.cc.h" diff --git a/src/include/xpr/xpr.h b/src/include/xpr/xpr.h index c98a825..e6fe804 100644 --- a/src/include/xpr/xpr.h +++ b/src/include/xpr/xpr.h @@ -15,5 +15,6 @@ #include "for.h" #include "index_id.h" #include "func.h" +#include "map_xpr.h" #include "xpr.cc.h" diff --git a/src/opt/mpi/include/rarray.cc.h b/src/opt/mpi/include/rarray.cc.h index 6585eb9..803e0a1 100644 --- a/src/opt/mpi/include/rarray.cc.h +++ b/src/opt/mpi/include/rarray.cc.h @@ -223,9 +223,11 @@ namespace CNORXZ template template void RCArray::load(const Sptr& lpi, const Sptr& ai, - const Sptr>& imap) const; + const Sptr>& imap) const { // TODO: blocks!!! + const SizeT blocks = 0; assert(0); // TODO!!! + const SizeT myrank = getRankNumber(); const SizeT Nranks = getNumRanks(); @@ -233,7 +235,7 @@ namespace CNORXZ mMap = Vector(mapsize,nullptr); Vector> sendbuf(Nranks); for(auto& sb: sendbuf){ - sb.reserve(mData.size()); + sb.reserve(mA->size()); } Vector> request(Nranks); const SizeT locsz = lpi->local()->lmax().val(); @@ -277,7 +279,7 @@ namespace CNORXZ sendpos.data(), sendsize, MPI_UNSIGNED_LONG, srcr, 0, MPI_COMM_WORLD, &stat); sendbuf[srcr].resize(sendsize*blocks); for(SizeT i = 0; i != sendsize; ++i){ - std::memcpy( sendbuf[srcr].data()+i*blocks, mData.data()+sendpos[i]*blocks, blocks*sizeof(T) ); + std::memcpy( sendbuf[srcr].data()+i*blocks, mA->data()+sendpos[i]*blocks, blocks*sizeof(T) ); } } @@ -312,7 +314,7 @@ namespace CNORXZ mMap[p] = mBuf.data() + off*blocks + cnt[r]*blocks; ++cnt[r]; } - mMap[q + myrank*locsz] = mData.data() + q*blocks; + mMap[q + myrank*locsz] = mA->data() + q*blocks; } , posop(ai), posop(lpi) ) ), NoF {} )(); } @@ -323,7 +325,7 @@ namespace CNORXZ { Sptr> imap = std::make_shared>(); - load(i, /**/, imap); + //load(i, /**/, imap); return imap; } diff --git a/src/opt/mpi/tests/l_unit_test.cc b/src/opt/mpi/tests/l_unit_test.cc deleted file mode 100644 index cb03af3..0000000 --- a/src/opt/mpi/tests/l_unit_test.cc +++ /dev/null @@ -1,136 +0,0 @@ -// -*- C++ -*- -/** - - @file opt/mpi/tests/l_unit_test.cc - @brief L unit tests. - - Copyright (c) 2024 Christian Zimmermann. All rights reserved. - Mail: chizeta@f3l.de - -**/ - -#include -#include - -#include "gtest/gtest.h" - -#include "cnorxz.h" -#include "test_numbers.h" - -namespace -{ - using namespace CNORXZ; - using Test::Numbers; - - class L_Test : public ::testing::Test - { - protected: - - L_Test() - { - auto a4 = Arr { 0,1,2,3 }; - auto a3 = Arr { 0,1,2 }; - mSpinR = std::dynamic_pointer_cast> ( SRangeFactory(a4).create() ); - mColorR = std::dynamic_pointer_cast> ( SRangeFactory(a3).create() ); - mSpatialR = std::dynamic_pointer_cast ( CRangeFactory(8).create() ); - mTemporalR = std::dynamic_pointer_cast ( CRangeFactory(24).create() ); - mLocSR = std::dynamic_pointer_cast ( CRangeFactory(4).create() ); - mLocTR = std::dynamic_pointer_cast ( CRangeFactory(8).create() ); - mRaSR = std::dynamic_pointer_cast ( CRangeFactory(2).create() ); - mRaTR = std::dynamic_pointer_cast ( CRangeFactory(3).create() ); - mData = MArray>(yrange({mRaTR,mRaSR,mRaSR,mRaSR,mLocTR,mLocSR,mLocSR,mLocSR,mSpinR,mColorR,mSpinR,mColorR})); - mDataFormat = mData.begin().format(); - auto vf = mDataFormat.all(); - vf[0] = mDataFormat[0]; - vf[1] = mDataFormat[4]; - vf[2] = mDataFormat[1]; - vf[3] = mDataFormat[5]; - vf[4] = mDataFormat[2]; - vf[5] = mDataFormat[6]; - vf[6] = mDataFormat[3]; - vf[7] = mDataFormat[7]; - mViewFormat = YFormat(vf); - mView = Slice>(yrange({mRaTR,mLocTR,mRaSR,mLocSR,mRaSR,mLocSR,mRaSR,mLocSR,mSpinR,mColorR,mSpinR,mColorR}), &mData, mViewFormat, 0); - mLocSI = CIndex(mLocSR); - mLocTI = CIndex(mLocTR); - mRaSI = CIndex(mRaSR); - mRaTI = CIndex(mRaTR); - mSpinI = SIndex(mSpinR); - mColorI = SIndex(mColorR); - } - - Sptr> mSpinR; - Sptr> mColorR; - Sptr mSpatialR; - Sptr mTemporalR; - Sptr mLocSR; - Sptr mLocTR; - Sptr mRaSR; - Sptr mRaTR; - - MArray> mData; - Slice> mView; - YFormat mDataFormat; - YFormat mViewFormat; - - CIndex mLocSI; - CIndex mLocTI; - CIndex mRaSI; - CIndex mRaTI; - SIndex mSpinI; - SIndex mColorI; - MIndex mSpatialI; - MIndex mTemporalI; - //GMIndex,CIndex,CIndex> mSpatialDI; - //GMIndex,CIndex,CIndex> mTemporalDI; - }; - - TEST_F(L_Test, Basic) - { - EXPECT_EQ(mData.size(), mView.size()); - } - - TEST_F(L_Test, Assign) - { - auto x0l = std::make_shared(mLocTI); - auto x0r = std::make_shared(mRaTI); - auto x0 = gmindexPtr(x0r*x0l); - auto x0a = gmindexPtr(x0r*x0l); - auto x1l = std::make_shared(mLocSI); - auto x1r = std::make_shared(mRaSI); - auto x1 = gmindexPtr(x1r*x1l); - auto x1a = gmindexPtr(x1r*x1l); - auto x2l = std::make_shared(mLocSI); - auto x2r = std::make_shared(mRaSI); - auto x2 = gmindexPtr(x2r*x2l); - auto x2a = gmindexPtr(x2r*x2l); - auto x3l = std::make_shared(mLocSI); - auto x3r = std::make_shared(mRaSI); - auto x3 = gmindexPtr(x3r*x3l); - auto x3a = gmindexPtr(x3r*x3l); - auto x = gmindexPtr(x0*x1*x2*x3); - auto xx = gmindexPtr(x0a*x1a*x2a*x3a); - auto al = std::make_shared>(mSpinI); - auto be = std::make_shared>(mSpinI); - auto a = std::make_shared>(mColorI); - auto b = std::make_shared>(mColorI); - - EXPECT_TRUE(x0->formatIsTrivial()); - EXPECT_TRUE(x1->formatIsTrivial()); - EXPECT_TRUE(x2->formatIsTrivial()); - EXPECT_TRUE(x3->formatIsTrivial()); - EXPECT_TRUE(x->formatIsTrivial()); - - auto fs = [&](SizeT i) { return i >= mSpatialR->size()/2 ? static_cast(i - mSpatialR->size()) : static_cast(i); }; - auto ft = [&](SizeT i) { return i >= mTemporalR->size()/2 ? static_cast(i - mTemporalR->size()) : static_cast(i); }; - EXPECT_TRUE(mindexPtr(xx*al*a*be*b)->formatIsTrivial()); - - mView(gmindexPtr(xx*al*a*be*b)) = operation( [](Int a0, Int a1, Int a2, Int a3) { Arr x{a0,a1,a2,a3}; return x; }, - mapop(x0, ft), mapop(x1, fs), mapop(x2, fs), mapop(x3, fs) ); - EXPECT_FALSE(xx->formatIsTrivial()); - for(*x = 0; x->lex() != x->lmax().val(); ++(*x)){ - Arr m{ ft(x0->lex()), fs(x1->lex()), fs(x2->lex()), fs(x3->lex()) }; - EXPECT_EQ( mView[x*al*a*be*b], m ); - } - } -} diff --git a/src/opt/mpi/tests/rindex_exp.cc b/src/opt/mpi/tests/rindex_exp.cc index 4bd9a88..216a16f 100644 --- a/src/opt/mpi/tests/rindex_exp.cc +++ b/src/opt/mpi/tests/rindex_exp.cc @@ -55,166 +55,6 @@ namespace RangePtr mRRange; }; - - template - class PosOp : public COpInterface> - { - public: - typedef COpInterface> OI; - - constexpr PosOp() = default; - - constexpr PosOp(const Sptr& i) : - mMyrank(getRankNumber()), mI(i) - {} - - template - constexpr decltype(auto) operator()(const PosT& pos) const - { - return static_cast(pos); - } - - constexpr decltype(auto) operator()() const - { - return static_cast(0); - } - - template - constexpr decltype(auto) rootSteps(const IndexId& id) const - { - return mI->stepSize(id); - } - - private: - SizeT mMyrank; - Sptr mI; - //SizeT mBlock; - }; - - template - constexpr decltype(auto) posop(const Sptr& i) - { - return PosOp(i); - } - - template - struct MkFPos - { - static constexpr decltype(auto) mk(const PosT& pos, const SizeT* map) - { - return FPos(pos.val(), map); - } - }; - - template - constexpr decltype(auto) mkMPos(const BPosT& bpos, const NPosT& npos) - { - return MPos(bpos, npos); - } - - template - struct MkFPos> - { - static constexpr decltype(auto) mk(const MPos& pos, const SizeT* map) - { - return mkMPos( MkFPos::mk( pos, map ), MkFPos::mk( pos.next(), map ) ); - } - }; - - template - constexpr decltype(auto) mkFPos(const PosT& pos, const SizeT* map) - { - return MkFPos::mk(pos, map); - } - - template - static void setupMap(const Sptr& ti, const Sptr& si, - const F& f, const Sptr>& m) - { - auto six = *si; - auto sie = si->range()->end(); - auto tix = *ti; - for(six = 0; six != sie; ++six){ - tix.at( f(*six) ); - if(six.rank() == getRankNumber()){ - (*m)[six.local()->lex()] = tix.pos(); - } - } - } - - template - static Sptr> setupMap(const Sptr& ti, const Sptr& si, - const F& f) - { - auto o = std::make_shared>(si->local()->lmax().val()); - setupMap(ti,si,f,o); - return o; - } - - template - class MapXpr : public XprInterface> - { - private: - Sptr mTi; - Sptr mSi; - Sptr> mMap; - Xpr mXpr; - typedef decltype(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() )) Ext; - Ext mExt; - - public: - - MapXpr() = default; - - // src local - template - MapXpr(const Sptr& ti, const Sptr& si, const F& f, Xpr&& xpr) : - mTi(ti), mSi(si), - mMap(std::make_shared>(mSi->local()->lmax().val())), - mXpr(std::forward(xpr)), - mExt(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() )) - { - setupMap(ti,si,f,mMap); - } - - MapXpr(const Sptr& ti, const Sptr& si, - const Sptr>& m, Xpr&& xpr) : - mTi(ti), mSi(si), - mMap(m), mXpr(std::forward(xpr)), - mExt(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() )) - {} - - - template - decltype(auto) operator()(const PosT& last) const - { - return mXpr( last.next() + mExt( last ) ); - } - - decltype(auto) operator()() const - { - return mXpr( mExt( UPos(0) ) ); - } - - template - decltype(auto) rootSteps(const IndexId& id) const - { - return mSi->stepSize(id) << mXpr.rootSteps(id); - } - }; - - template - decltype(auto) mapXpr(const Sptr& ti, const Sptr& si, const F& f, Xpr&& xpr) - { - return MapXpr(ti,si,f,std::forward(xpr)); - } - - template - decltype(auto) mapXpr(const Sptr& ti, const Sptr& si, - const Sptr>& m, Xpr&& xpr) - { - return MapXpr(ti,si,m,std::forward(xpr)); - } template void setupBuffer(const Sptr& rgj, const Sptr& rgi, diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 5a5f8d5..773b306 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -27,11 +27,6 @@ add_dependencies(mautest cnorxz) target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) add_test(NAME mautest COMMAND mautest) -add_executable(lutest l_unit_test.cc) -add_dependencies(lutest cnorxz) -target_link_libraries(lutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) -add_test(NAME lutest COMMAND lutest) - add_executable(oputest operation_unit_test.cc) add_dependencies(oputest cnorxz) target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) diff --git a/src/tests/l_unit_test.cc b/src/tests/l_unit_test.cc deleted file mode 100644 index d4576bb..0000000 --- a/src/tests/l_unit_test.cc +++ /dev/null @@ -1,136 +0,0 @@ -// -*- C++ -*- -/** - - @file tests/l_unit_test.cc - @brief MArray unit tests. - - Copyright (c) 2024 Christian Zimmermann. All rights reserved. - Mail: chizeta@f3l.de - -**/ - -#include -#include - -#include "gtest/gtest.h" - -#include "cnorxz.h" -#include "test_numbers.h" - -namespace -{ - using namespace CNORXZ; - using Test::Numbers; - - class L_Test : public ::testing::Test - { - protected: - - L_Test() - { - auto a4 = Arr { 0,1,2,3 }; - auto a3 = Arr { 0,1,2 }; - mSpinR = std::dynamic_pointer_cast> ( SRangeFactory(a4).create() ); - mColorR = std::dynamic_pointer_cast> ( SRangeFactory(a3).create() ); - mSpatialR = std::dynamic_pointer_cast ( CRangeFactory(8).create() ); - mTemporalR = std::dynamic_pointer_cast ( CRangeFactory(24).create() ); - mLocSR = std::dynamic_pointer_cast ( CRangeFactory(4).create() ); - mLocTR = std::dynamic_pointer_cast ( CRangeFactory(8).create() ); - mRaSR = std::dynamic_pointer_cast ( CRangeFactory(2).create() ); - mRaTR = std::dynamic_pointer_cast ( CRangeFactory(3).create() ); - mData = MArray>(yrange({mRaTR,mRaSR,mRaSR,mRaSR,mLocTR,mLocSR,mLocSR,mLocSR,mSpinR,mColorR,mSpinR,mColorR})); - mDataFormat = mData.begin().format(); - auto vf = mDataFormat.all(); - vf[0] = mDataFormat[0]; - vf[1] = mDataFormat[4]; - vf[2] = mDataFormat[1]; - vf[3] = mDataFormat[5]; - vf[4] = mDataFormat[2]; - vf[5] = mDataFormat[6]; - vf[6] = mDataFormat[3]; - vf[7] = mDataFormat[7]; - mViewFormat = YFormat(vf); - mView = Slice>(yrange({mRaTR,mLocTR,mRaSR,mLocSR,mRaSR,mLocSR,mRaSR,mLocSR,mSpinR,mColorR,mSpinR,mColorR}), &mData, mViewFormat, 0); - mLocSI = CIndex(mLocSR); - mLocTI = CIndex(mLocTR); - mRaSI = CIndex(mRaSR); - mRaTI = CIndex(mRaTR); - mSpinI = SIndex(mSpinR); - mColorI = SIndex(mColorR); - } - - Sptr> mSpinR; - Sptr> mColorR; - Sptr mSpatialR; - Sptr mTemporalR; - Sptr mLocSR; - Sptr mLocTR; - Sptr mRaSR; - Sptr mRaTR; - - MArray> mData; - Slice> mView; - YFormat mDataFormat; - YFormat mViewFormat; - - CIndex mLocSI; - CIndex mLocTI; - CIndex mRaSI; - CIndex mRaTI; - SIndex mSpinI; - SIndex mColorI; - MIndex mSpatialI; - MIndex mTemporalI; - //GMIndex,CIndex,CIndex> mSpatialDI; - //GMIndex,CIndex,CIndex> mTemporalDI; - }; - - TEST_F(L_Test, Basic) - { - EXPECT_EQ(mData.size(), mView.size()); - } - - TEST_F(L_Test, Assign) - { - auto x0l = std::make_shared(mLocTI); - auto x0r = std::make_shared(mRaTI); - auto x0 = gmindexPtr(x0r*x0l); - auto x0a = gmindexPtr(x0r*x0l); - auto x1l = std::make_shared(mLocSI); - auto x1r = std::make_shared(mRaSI); - auto x1 = gmindexPtr(x1r*x1l); - auto x1a = gmindexPtr(x1r*x1l); - auto x2l = std::make_shared(mLocSI); - auto x2r = std::make_shared(mRaSI); - auto x2 = gmindexPtr(x2r*x2l); - auto x2a = gmindexPtr(x2r*x2l); - auto x3l = std::make_shared(mLocSI); - auto x3r = std::make_shared(mRaSI); - auto x3 = gmindexPtr(x3r*x3l); - auto x3a = gmindexPtr(x3r*x3l); - auto x = gmindexPtr(x0*x1*x2*x3); - auto xx = gmindexPtr(x0a*x1a*x2a*x3a); - auto al = std::make_shared>(mSpinI); - auto be = std::make_shared>(mSpinI); - auto a = std::make_shared>(mColorI); - auto b = std::make_shared>(mColorI); - - EXPECT_TRUE(x0->formatIsTrivial()); - EXPECT_TRUE(x1->formatIsTrivial()); - EXPECT_TRUE(x2->formatIsTrivial()); - EXPECT_TRUE(x3->formatIsTrivial()); - EXPECT_TRUE(x->formatIsTrivial()); - - auto fs = [&](SizeT i) { return i >= mSpatialR->size()/2 ? static_cast(i - mSpatialR->size()) : static_cast(i); }; - auto ft = [&](SizeT i) { return i >= mTemporalR->size()/2 ? static_cast(i - mTemporalR->size()) : static_cast(i); }; - EXPECT_TRUE(mindexPtr(xx*al*a*be*b)->formatIsTrivial()); - - mView(gmindexPtr(xx*al*a*be*b)) = operation( [](Int a0, Int a1, Int a2, Int a3) { Arr x{a0,a1,a2,a3}; return x; }, - mapop(x0, ft), mapop(x1, fs), mapop(x2, fs), mapop(x3, fs) ); - EXPECT_FALSE(xx->formatIsTrivial()); - for(*x = 0; x->lex() != x->lmax().val(); ++(*x)){ - Arr m{ ft(x0->lex()), fs(x1->lex()), fs(x2->lex()), fs(x3->lex()) }; - EXPECT_EQ( mView[x*al*a*be*b], m ); - } - } -} diff --git a/src/tests/xpr_unit_test.cc b/src/tests/xpr_unit_test.cc index 567ff8d..db4984d 100644 --- a/src/tests/xpr_unit_test.cc +++ b/src/tests/xpr_unit_test.cc @@ -17,12 +17,6 @@ namespace { using namespace CNORXZ; - template - constexpr auto mkMPos(const PosT1& a, const PosT2& b) - { - return MPos(a,b); - } - class Pos_Test : public ::testing::Test { protected: