mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Debugged the real() and imag() functions and added tests to Test_Simd
This commit is contained in:
parent
3e3b367aa9
commit
e3d5319470
45
lib/Simd.h
45
lib/Simd.h
@ -1,32 +1,33 @@
|
||||
/*************************************************************************************
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/Simd.h
|
||||
Source file: ./lib/Simd.h
|
||||
|
||||
Copyright (C) 2015
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: neo <cossu@post.kek.jp>
|
||||
Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
See the full license in the file "LICENSE" in the top level distribution
|
||||
directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef GRID_SIMD_H
|
||||
#define GRID_SIMD_H
|
||||
|
||||
@ -118,6 +119,14 @@ namespace Grid {
|
||||
inline ComplexD timesI(const ComplexD &r) { return(r*ComplexD(0.0,1.0));}
|
||||
inline ComplexF timesMinusI(const ComplexF &r){ return(r*ComplexF(0.0,-1.0));}
|
||||
inline ComplexD timesMinusI(const ComplexD &r){ return(r*ComplexD(0.0,-1.0));}
|
||||
|
||||
// define projections to real and imaginay parts
|
||||
inline ComplexF projReal(const ComplexF &r){return( ComplexF(std::real(r), 0.0));}
|
||||
inline ComplexD projReal(const ComplexD &r){return( ComplexD(std::real(r), 0.0));}
|
||||
inline ComplexF projImag(const ComplexF &r){return (ComplexF(std::imag(r), 0.0 ));}
|
||||
inline ComplexD projImag(const ComplexD &r){return (ComplexD(std::imag(r), 0.0));}
|
||||
|
||||
// define auxiliary functions for complex computations
|
||||
inline void timesI(ComplexF &ret,const ComplexF &r) { ret = timesI(r);}
|
||||
inline void timesI(ComplexD &ret,const ComplexD &r) { ret = timesI(r);}
|
||||
inline void timesMinusI(ComplexF &ret,const ComplexF &r){ ret = timesMinusI(r);}
|
||||
|
@ -40,7 +40,7 @@ namespace Grid {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<class vobj> inline RealD norm2(const Lattice<vobj> &arg){
|
||||
ComplexD nrm = innerProduct(arg,arg);
|
||||
return real(nrm);
|
||||
return std::real(nrm);
|
||||
}
|
||||
|
||||
template<class vobj>
|
||||
|
@ -5,163 +5,156 @@
|
||||
#ifndef STOUT_SMEAR_
|
||||
#define STOUT_SMEAR_
|
||||
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
|
||||
/*! @brief Stout smearing of link variable. */
|
||||
template <class Gimpl>
|
||||
class Smear_Stout: public Smear<Gimpl> {
|
||||
private:
|
||||
const Smear < Gimpl > * SmearBase;
|
||||
/*! @brief Stout smearing of link variable. */
|
||||
template <class Gimpl>
|
||||
class Smear_Stout : public Smear<Gimpl> {
|
||||
private:
|
||||
const Smear<Gimpl>* SmearBase;
|
||||
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Gimpl)
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Gimpl)
|
||||
|
||||
Smear_Stout(Smear < Gimpl >* base):SmearBase(base){
|
||||
static_assert(Nc==3, "Stout smearing currently implemented only for Nc==3");
|
||||
}
|
||||
Smear_Stout(Smear<Gimpl>* base) : SmearBase(base) {
|
||||
static_assert(Nc == 3,
|
||||
"Stout smearing currently implemented only for Nc==3");
|
||||
}
|
||||
|
||||
/*! Default constructor */
|
||||
Smear_Stout(double rho = 1.0):SmearBase(new Smear_APE < Gimpl > (rho)){
|
||||
static_assert(Nc==3, "Stout smearing currently implemented only for Nc==3");
|
||||
}
|
||||
/*! Default constructor */
|
||||
Smear_Stout(double rho = 1.0) : SmearBase(new Smear_APE<Gimpl>(rho)) {
|
||||
static_assert(Nc == 3,
|
||||
"Stout smearing currently implemented only for Nc==3");
|
||||
}
|
||||
|
||||
~Smear_Stout(){} //delete SmearBase...
|
||||
~Smear_Stout() {} // delete SmearBase...
|
||||
|
||||
void smear(GaugeField& u_smr,const GaugeField& U) const{
|
||||
GaugeField C(U._grid);
|
||||
GaugeLinkField tmp(U._grid), iq_mu(U._grid), Umu(U._grid);
|
||||
void smear(GaugeField& u_smr, const GaugeField& U) const {
|
||||
GaugeField C(U._grid);
|
||||
GaugeLinkField tmp(U._grid), iq_mu(U._grid), Umu(U._grid);
|
||||
|
||||
std::cout<< GridLogDebug << "Stout smearing started\n";
|
||||
std::cout << GridLogDebug << "Stout smearing started\n";
|
||||
|
||||
//Smear the configurations
|
||||
SmearBase->smear(C, U);
|
||||
// Smear the configurations
|
||||
SmearBase->smear(C, U);
|
||||
|
||||
for (int mu = 0; mu<Nd; mu++)
|
||||
{
|
||||
tmp = peekLorentz(C,mu);
|
||||
Umu = peekLorentz(U,mu);
|
||||
iq_mu = Ta(tmp * adj(Umu)); // iq_mu = Ta(Omega_mu) to match the signs with the paper
|
||||
exponentiate_iQ(tmp, iq_mu);
|
||||
pokeLorentz(u_smr, tmp*Umu, mu);// u_smr = exp(iQ_mu)*U_mu
|
||||
}
|
||||
std::cout<< GridLogDebug << "Stout smearing completed\n";
|
||||
};
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
tmp = peekLorentz(C, mu);
|
||||
Umu = peekLorentz(U, mu);
|
||||
iq_mu = Ta(
|
||||
tmp *
|
||||
adj(Umu)); // iq_mu = Ta(Omega_mu) to match the signs with the paper
|
||||
exponentiate_iQ(tmp, iq_mu);
|
||||
pokeLorentz(u_smr, tmp * Umu, mu); // u_smr = exp(iQ_mu)*U_mu
|
||||
}
|
||||
std::cout << GridLogDebug << "Stout smearing completed\n";
|
||||
};
|
||||
|
||||
void derivative(GaugeField& SigmaTerm, const GaugeField& iLambda,
|
||||
const GaugeField& Gauge) const {
|
||||
SmearBase->derivative(SigmaTerm, iLambda, Gauge);
|
||||
};
|
||||
|
||||
void derivative(GaugeField& SigmaTerm,
|
||||
const GaugeField& iLambda,
|
||||
const GaugeField& Gauge) const{
|
||||
SmearBase->derivative(SigmaTerm, iLambda, Gauge);
|
||||
};
|
||||
void BaseSmear(GaugeField& C, const GaugeField& U) const {
|
||||
SmearBase->smear(C, U);
|
||||
};
|
||||
|
||||
void exponentiate_iQ(GaugeLinkField& e_iQ, const GaugeLinkField& iQ) const {
|
||||
// Put this outside
|
||||
// only valid for SU(3) matrices
|
||||
|
||||
void BaseSmear(GaugeField& C,
|
||||
const GaugeField& U) const{
|
||||
SmearBase->smear(C, U);
|
||||
};
|
||||
// only one Lorentz direction at a time
|
||||
|
||||
void exponentiate_iQ(GaugeLinkField& e_iQ,
|
||||
const GaugeLinkField& iQ) const{
|
||||
// Put this outside
|
||||
// only valid for SU(3) matrices
|
||||
// notice that it actually computes
|
||||
// exp ( input matrix )
|
||||
// the i sign is coming from outside
|
||||
// input matrix is anti-hermitian NOT hermitian
|
||||
|
||||
// only one Lorentz direction at a time
|
||||
GridBase* grid = iQ._grid;
|
||||
GaugeLinkField unity(grid);
|
||||
unity = 1.0;
|
||||
|
||||
// notice that it actually computes
|
||||
// exp ( input matrix )
|
||||
// the i sign is coming from outside
|
||||
// input matrix is anti-hermitian NOT hermitian
|
||||
GaugeLinkField iQ2(grid), iQ3(grid);
|
||||
LatticeComplex u(grid), w(grid);
|
||||
LatticeComplex f0(grid), f1(grid), f2(grid);
|
||||
|
||||
GridBase *grid = iQ._grid;
|
||||
GaugeLinkField unity(grid);
|
||||
unity=1.0;
|
||||
iQ2 = iQ * iQ;
|
||||
iQ3 = iQ * iQ2;
|
||||
|
||||
GaugeLinkField iQ2(grid), iQ3(grid);
|
||||
LatticeComplex u(grid), w(grid);
|
||||
LatticeComplex f0(grid), f1(grid), f2(grid);
|
||||
set_uw(u, w, iQ2, iQ3);
|
||||
set_fj(f0, f1, f2, u, w);
|
||||
|
||||
iQ2 = iQ * iQ;
|
||||
iQ3 = iQ * iQ2;
|
||||
e_iQ = f0 * unity + timesMinusI(f1) * iQ - f2 * iQ2;
|
||||
};
|
||||
|
||||
set_uw(u, w, iQ2, iQ3);
|
||||
set_fj(f0, f1, f2, u, w);
|
||||
void set_uw(LatticeComplex& u, LatticeComplex& w, GaugeLinkField& iQ2,
|
||||
GaugeLinkField& iQ3) const {
|
||||
Complex one_over_three = 1.0 / 3.0;
|
||||
Complex one_over_two = 1.0 / 2.0;
|
||||
|
||||
e_iQ = f0*unity + timesMinusI(f1) * iQ - f2 * iQ2;
|
||||
GridBase* grid = u._grid;
|
||||
LatticeComplex c0(grid), c1(grid), tmp(grid), c0max(grid), theta(grid);
|
||||
|
||||
// sign in c0 from the conventions on the Ta
|
||||
c0 = -imag(trace(iQ3)) * one_over_three;
|
||||
c1 = -real(trace(iQ2)) * one_over_two;
|
||||
|
||||
};
|
||||
// Cayley Hamilton checks to machine precision, tested
|
||||
tmp = c1 * one_over_three;
|
||||
c0max = 2.0 * pow(tmp, 1.5);
|
||||
|
||||
theta = acos(c0 / c0max) *
|
||||
one_over_three; // divide by three here, now leave as it is
|
||||
u = sqrt(tmp) * cos(theta);
|
||||
w = sqrt(c1) * sin(theta);
|
||||
}
|
||||
|
||||
void set_uw(LatticeComplex& u, LatticeComplex& w,
|
||||
GaugeLinkField& iQ2, GaugeLinkField& iQ3) const{
|
||||
Complex one_over_three = 1.0/3.0;
|
||||
Complex one_over_two = 1.0/2.0;
|
||||
void set_fj(LatticeComplex& f0, LatticeComplex& f1, LatticeComplex& f2,
|
||||
const LatticeComplex& u, const LatticeComplex& w) const {
|
||||
GridBase* grid = u._grid;
|
||||
LatticeComplex xi0(grid), u2(grid), w2(grid), cosw(grid);
|
||||
LatticeComplex fden(grid);
|
||||
LatticeComplex h0(grid), h1(grid), h2(grid);
|
||||
LatticeComplex e2iu(grid), emiu(grid), ixi0(grid), qt(grid);
|
||||
LatticeComplex unity(grid);
|
||||
unity = 1.0;
|
||||
|
||||
GridBase *grid = u._grid;
|
||||
LatticeComplex c0(grid), c1(grid), tmp(grid), c0max(grid), theta(grid);
|
||||
xi0 = func_xi0(w);
|
||||
u2 = u * u;
|
||||
w2 = w * w;
|
||||
cosw = cos(w);
|
||||
|
||||
// sign in c0 from the conventions on the Ta
|
||||
c0 = - real(timesMinusI(trace(iQ3))) * one_over_three; //temporary hack
|
||||
c1 = - real(trace(iQ2)) * one_over_two;
|
||||
ixi0 = timesI(xi0);
|
||||
emiu = cos(u) - timesI(sin(u));
|
||||
e2iu = cos(2.0 * u) + timesI(sin(2.0 * u));
|
||||
|
||||
//Cayley Hamilton checks to machine precision, tested
|
||||
tmp = c1 * one_over_three;
|
||||
c0max = 2.0 * pow(tmp, 1.5);
|
||||
h0 = e2iu * (u2 - w2) +
|
||||
emiu * ((8.0 * u2 * cosw) + (2.0 * u * (3.0 * u2 + w2) * ixi0));
|
||||
h1 = e2iu * (2.0 * u) - emiu * ((2.0 * u * cosw) - (3.0 * u2 - w2) * ixi0);
|
||||
h2 = e2iu - emiu * (cosw + (3.0 * u) * ixi0);
|
||||
|
||||
theta = acos(c0/c0max)*one_over_three; // divide by three here, now leave as it is
|
||||
u = sqrt(tmp) * cos( theta );
|
||||
w = sqrt(c1) * sin( theta );
|
||||
}
|
||||
fden = unity / (9.0 * u2 - w2); // reals
|
||||
f0 = h0 * fden;
|
||||
f1 = h1 * fden;
|
||||
f2 = h2 * fden;
|
||||
}
|
||||
|
||||
void set_fj(LatticeComplex& f0, LatticeComplex& f1, LatticeComplex& f2,
|
||||
const LatticeComplex& u, const LatticeComplex& w) const{
|
||||
LatticeComplex func_xi0(const LatticeComplex& w) const {
|
||||
// Define a function to do the check
|
||||
// if( w < 1e-4 ) std::cout << GridLogWarning<< "[Smear_stout] w too small:
|
||||
// "<< w <<"\n";
|
||||
return sin(w) / w;
|
||||
}
|
||||
|
||||
GridBase *grid = u._grid;
|
||||
LatticeComplex xi0(grid), u2(grid), w2(grid), cosw(grid);
|
||||
LatticeComplex fden(grid);
|
||||
LatticeComplex h0(grid), h1(grid), h2(grid);
|
||||
LatticeComplex e2iu(grid), emiu(grid), ixi0(grid), qt(grid);
|
||||
LatticeComplex unity(grid);
|
||||
unity = 1.0;
|
||||
|
||||
xi0 = func_xi0(w);
|
||||
u2 = u * u;
|
||||
w2 = w * w;
|
||||
cosw = cos(w);
|
||||
|
||||
ixi0 = timesI(xi0);
|
||||
emiu = cos(u) - timesI(sin(u));
|
||||
e2iu = cos(2.0*u) + timesI(sin(2.0*u));
|
||||
|
||||
h0 = e2iu * (u2 - w2) + emiu * ( (8.0*u2*cosw) + (2.0*u*(3.0*u2 + w2)*ixi0));
|
||||
h1 = e2iu * (2.0 * u) - emiu * ( (2.0*u*cosw) - (3.0*u2-w2)*ixi0);
|
||||
h2 = e2iu - emiu * ( cosw + (3.0*u)*ixi0);
|
||||
|
||||
fden = unity/(9.0*u2 - w2);// reals
|
||||
f0 = h0 * fden;
|
||||
f1 = h1 * fden;
|
||||
f2 = h2 * fden;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
LatticeComplex func_xi0(const LatticeComplex& w) const{
|
||||
// Define a function to do the check
|
||||
//if( w < 1e-4 ) std::cout << GridLogWarning<< "[Smear_stout] w too small: "<< w <<"\n";
|
||||
return sin(w)/w;
|
||||
}
|
||||
|
||||
LatticeComplex func_xi1(const LatticeComplex& w) const{
|
||||
// Define a function to do the check
|
||||
//if( w < 1e-4 ) std::cout << GridLogWarning << "[Smear_stout] w too small: "<< w <<"\n";
|
||||
return cos(w)/(w*w) - sin(w)/(w*w*w);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
LatticeComplex func_xi1(const LatticeComplex& w) const {
|
||||
// Define a function to do the check
|
||||
// if( w < 1e-4 ) std::cout << GridLogWarning << "[Smear_stout] w too small:
|
||||
// "<< w <<"\n";
|
||||
return cos(w) / (w * w) - sin(w) / (w * w * w);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,247 +1,234 @@
|
||||
/*************************************************************************************
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/simd/Grid_vector_unops.h
|
||||
Source file: ./lib/simd/Grid_vector_unops.h
|
||||
|
||||
Copyright (C) 2015
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: neo <cossu@post.kek.jp>
|
||||
Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
See the full license in the file "LICENSE" in the top level distribution
|
||||
directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef GRID_VECTOR_UNOPS
|
||||
#define GRID_VECTOR_UNOPS
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace Grid {
|
||||
namespace Grid {
|
||||
|
||||
template<class scalar> struct SqrtRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return sqrt(real(a));
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct SqrtRealFunctor {
|
||||
scalar operator()(const scalar &a) const { return sqrt(real(a)); }
|
||||
};
|
||||
|
||||
template<class scalar> struct RSqrtRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return scalar(1.0/sqrt(real(a)));
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct RSqrtRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return scalar(1.0 / sqrt(real(a)));
|
||||
}
|
||||
};
|
||||
|
||||
template<class scalar> struct CosRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return cos(real(a));
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct CosRealFunctor {
|
||||
scalar operator()(const scalar &a) const { return cos(real(a)); }
|
||||
};
|
||||
|
||||
template<class scalar> struct SinRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return sin(real(a));
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct SinRealFunctor {
|
||||
scalar operator()(const scalar &a) const { return sin(real(a)); }
|
||||
};
|
||||
|
||||
template<class scalar> struct AcosRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return acos(real(a));
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct AcosRealFunctor {
|
||||
scalar operator()(const scalar &a) const { return acos(real(a)); }
|
||||
};
|
||||
|
||||
template<class scalar> struct AsinRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return asin(real(a));
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct AsinRealFunctor {
|
||||
scalar operator()(const scalar &a) const { return asin(real(a)); }
|
||||
};
|
||||
|
||||
template<class scalar> struct LogRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return log(real(a));
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct LogRealFunctor {
|
||||
scalar operator()(const scalar &a) const { return log(real(a)); }
|
||||
};
|
||||
|
||||
template<class scalar> struct ExpRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return exp(real(a));
|
||||
}
|
||||
};
|
||||
template<class scalar> struct NotFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return (!a);
|
||||
}
|
||||
};
|
||||
template<class scalar> struct AbsRealFunctor {
|
||||
scalar operator()(const scalar &a) const {
|
||||
return std::abs(real(a));
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct ExpRealFunctor {
|
||||
scalar operator()(const scalar &a) const { return exp(real(a)); }
|
||||
};
|
||||
template <class scalar>
|
||||
struct NotFunctor {
|
||||
scalar operator()(const scalar &a) const { return (!a); }
|
||||
};
|
||||
template <class scalar>
|
||||
struct AbsRealFunctor {
|
||||
scalar operator()(const scalar &a) const { return std::abs(real(a)); }
|
||||
};
|
||||
|
||||
template<class scalar> struct PowRealFunctor {
|
||||
double y;
|
||||
PowRealFunctor(double _y) : y(_y) {};
|
||||
scalar operator()(const scalar &a) const {
|
||||
return pow(real(a),y);
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct PowRealFunctor {
|
||||
double y;
|
||||
PowRealFunctor(double _y) : y(_y){};
|
||||
scalar operator()(const scalar &a) const { return pow(real(a), y); }
|
||||
};
|
||||
|
||||
template<class scalar> struct ModIntFunctor {
|
||||
Integer y;
|
||||
ModIntFunctor(Integer _y) : y(_y) {};
|
||||
scalar operator()(const scalar &a) const {
|
||||
return Integer(a)%y;
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct ModIntFunctor {
|
||||
Integer y;
|
||||
ModIntFunctor(Integer _y) : y(_y){};
|
||||
scalar operator()(const scalar &a) const { return Integer(a) % y; }
|
||||
};
|
||||
|
||||
template<class scalar> struct DivIntFunctor {
|
||||
Integer y;
|
||||
DivIntFunctor(Integer _y) : y(_y) {};
|
||||
scalar operator()(const scalar &a) const {
|
||||
return Integer(a)/y;
|
||||
}
|
||||
};
|
||||
template <class scalar>
|
||||
struct DivIntFunctor {
|
||||
Integer y;
|
||||
DivIntFunctor(Integer _y) : y(_y){};
|
||||
scalar operator()(const scalar &a) const { return Integer(a) / y; }
|
||||
};
|
||||
|
||||
template<class scalar> struct RealFunctor {
|
||||
scalar operator()(const std::complex<scalar> &a) const {
|
||||
return real(a);
|
||||
}
|
||||
};
|
||||
template<class scalar> struct ImagFunctor {
|
||||
scalar operator()(const std::complex<scalar> &a) const {
|
||||
return imag(a);
|
||||
}
|
||||
};
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> real(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(RealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> imag(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(ImagFunctor<S>(),r);
|
||||
}
|
||||
template <class scalar>
|
||||
struct RealFunctor {
|
||||
scalar operator()(const scalar &a) const { return std::real(a); }
|
||||
};
|
||||
template <class scalar>
|
||||
struct ImagFunctor {
|
||||
scalar operator()(const scalar &a) const { return std::imag(a); }
|
||||
};
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> real(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(RealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> imag(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(ImagFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> sqrt(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(SqrtRealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> rsqrt(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(RSqrtRealFunctor<S>(), r);
|
||||
}
|
||||
template <class Scalar>
|
||||
inline Scalar rsqrt(const Scalar &r) {
|
||||
return (RSqrtRealFunctor<Scalar>(), r);
|
||||
}
|
||||
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> sqrt(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(SqrtRealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> rsqrt(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(RSqrtRealFunctor<S>(),r);
|
||||
}
|
||||
template < class Scalar >
|
||||
inline Scalar rsqrt(const Scalar &r) {
|
||||
return (RSqrtRealFunctor<Scalar>(),r);
|
||||
}
|
||||
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> cos(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(CosRealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> sin(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(SinRealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> acos(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(AcosRealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> asin(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(AsinRealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> log(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(LogRealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> abs(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(AbsRealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> exp(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(ExpRealFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> Not(const Grid_simd<S,V> &r) {
|
||||
return SimdApply(NotFunctor<S>(),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> pow(const Grid_simd<S,V> &r,double y) {
|
||||
return SimdApply(PowRealFunctor<S>(y),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> mod(const Grid_simd<S,V> &r,Integer y) {
|
||||
return SimdApply(ModIntFunctor<S>(y),r);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> div(const Grid_simd<S,V> &r,Integer y) {
|
||||
return SimdApply(DivIntFunctor<S>(y),r);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Allows us to assign into **conformable** real vectors from complex
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// template < class S, class V >
|
||||
// inline auto ComplexRemove(const Grid_simd<S,V> &c) -> Grid_simd<Grid_simd<S,V>::Real,V> {
|
||||
// Grid_simd<Grid_simd<S,V>::Real,V> ret;
|
||||
// ret.v = c.v;
|
||||
// return ret;
|
||||
// }
|
||||
template<class scalar> struct AndFunctor {
|
||||
scalar operator()(const scalar &x, const scalar &y) const {
|
||||
return x & y;
|
||||
}
|
||||
};
|
||||
template<class scalar> struct OrFunctor {
|
||||
scalar operator()(const scalar &x, const scalar &y) const {
|
||||
return x | y;
|
||||
}
|
||||
};
|
||||
template<class scalar> struct AndAndFunctor {
|
||||
scalar operator()(const scalar &x, const scalar &y) const {
|
||||
return x && y;
|
||||
}
|
||||
};
|
||||
template<class scalar> struct OrOrFunctor {
|
||||
scalar operator()(const scalar &x, const scalar &y) const {
|
||||
return x || y;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// Calls to simd binop functors
|
||||
////////////////////////////////
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> operator &(const Grid_simd<S,V> &x,const Grid_simd<S,V> &y) {
|
||||
return SimdApplyBinop(AndFunctor<S>(),x,y);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> operator &&(const Grid_simd<S,V> &x,const Grid_simd<S,V> &y) {
|
||||
return SimdApplyBinop(AndAndFunctor<S>(),x,y);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> operator |(const Grid_simd<S,V> &x,const Grid_simd<S,V> &y) {
|
||||
return SimdApplyBinop(OrFunctor<S>(),x,y);
|
||||
}
|
||||
template < class S, class V >
|
||||
inline Grid_simd<S,V> operator ||(const Grid_simd<S,V> &x,const Grid_simd<S,V> &y) {
|
||||
return SimdApplyBinop(OrOrFunctor<S>(),x,y);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> cos(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(CosRealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> sin(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(SinRealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> acos(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(AcosRealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> asin(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(AsinRealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> log(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(LogRealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> abs(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(AbsRealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> exp(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(ExpRealFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> Not(const Grid_simd<S, V> &r) {
|
||||
return SimdApply(NotFunctor<S>(), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> pow(const Grid_simd<S, V> &r, double y) {
|
||||
return SimdApply(PowRealFunctor<S>(y), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> mod(const Grid_simd<S, V> &r, Integer y) {
|
||||
return SimdApply(ModIntFunctor<S>(y), r);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> div(const Grid_simd<S, V> &r, Integer y) {
|
||||
return SimdApply(DivIntFunctor<S>(y), r);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Allows us to assign into **conformable** real vectors from complex
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// template < class S, class V >
|
||||
// inline auto ComplexRemove(const Grid_simd<S,V> &c) ->
|
||||
// Grid_simd<Grid_simd<S,V>::Real,V> {
|
||||
// Grid_simd<Grid_simd<S,V>::Real,V> ret;
|
||||
// ret.v = c.v;
|
||||
// return ret;
|
||||
// }
|
||||
template <class scalar>
|
||||
struct AndFunctor {
|
||||
scalar operator()(const scalar &x, const scalar &y) const { return x & y; }
|
||||
};
|
||||
template <class scalar>
|
||||
struct OrFunctor {
|
||||
scalar operator()(const scalar &x, const scalar &y) const { return x | y; }
|
||||
};
|
||||
template <class scalar>
|
||||
struct AndAndFunctor {
|
||||
scalar operator()(const scalar &x, const scalar &y) const { return x && y; }
|
||||
};
|
||||
template <class scalar>
|
||||
struct OrOrFunctor {
|
||||
scalar operator()(const scalar &x, const scalar &y) const { return x || y; }
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// Calls to simd binop functors
|
||||
////////////////////////////////
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> operator&(const Grid_simd<S, V> &x,
|
||||
const Grid_simd<S, V> &y) {
|
||||
return SimdApplyBinop(AndFunctor<S>(), x, y);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> operator&&(const Grid_simd<S, V> &x,
|
||||
const Grid_simd<S, V> &y) {
|
||||
return SimdApplyBinop(AndAndFunctor<S>(), x, y);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> operator|(const Grid_simd<S, V> &x,
|
||||
const Grid_simd<S, V> &y) {
|
||||
return SimdApplyBinop(OrFunctor<S>(), x, y);
|
||||
}
|
||||
template <class S, class V>
|
||||
inline Grid_simd<S, V> operator||(const Grid_simd<S, V> &x,
|
||||
const Grid_simd<S, V> &y) {
|
||||
return SimdApplyBinop(OrOrFunctor<S>(), x, y);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,31 +1,32 @@
|
||||
/*************************************************************************************
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./tests/Test_simd.cc
|
||||
Source file: ./tests/Test_simd.cc
|
||||
|
||||
Copyright (C) 2015
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: neo <cossu@post.kek.jp>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
See the full license in the file "LICENSE" in the top level distribution
|
||||
directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#include <Grid.h>
|
||||
|
||||
using namespace std;
|
||||
@ -62,6 +63,18 @@ public:
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = adj(i1);}
|
||||
std::string name(void) const { return std::string("Adj"); }
|
||||
};
|
||||
class funcImag {
|
||||
public:
|
||||
funcImag() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = imag(i1);}
|
||||
std::string name(void) const { return std::string("imag"); }
|
||||
};
|
||||
class funcReal {
|
||||
public:
|
||||
funcReal() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = real(i1);}
|
||||
std::string name(void) const { return std::string("real"); }
|
||||
};
|
||||
|
||||
class funcTimesI {
|
||||
public:
|
||||
@ -141,7 +154,13 @@ void Tester(const functor &func)
|
||||
}
|
||||
|
||||
extract<vec,scal>(v_result,result);
|
||||
std::cout<<GridLogMessage << " " << func.name()<<std::endl;
|
||||
|
||||
std::cout << GridLogMessage << " " << func.name() << std::endl;
|
||||
|
||||
std::cout << GridLogDebug << v_input1 << std::endl;
|
||||
std::cout << GridLogDebug << v_result << std::endl;
|
||||
|
||||
|
||||
|
||||
int ok=0;
|
||||
for(int i=0;i<Nsimd;i++){
|
||||
@ -389,6 +408,8 @@ int main (int argc, char ** argv)
|
||||
Tester<ComplexF,vComplexF>(funcTimes());
|
||||
Tester<ComplexF,vComplexF>(funcConj());
|
||||
Tester<ComplexF,vComplexF>(funcAdj());
|
||||
Tester<ComplexF,vComplexF>(funcReal());
|
||||
Tester<ComplexF,vComplexF>(funcImag());
|
||||
Tester<ComplexF,vComplexF>(funcInnerProduct());
|
||||
ReductionTester<ComplexF,ComplexF,vComplexF>(funcReduce());
|
||||
|
||||
@ -421,17 +442,21 @@ int main (int argc, char ** argv)
|
||||
Tester<ComplexD,vComplexD>(funcTimes());
|
||||
Tester<ComplexD,vComplexD>(funcConj());
|
||||
Tester<ComplexD,vComplexD>(funcAdj());
|
||||
Tester<ComplexD,vComplexD>(funcInnerProduct());
|
||||
ReductionTester<ComplexD,ComplexD,vComplexD>(funcReduce());
|
||||
Tester<ComplexD, vComplexD>(funcReal());
|
||||
Tester<ComplexD, vComplexD>(funcImag());
|
||||
|
||||
Tester<ComplexD, vComplexD>(funcInnerProduct());
|
||||
ReductionTester<ComplexD, ComplexD, vComplexD>(funcReduce());
|
||||
|
||||
std::cout<<GridLogMessage << "==================================="<< std::endl;
|
||||
std::cout<<GridLogMessage << "Testing vComplexD permutes "<<std::endl;
|
||||
std::cout<<GridLogMessage << "==================================="<< std::endl;
|
||||
std::cout << GridLogMessage
|
||||
<< "===================================" << std::endl;
|
||||
std::cout << GridLogMessage << "Testing vComplexD permutes " << std::endl;
|
||||
std::cout << GridLogMessage
|
||||
<< "===================================" << std::endl;
|
||||
|
||||
// Log2 iteration
|
||||
for(int i=0;(1<<i)< vComplexD::Nsimd();i++){
|
||||
PermTester<ComplexD,vComplexD>(funcPermute(i));
|
||||
for (int i = 0; (1 << i) < vComplexD::Nsimd(); i++) {
|
||||
PermTester<ComplexD, vComplexD>(funcPermute(i));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user