Grid 0.7.0
Tensor_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/tensors/Tensor_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: paboyle <paboyle@ph.ed.ac.uk>
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_TENSOR_UNARY_H
31#define GRID_TENSOR_UNARY_H
32
34
35#define UNARY(func) \
36 template<class obj> accelerator_inline auto func(const iScalar<obj> &z) -> iScalar<obj> \
37 { \
38 iScalar<obj> ret; \
39 ret._internal = func( (z._internal)); \
40 return ret; \
41 } \
42 template<class obj,int N> accelerator_inline auto func(const iVector<obj,N> &z) -> iVector<obj,N> \
43 { \
44 iVector<obj,N> ret; \
45 for(int c1=0;c1<N;c1++){ \
46 ret._internal[c1] = func( (z._internal[c1])); \
47 } \
48 return ret; \
49 } \
50 template<class obj,int N> accelerator_inline auto func(const iMatrix<obj,N> &z) -> iMatrix<obj,N> \
51 { \
52 iMatrix<obj,N> ret; \
53 for(int c1=0;c1<N;c1++){ \
54 for(int c2=0;c2<N;c2++){ \
55 ret._internal[c1][c2] = func( (z._internal[c1][c2])); \
56 }} \
57 return ret; \
58 }
59
60
61#define BINARY_RSCALAR(func,scal) \
62 template<class obj> accelerator_inline iScalar<obj> func(const iScalar<obj> &z,scal y) \
63 { \
64 iScalar<obj> ret; \
65 ret._internal = func(z._internal,y); \
66 return ret; \
67 } \
68 template<class obj,int N> accelerator_inline iVector<obj,N> func(const iVector<obj,N> &z,scal y) \
69 { \
70 iVector<obj,N> ret; \
71 for(int c1=0;c1<N;c1++){ \
72 ret._internal[c1] = func(z._internal[c1],y); \
73 } \
74 return ret; \
75 } \
76 template<class obj,int N> accelerator_inline iMatrix<obj,N> func(const iMatrix<obj,N> &z, scal y) \
77 { \
78 iMatrix<obj,N> ret; \
79 for(int c1=0;c1<N;c1++){ \
80 for(int c2=0;c2<N;c2++){ \
81 ret._internal[c1][c2] = func(z._internal[c1][c2],y); \
82 }} \
83 return ret; \
84 }
85
95
96
97template<class obj> accelerator_inline auto toReal(const iScalar<obj> &z) -> typename iScalar<obj>::Realified
98{
99 typename iScalar<obj>::Realified ret;
100 ret._internal = toReal(z._internal);
101 return ret;
102}
103template<class obj,int N> accelerator_inline auto toReal(const iVector<obj,N> &z) -> typename iVector<obj,N>::Realified
104{
105 typename iVector<obj,N>::Realified ret;
106 for(int c1=0;c1<N;c1++){
107 ret._internal[c1] = toReal(z._internal[c1]);
108 }
109 return ret;
110}
111template<class obj,int N> accelerator_inline auto toReal(const iMatrix<obj,N> &z) -> typename iMatrix<obj,N>::Realified
112{
113 typename iMatrix<obj,N>::Realified ret;
114 for(int c1=0;c1<N;c1++){
115 for(int c2=0;c2<N;c2++){
116 ret._internal[c1][c2] = toReal(z._internal[c1][c2]);
117 }}
118 return ret;
119}
120
121template<class obj> accelerator_inline auto toComplex(const iScalar<obj> &z) -> typename iScalar<obj>::Complexified
122{
123 typename iScalar<obj>::Complexified ret;
124 ret._internal = toComplex(z._internal);
125 return ret;
126}
127template<class obj,int N> accelerator_inline auto toComplex(const iVector<obj,N> &z) -> typename iVector<obj,N>::Complexified
128{
129 typename iVector<obj,N>::Complexified ret;
130 for(int c1=0;c1<N;c1++){
131 ret._internal[c1] = toComplex(z._internal[c1]);
132 }
133 return ret;
134}
135template<class obj,int N> accelerator_inline auto toComplex(const iMatrix<obj,N> &z) -> typename iMatrix<obj,N>::Complexified
136{
137 typename iMatrix<obj,N>::Complexified ret;
138 for(int c1=0;c1<N;c1++){
139 for(int c2=0;c2<N;c2++){
140 ret._internal[c1][c2] = toComplex(z._internal[c1][c2]);
141 }}
142 return ret;
143}
144
149
150#undef UNARY
151#undef BINARY_RSCALAR
152
154
155#endif
#define accelerator_inline
accelerator_inline Grid_simd< S, V > cos(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > abs(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > asin(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > sin(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > Not(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > acos(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > exp(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > sqrt(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > log(const Grid_simd< S, V > &r)
Lattice< obj > mod(const Lattice< obj > &rhs_i, Integer y)
Lattice< obj > div(const Lattice< obj > &rhs_i, Integer y)
Lattice< obj > pow(const Lattice< obj > &rhs_i, RealD y)
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
uint32_t Integer
Definition Simd.h:58
float RealF
Definition Simd.h:60
double RealD
Definition Simd.h:61
accelerator_inline auto toComplex(const iScalar< obj > &z) -> typename iScalar< obj >::Complexified
#define BINARY_RSCALAR(func, scal)
#define UNARY(func)
accelerator_inline auto toReal(const iScalar< obj > &z) -> typename iScalar< obj >::Realified
vtype _internal[N][N]
vtype _internal
vtype _internal[N]