Grid 0.7.0
Lattice_reality.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_reality.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>
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc.,
25 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26
27 See the full license in the file "LICENSE" in the top level distribution directory
28*************************************************************************************/
29/* END LEGAL */
30#ifndef GRID_LATTICE_REALITY_H
31#define GRID_LATTICE_REALITY_H
32
33
34// FIXME .. this is the sector of the code
35// I am most worried about the directions
36// The choice of burying complex in the SIMD
37// is making the use of "real" and "imag" very cumbersome
38
40
41template<class vobj> inline Lattice<vobj> adj(const Lattice<vobj> &lhs){
42 Lattice<vobj> ret(lhs.Grid());
43
44 autoView( lhs_v, lhs, AcceleratorRead);
45 autoView( ret_v, ret, AcceleratorWrite);
46
47 ret.Checkerboard()=lhs.Checkerboard();
48 accelerator_for( ss, lhs_v.size(), 1, {
49 ret_v[ss] = adj(lhs_v[ss]);
50 });
51 return ret;
52};
53
54template<class vobj> inline Lattice<vobj> conjugate(const Lattice<vobj> &lhs){
55 Lattice<vobj> ret(lhs.Grid());
56
57 autoView( lhs_v, lhs, AcceleratorRead);
58 autoView( ret_v, ret, AcceleratorWrite);
59
60 ret.Checkerboard() = lhs.Checkerboard();
61 accelerator_for( ss, lhs_v.size(), vobj::Nsimd(), {
62 coalescedWrite( ret_v[ss] , conjugate(lhs_v(ss)));
63 });
64 return ret;
65};
66
67template<class vobj> inline Lattice<typename vobj::Complexified> toComplex(const Lattice<vobj> &lhs){
69
70 autoView( lhs_v, lhs, AcceleratorRead);
71 autoView( ret_v, ret, AcceleratorWrite);
72
73 ret.Checkerboard() = lhs.Checkerboard();
74 accelerator_for( ss, lhs_v.size(), 1, {
75 ret_v[ss] = toComplex(lhs_v[ss]);
76 });
77 return ret;
78};
79template<class vobj> inline Lattice<typename vobj::Realified> toReal(const Lattice<vobj> &lhs){
81
82 autoView( lhs_v, lhs, AcceleratorRead);
83 autoView( ret_v, ret, AcceleratorWrite);
84
85 ret.Checkerboard() = lhs.Checkerboard();
86 accelerator_for( ss, lhs_v.size(), 1, {
87 ret_v[ss] = toReal(lhs_v[ss]);
88 });
89 return ret;
90};
91
92
93template<class Expression,typename std::enable_if<is_lattice_expr<Expression>::value,void>::type * = nullptr>
94auto toComplex(const Expression &expr) -> decltype(closure(expr))
95{
96 return toComplex(closure(expr));
97}
98template<class Expression,typename std::enable_if<is_lattice_expr<Expression>::value,void>::type * = nullptr>
99auto toReal(const Expression &expr) -> decltype(closure(expr))
100{
101 return toReal(closure(expr));
102}
103template<class Expression,typename std::enable_if<is_lattice_expr<Expression>::value,void>::type * = nullptr>
104auto adj(const Expression &expr) -> decltype(closure(expr))
105{
106 return adj(closure(expr));
107}
108template<class Expression,typename std::enable_if<is_lattice_expr<Expression>::value,void>::type * = nullptr>
109auto conjugate(const Expression &expr) -> decltype(closure(expr))
110{
111 return conjugate(closure(expr));
112}
113
115
116#endif
#define accelerator_for(iterator, num, nsimd,...)
auto closure(const LatticeUnaryExpression< Op, T1 > &expr) -> Lattice< typename std::remove_const< decltype(expr.op.func(vecEval(0, expr.arg1)))>::type >
Definition Lattice_ET.h:492
Lattice< typename vobj::Complexified > toComplex(const Lattice< vobj > &lhs)
Lattice< vobj > conjugate(const Lattice< vobj > &lhs)
Lattice< typename vobj::Realified > toReal(const Lattice< vobj > &lhs)
Lattice< vobj > adj(const Lattice< vobj > &lhs)
#define autoView(l_v, l, mode)
@ AcceleratorRead
@ AcceleratorWrite
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
accelerator_inline int Checkerboard(void) const
GridBase * Grid(void) const