mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-10 19:36:56 +01:00
Some unary ops and coarse grid support
This commit is contained in:
@ -297,11 +297,13 @@ PARALLEL_FOR_LOOP
|
||||
#include <lattice/Lattice_reduction.h>
|
||||
#include <lattice/Lattice_peekpoke.h>
|
||||
#include <lattice/Lattice_reality.h>
|
||||
#include <lattice/Lattice_comparison_utils.h>
|
||||
#include <lattice/Lattice_comparison.h>
|
||||
#include <lattice/Lattice_coordinate.h>
|
||||
#include <lattice/Lattice_where.h>
|
||||
#include <lattice/Lattice_rng.h>
|
||||
#include <lattice/Lattice_unary.h>
|
||||
#include <lattice/Lattice_transfer.h>
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
145
lib/lattice/Lattice_comparison_utils.h
Normal file
145
lib/lattice/Lattice_comparison_utils.h
Normal file
@ -0,0 +1,145 @@
|
||||
#ifndef GRID_COMPARISON_H
|
||||
#define GRID_COMPARISON_H
|
||||
|
||||
namespace Grid {
|
||||
|
||||
/////////////////////////////////////////
|
||||
// This implementation is a bit poor.
|
||||
// Only support logical operations (== etc)
|
||||
// on scalar objects. Strip any tensor structures.
|
||||
// Should guard this with isGridTensor<> enable if?
|
||||
/////////////////////////////////////////
|
||||
// Generic list of functors
|
||||
template<class lobj,class robj> class veq {
|
||||
public:
|
||||
vInteger operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) == TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class vne {
|
||||
public:
|
||||
vInteger operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) != TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class vlt {
|
||||
public:
|
||||
vInteger operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) < TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class vle {
|
||||
public:
|
||||
vInteger operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) <= TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class vgt {
|
||||
public:
|
||||
vInteger operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) > TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class vge {
|
||||
public:
|
||||
vInteger operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) >= TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
// Generic list of functors
|
||||
template<class lobj,class robj> class seq {
|
||||
public:
|
||||
Integer operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) == TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class sne {
|
||||
public:
|
||||
Integer operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) != TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class slt {
|
||||
public:
|
||||
Integer operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) < TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class sle {
|
||||
public:
|
||||
Integer operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) <= TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class sgt {
|
||||
public:
|
||||
Integer operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) > TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
template<class lobj,class robj> class sge {
|
||||
public:
|
||||
Integer operator()(const lobj &lhs, const robj &rhs)
|
||||
{
|
||||
return TensorRemove(lhs) >= TensorRemove(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Integer gets extra relational functions. Could also implement these for RealF, RealD etc..
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<class sfunctor>
|
||||
inline vInteger Comparison(sfunctor sop,const vInteger & lhs, const vInteger & rhs)
|
||||
{
|
||||
std::vector<Integer> vlhs(vInteger::Nsimd()); // Use functors to reduce this to single implementation
|
||||
std::vector<Integer> vrhs(vInteger::Nsimd());
|
||||
vInteger ret;
|
||||
extract<vInteger,Integer>(lhs,vlhs);
|
||||
extract<vInteger,Integer>(rhs,vrhs);
|
||||
for(int s=0;s<vInteger::Nsimd();s++){
|
||||
vlhs[s] = sop(vlhs[s],vrhs[s]);
|
||||
}
|
||||
merge<vInteger,Integer>(ret,vlhs);
|
||||
return ret;
|
||||
}
|
||||
inline vInteger operator < (const vInteger & lhs, const vInteger & rhs)
|
||||
{
|
||||
return Comparison(slt<Integer,Integer>(),lhs,rhs);
|
||||
}
|
||||
inline vInteger operator <= (const vInteger & lhs, const vInteger & rhs)
|
||||
{
|
||||
return Comparison(sle<Integer,Integer>(),lhs,rhs);
|
||||
}
|
||||
inline vInteger operator > (const vInteger & lhs, const vInteger & rhs)
|
||||
{
|
||||
return Comparison(sgt<Integer,Integer>(),lhs,rhs);
|
||||
}
|
||||
inline vInteger operator >= (const vInteger & lhs, const vInteger & rhs)
|
||||
{
|
||||
return Comparison(sge<Integer,Integer>(),lhs,rhs);
|
||||
}
|
||||
inline vInteger operator == (const vInteger & lhs, const vInteger & rhs)
|
||||
{
|
||||
return Comparison(seq<Integer,Integer>(),lhs,rhs);
|
||||
}
|
||||
inline vInteger operator != (const vInteger & lhs, const vInteger & rhs)
|
||||
{
|
||||
return Comparison(sne<Integer,Integer>(),lhs,rhs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -3,20 +3,8 @@
|
||||
|
||||
namespace Grid {
|
||||
|
||||
/*
|
||||
depbase=`echo Grid_main.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
|
||||
icpc -DHAVE_CONFIG_H -I. -I../lib -I../lib -mmic -O3 -std=c++11 -fopenmp -MT Grid_main.o -MD -MP -MF $depbase.Tpo -c -o Grid_main.o Grid_main.cc &&\
|
||||
mv -f $depbase.Tpo $depbase.Po
|
||||
../lib/lattice/Grid_lattice_coordinate.h(25): error: no suitable user-defined conversion from "vector_type" to "const Grid::iScalar<Grid::iScalar<Grid::iScalar<Grid::vInteger>>>" exists
|
||||
l._odata[o]=vI;
|
||||
^
|
||||
detected during instantiation of "void Grid::LatticeCoordinate(Grid::Lattice<iobj> &, int) [with iobj=Grid::QCD::vTInteger]" at line 283 of "Grid_main.cc"
|
||||
|
||||
compilation aborted for Grid_main.cc (code 2)
|
||||
*/
|
||||
template<class iobj> inline void LatticeCoordinate(Lattice<iobj> &l,int mu)
|
||||
{
|
||||
typedef typename iobj::scalar_object scalar_object;
|
||||
typedef typename iobj::scalar_type scalar_type;
|
||||
typedef typename iobj::vector_type vector_type;
|
||||
|
||||
@ -33,7 +21,7 @@ namespace Grid {
|
||||
mergebuf[i]=(Integer)gcoor[mu];
|
||||
}
|
||||
merge<vector_type,scalar_type>(vI,mergebuf);
|
||||
l._odata[o]._internal._internal._internal=vI;
|
||||
l._odata[o]=vI;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -166,9 +166,10 @@ template<class vobj,class CComplex>
|
||||
inline void blockNormalise(Lattice<CComplex> &ip,Lattice<vobj> &fineX)
|
||||
{
|
||||
GridBase *coarse = ip._grid;
|
||||
Lattice<vobj> zz(fineX._grid); zz=zero;
|
||||
blockInnerProduct(ip,fineX,fineX);
|
||||
ip = rsqrt(ip);
|
||||
blockZAXPY(fineX,ip,fineX,fineX);
|
||||
blockZAXPY(fineX,ip,fineX,zz);
|
||||
}
|
||||
// useful in multigrid project;
|
||||
// Generic name : Coarsen?
|
||||
@ -205,6 +206,26 @@ inline void blockSum(Lattice<vobj> &coarseData,const Lattice<vobj> &fineData)
|
||||
return;
|
||||
}
|
||||
|
||||
template<class vobj>
|
||||
inline void blockPick(GridBase *coarse,const Lattice<vobj> &unpicked,Lattice<vobj> &picked,std::vector<int> coor)
|
||||
{
|
||||
GridBase * fine = unpicked._grid;
|
||||
|
||||
Lattice<vobj> zz(fine);
|
||||
Lattice<iScalar<vInteger> > fcoor(fine);
|
||||
|
||||
zz = zero;
|
||||
|
||||
picked = unpicked;
|
||||
for(int d=0;d<fine->_ndimension;d++){
|
||||
LatticeCoordinate(fcoor,d);
|
||||
int block= fine->_rdimensions[d] / coarse->_rdimensions[d];
|
||||
int lo = (coor[d])*block;
|
||||
int hi = (coor[d]+1)*block;
|
||||
picked = where( (fcoor<hi) , picked, zz);
|
||||
picked = where( (fcoor>=lo), picked, zz);
|
||||
}
|
||||
}
|
||||
|
||||
template<class vobj,class CComplex>
|
||||
inline void blockOrthogonalise(Lattice<CComplex> &ip,std::vector<Lattice<vobj> > &Basis)
|
||||
|
@ -26,7 +26,48 @@ PARALLEL_FOR_LOOP
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template<class obj> Lattice<obj> sin(const Lattice<obj> &rhs){
|
||||
Lattice<obj> ret(rhs._grid);
|
||||
ret.checkerboard = rhs.checkerboard;
|
||||
conformable(ret,rhs);
|
||||
PARALLEL_FOR_LOOP
|
||||
for(int ss=0;ss<rhs._grid->oSites();ss++){
|
||||
ret._odata[ss]=sin(rhs._odata[ss]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template<class obj> Lattice<obj> cos(const Lattice<obj> &rhs){
|
||||
Lattice<obj> ret(rhs._grid);
|
||||
ret.checkerboard = rhs.checkerboard;
|
||||
conformable(ret,rhs);
|
||||
PARALLEL_FOR_LOOP
|
||||
for(int ss=0;ss<rhs._grid->oSites();ss++){
|
||||
ret._odata[ss]=cos(rhs._odata[ss]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template<class obj> Lattice<obj> pow(const Lattice<obj> &rhs,RealD y){
|
||||
Lattice<obj> ret(rhs._grid);
|
||||
ret.checkerboard = rhs.checkerboard;
|
||||
conformable(ret,rhs);
|
||||
PARALLEL_FOR_LOOP
|
||||
for(int ss=0;ss<rhs._grid->oSites();ss++){
|
||||
ret._odata[ss]=pow(rhs._odata[ss],y);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
template<class obj> Lattice<obj> mod(const Lattice<obj> &rhs,Integer y){
|
||||
Lattice<obj> ret(rhs._grid);
|
||||
ret.checkerboard = rhs.checkerboard;
|
||||
conformable(ret,rhs);
|
||||
PARALLEL_FOR_LOOP
|
||||
for(int ss=0;ss<rhs._grid->oSites();ss++){
|
||||
ret._odata[ss]=mod(rhs._odata[ss],y);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user