WIP: reorder mpi code + map xpr + pos op

This commit is contained in:
Christian Zimmermann 2024-04-15 19:19:21 +02:00
parent 5ed0d6bbcb
commit adfb0fda67
14 changed files with 242 additions and 480 deletions

View file

@ -509,41 +509,35 @@ namespace CNORXZ
return i->xpr(i); return i->xpr(i);
} }
/*============+ /*==============+
| MapOp | | PosOp |
+============*/ +==============*/
template <class Index, class F> template <class Index>
constexpr MapOp<Index,F>::MapOp(const Sptr<Index>& i, F&& f) : constexpr PosOp<Index>::PosOp(const Sptr<Index>& i) :
mI(i), mI(i)
mF(std::forward<F>(f))
{} {}
template <class Index, class F> template <class Index>
template <class PosT> template <class PosT>
constexpr decltype(auto) MapOp<Index,F>::operator()(const PosT& pos) const constexpr decltype(auto) PosOp<Index>::operator()(const PosT& pos) const
{ {
return mF(pos.val()); return static_cast<SizeT>(pos);
}
template <class Index, class F>
constexpr decltype(auto) MapOp<Index,F>::operator()() const
{
return mF(SPos<0>());
} }
template <class Index, class F> template <class Index>
constexpr decltype(auto) PosOp<Index>::operator()() const
{
return static_cast<SizeT>(0);
}
template <class Index>
template <SizeT I> template <SizeT I>
constexpr decltype(auto) MapOp<Index,F>::rootSteps(const IndexId<I>& id) const constexpr decltype(auto) PosOp<Index>::rootSteps(const IndexId<I>& id) const
{ {
return mI->stepSize(id); return mI->stepSize(id);
} }
template <class Index, class F>
constexpr decltype(auto) mapop(const Sptr<Index>& i, F&& f)
{
return MapOp<Index,F>(i, std::forward<F>(f));
}
} }
#endif #endif

View file

@ -294,15 +294,14 @@ namespace CNORXZ
template <class IndexT> template <class IndexT>
constexpr decltype(auto) indexOp(const Sptr<IndexT>& i); constexpr decltype(auto) indexOp(const Sptr<IndexT>& i);
template <class Index, class F> template <class Index>
class MapOp : public OpInterface<MapOp<Index,F>> class PosOp : public COpInterface<PosOp<Index>>
{ {
public: public:
typedef OpInterface<MapOp<Index,F>> OI; typedef COpInterface<PosOp<Index>> OI;
constexpr MapOp() = default; constexpr PosOp() = default;
constexpr PosOp(const Sptr<Index>& i);
constexpr MapOp(const Sptr<Index>& i, F&& f);
template <class PosT> template <class PosT>
constexpr decltype(auto) operator()(const PosT& pos) const; constexpr decltype(auto) operator()(const PosT& pos) const;
@ -314,11 +313,14 @@ namespace CNORXZ
private: private:
Sptr<Index> mI; Sptr<Index> mI;
F mF;
}; };
template <class Index, class F> template <class Index>
constexpr decltype(auto) mapop(const Sptr<Index>& i, F&& f); constexpr decltype(auto) posop(const Sptr<Index>& i)
{
return PosOp<Index>(i);
}
} }
#endif #endif

View file

