Grid 0.7.0
Lattice_real_imag.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_REAL_IMAG_H
31#define GRID_LATTICE_REAL_IMAG_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> real(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] =real(lhs_v[ss]);
50 });
51 return ret;
52};
53template<class vobj> inline Lattice<vobj> imag(const Lattice<vobj> &lhs){
54 Lattice<vobj> ret(lhs.Grid());
55
56 autoView( lhs_v, lhs, AcceleratorRead);
57 autoView( ret_v, ret, AcceleratorWrite);
58
59 ret.Checkerboard()=lhs.Checkerboard();
60 accelerator_for( ss, lhs_v.size(), 1, {
61 ret_v[ss] =imag(lhs_v[ss]);
62 });
63 return ret;
64};
65
66template<class Expression,typename std::enable_if<is_lattice_expr<Expression>::value,void>::type * = nullptr>
67 auto real(const Expression &expr) -> decltype(real(closure(expr)))
68{
69 return real(closure(expr));
70}
71template<class Expression,typename std::enable_if<is_lattice_expr<Expression>::value,void>::type * = nullptr>
72 auto imag(const Expression &expr) -> decltype(imag(closure(expr)))
73{
74 return imag(closure(expr));
75}
76
78
79#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< vobj > real(const Lattice< vobj > &lhs)
Lattice< vobj > imag(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