Grid 0.7.0
Lattice_unary.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/lattice/Lattice_unary.h
6
7 Copyright (C) 2015
8
9Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
10Author: Peter Boyle <paboyle@ph.ed.ac.uk>
11Author: neo <cossu@post.kek.jp>
12Author: paboyle <paboyle@ph.ed.ac.uk>
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License along
25 with this program; if not, write to the Free Software Foundation, Inc.,
26 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27
28 See the full license in the file "LICENSE" in the top level distribution directory
29*************************************************************************************/
30/* END LEGAL */
31#ifndef GRID_LATTICE_UNARY_H
32#define GRID_LATTICE_UNARY_H
33
35
36template<class obj> Lattice<obj> pow(const Lattice<obj> &rhs_i,RealD y){
37 Lattice<obj> ret_i(rhs_i.Grid());
38 autoView( rhs, rhs_i, AcceleratorRead);
39 autoView( ret, ret_i, AcceleratorWrite);
40 ret.Checkerboard() = rhs.Checkerboard();
41 accelerator_for(ss,rhs.size(),1,{
42 ret[ss]=pow(rhs[ss],y);
43 });
44 return ret_i;
45}
46template<class obj> Lattice<obj> mod(const Lattice<obj> &rhs_i,Integer y){
47 Lattice<obj> ret_i(rhs_i.Grid());
48 autoView( rhs , rhs_i, AcceleratorRead);
49 autoView( ret , ret_i, AcceleratorWrite);
50 ret.Checkerboard() = rhs.Checkerboard();
51 accelerator_for(ss,rhs.size(),obj::Nsimd(),{
52 coalescedWrite(ret[ss],mod(rhs(ss),y));
53 });
54 return ret_i;
55}
56
57template<class obj> Lattice<obj> div(const Lattice<obj> &rhs_i,Integer y){
58 Lattice<obj> ret_i(rhs_i.Grid());
59 autoView( ret , ret_i, AcceleratorWrite);
60 autoView( rhs , rhs_i, AcceleratorRead);
61 ret.Checkerboard() = rhs_i.Checkerboard();
62 accelerator_for(ss,rhs.size(),obj::Nsimd(),{
63 coalescedWrite(ret[ss],div(rhs(ss),y));
64 });
65 return ret_i;
66}
67
68template<class obj> Lattice<obj> expMat(const Lattice<obj> &rhs_i, RealD alpha, Integer Nexp = DEFAULT_MAT_EXP){
69 Lattice<obj> ret_i(rhs_i.Grid());
70 autoView( rhs , rhs_i, AcceleratorRead);
71 autoView( ret , ret_i, AcceleratorWrite);
72 ret.Checkerboard() = rhs.Checkerboard();
73 accelerator_for(ss,rhs.size(),obj::Nsimd(),{
74 coalescedWrite(ret[ss],Exponentiate(rhs(ss),alpha, Nexp));
75 });
76 return ret_i;
77}
78
80#endif
#define accelerator_for(iterator, num, nsimd,...)
Lattice< obj > mod(const Lattice< obj > &rhs_i, Integer y)
Lattice< obj > div(const Lattice< obj > &rhs_i, Integer y)
Lattice< obj > expMat(const Lattice< obj > &rhs_i, RealD alpha, Integer Nexp=DEFAULT_MAT_EXP)
Lattice< obj > pow(const Lattice< obj > &rhs_i, RealD y)
#define autoView(l_v, l, mode)
@ AcceleratorRead
@ AcceleratorWrite
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
uint32_t Integer
Definition Simd.h:58
double RealD
Definition Simd.h:61
#define DEFAULT_MAT_EXP
Definition Tensor_exp.h:31
accelerator_inline int Checkerboard(void) const
GridBase * Grid(void) const