@ -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 <class TarIndex, class SrcIndex, class F>
static void setupMap(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const F& f, const Sptr<Vector<SizeT>>& 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 <class TarIndex, class SrcIndex, class F>
static Sptr<Vector<SizeT>> setupMap(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const F& f)
{
auto o = std::make_shared<Vector<SizeT>>(si->local()->lmax().val());
setupMap(ti,si,f,o);
return o;
}
template <class TarIndex, class SrcIndex, class Xpr>
template <class F>
MapXpr<TarIndex,SrcIndex,Xpr>::MapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const F& f, Xpr&& xpr) :
mTi(ti), mSi(si),
mMap(std::make_shared<Vector<SizeT>>(mSi->local()->lmax().val())),
mXpr(std::forward<Xpr>(xpr)),
mExt(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() ))
{
setupMap(ti,si,f,mMap);
}
template <class TarIndex, class SrcIndex, class Xpr>
MapXpr<TarIndex,SrcIndex,Xpr>::MapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const Sptr<Vector<SizeT>>& m, Xpr&& xpr) :
mTi(ti), mSi(si),
mMap(m), mXpr(std::forward<Xpr>(xpr)),
mExt(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() ))
{}
template <class TarIndex, class SrcIndex, class Xpr>
template <class PosT>
decltype(auto) MapXpr<TarIndex,SrcIndex,Xpr>::operator()(const PosT& last) const
{
return mXpr( last.next() + mExt( last ) );
}
template <class TarIndex, class SrcIndex, class Xpr>
decltype(auto) MapXpr<TarIndex,SrcIndex,Xpr>::operator()() const
{
return mXpr( mExt( UPos(0) ) );
}
template <class TarIndex, class SrcIndex, class Xpr>
template <SizeT I>
decltype(auto) MapXpr<TarIndex,SrcIndex,Xpr>::rootSteps(const IndexId<I>& id) const
{
return mSi->stepSize(id) << mXpr.rootSteps(id);
}
template <class TarIndex, class SrcIndex, class F, class Xpr>
decltype(auto) mapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si, const F& f, Xpr&& xpr)
{
return MapXpr<TarIndex,SrcIndex,Xpr>(ti,si,f,std::forward<Xpr>(xpr));
}
template <class TarIndex, class SrcIndex, class Xpr>
decltype(auto) mapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const Sptr<Vector<SizeT>>& m, Xpr&& xpr)
{
return MapXpr<TarIndex,SrcIndex,Xpr>(ti,si,m,std::forward<Xpr>(xpr));
}
}
#endif

69
src/include/xpr/map_xpr.h Normal file
View file

@ -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 <class TarIndex, class SrcIndex, class F>
static void setupMap(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const F& f, const Sptr<Vector<SizeT>>& m);
template <class TarIndex, class SrcIndex, class F>
static Sptr<Vector<SizeT>> setupMap(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const F& f);
template <class TarIndex, class SrcIndex, class Xpr>
class MapXpr : public XprInterface<MapXpr<TarIndex,SrcIndex,Xpr>>
{
private:
Sptr<TarIndex> mTi;
Sptr<SrcIndex> mSi;
Sptr<Vector<SizeT>> mMap;
Xpr mXpr;
typedef decltype(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() )) Ext;
Ext mExt;
public:
MapXpr() = default;
// src local
template <class F>
MapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si, const F& f, Xpr&& xpr);
MapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const Sptr<Vector<SizeT>>& m, Xpr&& xpr);
template <class PosT>
decltype(auto) operator()(const PosT& last) const;
decltype(auto) operator()() const;
template <SizeT I>
decltype(auto) rootSteps(const IndexId<I>& id) const;
};
template <class TarIndex, class SrcIndex, class F, class Xpr>
decltype(auto) mapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si, const F& f, Xpr&& xpr);
template <class TarIndex, class SrcIndex, class Xpr>
decltype(auto) mapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const Sptr<Vector<SizeT>>& m, Xpr&& xpr);
}
#endif

View file

@ -239,6 +239,31 @@ namespace CNORXZ
{ {
return mMax; return mMax;
} }
template <class PosT>
struct MkFPos
{
static constexpr decltype(auto) mk(const PosT& pos, const SizeT* map)
{
return FPos(pos.val(), map);
}
};
template <class BPosT, class NPosT>
struct MkFPos<MPos<BPosT,NPosT>>
{
static constexpr decltype(auto) mk(const MPos<BPosT,NPosT>& pos, const SizeT* map)
{
return mkMPos( MkFPos<BPosT>::mk( pos, map ), MkFPos<NPosT>::mk( pos.next(), map ) );
}
};
template <class PosT>
constexpr decltype(auto) mkFPos(const PosT& pos, const SizeT* map)
{
return MkFPos<PosT>::mk(pos, map);
}
/*===========+ /*===========+
| SFPos | | SFPos |
@ -423,6 +448,12 @@ namespace CNORXZ
return extend(a); return extend(a);
} }
template <class BPosT, class NPosT>
constexpr decltype(auto) mkMPos(const BPosT& bpos, const NPosT& npos)
{
return MPos<BPosT,NPosT>(bpos, npos);
}
/*==========+ /*==========+
| DPos | | DPos |
+==========*/ +==========*/

View file

@ -126,6 +126,9 @@ namespace CNORXZ
constexpr const SizeT* map() const { return mMap; } constexpr const SizeT* map() const { return mMap; }
}; };
template <class PosT>
constexpr decltype(auto) mkFPos(const PosT& pos, const SizeT* map);
template <SizeT N, SizeT... Ms> template <SizeT N, SizeT... Ms>
class SFPos class SFPos
{ {
@ -197,6 +200,9 @@ namespace CNORXZ
constexpr decltype(auto) operator<<(const PosT& a) const; constexpr decltype(auto) operator<<(const PosT& a) const;
}; };
template <class BPosT, class NPosT>
constexpr decltype(auto) mkMPos(const BPosT& bpos, const NPosT& npos);
// treat as scalar pos! // treat as scalar pos!
class DPos : public ObjHandle<VPosBase> class DPos : public ObjHandle<VPosBase>
{ {

View file

@ -15,3 +15,4 @@
#include "for.cc.h" #include "for.cc.h"
#include "index_id.cc.h" #include "index_id.cc.h"
#include "func.cc.h" #include "func.cc.h"
#include "map_xpr.cc.h"

View file

@ -15,5 +15,6 @@
#include "for.h" #include "for.h"
#include "index_id.h" #include "index_id.h"
#include "func.h" #include "func.h"
#include "map_xpr.h"
#include "xpr.cc.h" #include "xpr.cc.h"

View file

@ -223,9 +223,11 @@ namespace CNORXZ
template <typename T> template <typename T>
template <class Index1, class Index2> template <class Index1, class Index2>
void RCArray<T>::load(const Sptr<Index1>& lpi, const Sptr<Index2>& ai, void RCArray<T>::load(const Sptr<Index1>& lpi, const Sptr<Index2>& ai,
const Sptr<Vector<SizeT>>& imap) const; const Sptr<Vector<SizeT>>& imap) const
{ {
// TODO: blocks!!! // TODO: blocks!!!
const SizeT blocks = 0; assert(0); // TODO!!!
const SizeT myrank = getRankNumber(); const SizeT myrank = getRankNumber();
const SizeT Nranks = getNumRanks(); const SizeT Nranks = getNumRanks();
@ -233,7 +235,7 @@ namespace CNORXZ
mMap = Vector<const T*>(mapsize,nullptr); mMap = Vector<const T*>(mapsize,nullptr);
Vector<Vector<T>> sendbuf(Nranks); Vector<Vector<T>> sendbuf(Nranks);
for(auto& sb: sendbuf){ for(auto& sb: sendbuf){
sb.reserve(mData.size()); sb.reserve(mA->size());
} }
Vector<Vector<SizeT>> request(Nranks); Vector<Vector<SizeT>> request(Nranks);
const SizeT locsz = lpi->local()->lmax().val(); 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); sendpos.data(), sendsize, MPI_UNSIGNED_LONG, srcr, 0, MPI_COMM_WORLD, &stat);
sendbuf[srcr].resize(sendsize*blocks); sendbuf[srcr].resize(sendsize*blocks);
for(SizeT i = 0; i != sendsize; ++i){ 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; mMap[p] = mBuf.data() + off*blocks + cnt[r]*blocks;
++cnt[r]; ++cnt[r];
} }
mMap[q + myrank*locsz] = mData.data() + q*blocks; mMap[q + myrank*locsz] = mA->data() + q*blocks;
} , posop(ai), posop(lpi) ) ), NoF {} )(); } , posop(ai), posop(lpi) ) ), NoF {} )();
} }
@ -323,7 +325,7 @@ namespace CNORXZ
{ {
Sptr<Vector<SizeT>> imap = std::make_shared<Vector<SizeT>>(); Sptr<Vector<SizeT>> imap = std::make_shared<Vector<SizeT>>();
load(i, /**/, imap); //load(i, /**/, imap);
return imap; return imap;
} }

View file

@ -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 <cstdlib>
#include <iostream>
#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<SizeT,4> { 0,1,2,3 };
auto a3 = Arr<SizeT,3> { 0,1,2 };
mSpinR = std::dynamic_pointer_cast<SRange<SizeT,4>> ( SRangeFactory<SizeT,4>(a4).create() );
mColorR = std::dynamic_pointer_cast<SRange<SizeT,3>> ( SRangeFactory<SizeT,3>(a3).create() );
mSpatialR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(8).create() );
mTemporalR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(24).create() );
mLocSR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(4).create() );
mLocTR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(8).create() );
mRaSR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(2).create() );
mRaTR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(3).create() );
mData = MArray<Arr<Int,4>>(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<Arr<Int,4>>(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<SizeT,4>(mSpinR);
mColorI = SIndex<SizeT,3>(mColorR);
}
Sptr<SRange<SizeT,4>> mSpinR;
Sptr<SRange<SizeT,3>> mColorR;
Sptr<CRange> mSpatialR;
Sptr<CRange> mTemporalR;
Sptr<CRange> mLocSR;
Sptr<CRange> mLocTR;
Sptr<CRange> mRaSR;
Sptr<CRange> mRaTR;
MArray<Arr<Int,4>> mData;
Slice<Arr<Int,4>> mView;
YFormat mDataFormat;
YFormat mViewFormat;
CIndex mLocSI;
CIndex mLocTI;
CIndex mRaSI;
CIndex mRaTI;
SIndex<SizeT,4> mSpinI;
SIndex<SizeT,3> mColorI;
MIndex<CIndex,CIndex> mSpatialI;
MIndex<CIndex,CIndex> mTemporalI;
//GMIndex<Arr<SizeT,2>,CIndex,CIndex> mSpatialDI;
//GMIndex<Arr<SizeT,2>,CIndex,CIndex> mTemporalDI;
};
TEST_F(L_Test, Basic)
{
EXPECT_EQ(mData.size(), mView.size());
}
TEST_F(L_Test, Assign)
{
auto x0l = std::make_shared<CIndex>(mLocTI);
auto x0r = std::make_shared<CIndex>(mRaTI);
auto x0 = gmindexPtr(x0r*x0l);
auto x0a = gmindexPtr(x0r*x0l);
auto x1l = std::make_shared<CIndex>(mLocSI);
auto x1r = std::make_shared<CIndex>(mRaSI);
auto x1 = gmindexPtr(x1r*x1l);
auto x1a = gmindexPtr(x1r*x1l);
auto x2l = std::make_shared<CIndex>(mLocSI);
auto x2r = std::make_shared<CIndex>(mRaSI);
auto x2 = gmindexPtr(x2r*x2l);
auto x2a = gmindexPtr(x2r*x2l);
auto x3l = std::make_shared<CIndex>(mLocSI);
auto x3r = std::make_shared<CIndex>(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<SIndex<SizeT,4>>(mSpinI);
auto be = std::make_shared<SIndex<SizeT,4>>(mSpinI);
auto a = std::make_shared<SIndex<SizeT,3>>(mColorI);
auto b = std::make_shared<SIndex<SizeT,3>>(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<Int>(i - mSpatialR->size()) : static_cast<Int>(i); };
auto ft = [&](SizeT i) { return i >= mTemporalR->size()/2 ? static_cast<Int>(i - mTemporalR->size()) : static_cast<Int>(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<Int,4> 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<Int,4> m{ ft(x0->lex()), fs(x1->lex()), fs(x2->lex()), fs(x3->lex()) };
EXPECT_EQ( mView[x*al*a*be*b], m );
}
}
}

View file

@ -55,166 +55,6 @@ namespace
RangePtr mRRange; RangePtr mRRange;
}; };
template <class Index>
class PosOp : public COpInterface<PosOp<Index>>
{
public:
typedef COpInterface<PosOp<Index>> OI;
constexpr PosOp() = default;
constexpr PosOp(const Sptr<Index>& i) :
mMyrank(getRankNumber()), mI(i)
{}
template <class PosT>
constexpr decltype(auto) operator()(const PosT& pos) const
{
return static_cast<SizeT>(pos);
}
constexpr decltype(auto) operator()() const
{
return static_cast<SizeT>(0);
}
template <SizeT I>
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const
{
return mI->stepSize(id);
}
private:
SizeT mMyrank;
Sptr<Index> mI;
//SizeT mBlock;
};
template <class Index>
constexpr decltype(auto) posop(const Sptr<Index>& i)
{
return PosOp<Index>(i);
}
template <class PosT>
struct MkFPos
{
static constexpr decltype(auto) mk(const PosT& pos, const SizeT* map)
{
return FPos(pos.val(), map);
}
};
template <class BPosT, class NPosT>
constexpr decltype(auto) mkMPos(const BPosT& bpos, const NPosT& npos)
{
return MPos<BPosT,NPosT>(bpos, npos);
}
template <class BPosT, class NPosT>
struct MkFPos<MPos<BPosT,NPosT>>
{
static constexpr decltype(auto) mk(const MPos<BPosT,NPosT>& pos, const SizeT* map)
{
return mkMPos( MkFPos<BPosT>::mk( pos, map ), MkFPos<NPosT>::mk( pos.next(), map ) );
}
};
template <class PosT>
constexpr decltype(auto) mkFPos(const PosT& pos, const SizeT* map)
{
return MkFPos<PosT>::mk(pos, map);
}
template <class TarIndex, class SrcIndex, class F>
static void setupMap(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const F& f, const Sptr<Vector<SizeT>>& 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 <class TarIndex, class SrcIndex, class F>
static Sptr<Vector<SizeT>> setupMap(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const F& f)
{
auto o = std::make_shared<Vector<SizeT>>(si->local()->lmax().val());
setupMap(ti,si,f,o);
return o;
}
template <class TarIndex, class SrcIndex, class Xpr>
class MapXpr : public XprInterface<MapXpr<TarIndex,SrcIndex,Xpr>>
{
private:
Sptr<TarIndex> mTi;
Sptr<SrcIndex> mSi;
Sptr<Vector<SizeT>> mMap;
Xpr mXpr;
typedef decltype(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() )) Ext;
Ext mExt;
public:
MapXpr() = default;
// src local
template <class F>
MapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si, const F& f, Xpr&& xpr) :
mTi(ti), mSi(si),
mMap(std::make_shared<Vector<SizeT>>(mSi->local()->lmax().val())),
mXpr(std::forward<Xpr>(xpr)),
mExt(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() ))
{
setupMap(ti,si,f,mMap);
}
MapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const Sptr<Vector<SizeT>>& m, Xpr&& xpr) :
mTi(ti), mSi(si),
mMap(m), mXpr(std::forward<Xpr>(xpr)),
mExt(mkFPos( mXpr.rootSteps(mTi->id()), mMap->data() ))
{}
template <class PosT>
decltype(auto) operator()(const PosT& last) const
{
return mXpr( last.next() + mExt( last ) );
}
decltype(auto) operator()() const
{
return mXpr( mExt( UPos(0) ) );
}
template <SizeT I>
decltype(auto) rootSteps(const IndexId<I>& id) const
{
return mSi->stepSize(id) << mXpr.rootSteps(id);
}
};
template <class TarIndex, class SrcIndex, class F, class Xpr>
decltype(auto) mapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si, const F& f, Xpr&& xpr)
{
return MapXpr<TarIndex,SrcIndex,Xpr>(ti,si,f,std::forward<Xpr>(xpr));
}
template <class TarIndex, class SrcIndex, class Xpr>
decltype(auto) mapXpr(const Sptr<TarIndex>& ti, const Sptr<SrcIndex>& si,
const Sptr<Vector<SizeT>>& m, Xpr&& xpr)
{
return MapXpr<TarIndex,SrcIndex,Xpr>(ti,si,m,std::forward<Xpr>(xpr));
}
template <class TarIndex, class SrcIndex, typename T> template <class TarIndex, class SrcIndex, typename T>
void setupBuffer(const Sptr<TarIndex>& rgj, const Sptr<SrcIndex>& rgi, void setupBuffer(const Sptr<TarIndex>& rgj, const Sptr<SrcIndex>& rgi,

View file

@ -27,11 +27,6 @@ add_dependencies(mautest cnorxz)
target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)
add_test(NAME mautest COMMAND mautest) 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_executable(oputest operation_unit_test.cc)
add_dependencies(oputest cnorxz) add_dependencies(oputest cnorxz)
target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)

View file

@ -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 <cstdlib>
#include <iostream>
#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<SizeT,4> { 0,1,2,3 };
auto a3 = Arr<SizeT,3> { 0,1,2 };
mSpinR = std::dynamic_pointer_cast<SRange<SizeT,4>> ( SRangeFactory<SizeT,4>(a4).create() );
mColorR = std::dynamic_pointer_cast<SRange<SizeT,3>> ( SRangeFactory<SizeT,3>(a3).create() );
mSpatialR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(8).create() );
mTemporalR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(24).create() );
mLocSR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(4).create() );
mLocTR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(8).create() );
mRaSR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(2).create() );
mRaTR = std::dynamic_pointer_cast<CRange> ( CRangeFactory(3).create() );
mData = MArray<Arr<Int,4>>(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<Arr<Int,4>>(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<SizeT,4>(mSpinR);
mColorI = SIndex<SizeT,3>(mColorR);
}
Sptr<SRange<SizeT,4>> mSpinR;
Sptr<SRange<SizeT,3>> mColorR;
Sptr<CRange> mSpatialR;
Sptr<CRange> mTemporalR;
Sptr<CRange> mLocSR;
Sptr<CRange> mLocTR;
Sptr<CRange> mRaSR;
Sptr<CRange> mRaTR;
MArray<Arr<Int,4>> mData;
Slice<Arr<Int,4>> mView;
YFormat mDataFormat;
YFormat mViewFormat;
CIndex mLocSI;
CIndex mLocTI;
CIndex mRaSI;
CIndex mRaTI;
SIndex<SizeT,4> mSpinI;
SIndex<SizeT,3> mColorI;
MIndex<CIndex,CIndex> mSpatialI;
MIndex<CIndex,CIndex> mTemporalI;
//GMIndex<Arr<SizeT,2>,CIndex,CIndex> mSpatialDI;
//GMIndex<Arr<SizeT,2>,CIndex,CIndex> mTemporalDI;
};
TEST_F(L_Test, Basic)
{
EXPECT_EQ(mData.size(), mView.size());
}
TEST_F(L_Test, Assign)
{
auto x0l = std::make_shared<CIndex>(mLocTI);
auto x0r = std::make_shared<CIndex>(mRaTI);
auto x0 = gmindexPtr(x0r*x0l);
auto x0a = gmindexPtr(x0r*x0l);
auto x1l = std::make_shared<CIndex>(mLocSI);
auto x1r = std::make_shared<CIndex>(mRaSI);
auto x1 = gmindexPtr(x1r*x1l);
auto x1a = gmindexPtr(x1r*x1l);
auto x2l = std::make_shared<CIndex>(mLocSI);
auto x2r = std::make_shared<CIndex>(mRaSI);
auto x2 = gmindexPtr(x2r*x2l);
auto x2a = gmindexPtr(x2r*x2l);
auto x3l = std::make_shared<CIndex>(mLocSI);
auto x3r = std::make_shared<CIndex>(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<SIndex<SizeT,4>>(mSpinI);
auto be = std::make_shared<SIndex<SizeT,4>>(mSpinI);
auto a = std::make_shared<SIndex<SizeT,3>>(mColorI);
auto b = std::make_shared<SIndex<SizeT,3>>(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<Int>(i - mSpatialR->size()) : static_cast<Int>(i); };
auto ft = [&](SizeT i) { return i >= mTemporalR->size()/2 ? static_cast<Int>(i - mTemporalR->size()) : static_cast<Int>(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<Int,4> 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<Int,4> m{ ft(x0->lex()), fs(x1->lex()), fs(x2->lex()), fs(x3->lex()) };
EXPECT_EQ( mView[x*al*a*be*b], m );
}
}
}

View file

@ -17,12 +17,6 @@ namespace
{ {
using namespace CNORXZ; using namespace CNORXZ;
template <class PosT1, class PosT2>
constexpr auto mkMPos(const PosT1& a, const PosT2& b)
{
return MPos<PosT1,PosT2>(a,b);
}
class Pos_Test : public ::testing::Test class Pos_Test : public ::testing::Test
{ {
protected: protected: