Grid
0.7.0
Tensor_arith_add.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_arith_add.h
6
7
Copyright (C) 2015
8
9
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10
Author: neo <cossu@post.kek.jp>
11
12
This program is free software; you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
14
the Free Software Foundation; either version 2 of the License, or
15
(at your option) any later version.
16
17
This program is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
GNU General Public License for more details.
21
22
You should have received a copy of the GNU General Public License along
23
with this program; if not, write to the Free Software Foundation, Inc.,
24
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26
See the full license in the file "LICENSE" in the top level distribution directory
27
*************************************************************************************/
28
/* END LEGAL */
29
#ifndef GRID_MATH_ARITH_ADD_H
30
#define GRID_MATH_ARITH_ADD_H
31
32
NAMESPACE_BEGIN
(
Grid
);
33
37
38
// ADD is simple for now; cannot mix types and straightforward template
39
// Scalar +/- Scalar
40
// Vector +/- Vector
41
// Matrix +/- Matrix
42
template
<
class
vtype,
class
ltype,
class
rtype>
accelerator_inline
void
add
(
iScalar<vtype>
* __restrict__ ret,
43
const
iScalar<ltype>
* __restrict__ lhs,
44
const
iScalar<rtype>
* __restrict__ rhs)
45
{
46
add
(&ret->
_internal
,&lhs->
_internal
,&rhs->
_internal
);
47
}
48
template
<
class
vtype,
class
ltype,
class
rtype,
int
N>
accelerator_inline
void
add
(
iVector<vtype,N>
* __restrict__ ret,
49
const
iVector<ltype,N>
* __restrict__ lhs,
50
const
iVector<rtype,N>
* __restrict__ rhs)
51
{
52
for
(
int
c=0;c<N;c++){
53
ret->
_internal
[c]=lhs->
_internal
[c]+rhs->
_internal
[c];
54
}
55
return
;
56
}
57
58
template
<
class
vtype,
class
ltype,
class
rtype,
int
N>
accelerator_inline
void
add
(
iMatrix<vtype,N>
* __restrict__ ret,
59
const
iMatrix<ltype,N>
* __restrict__ lhs,
60
const
iMatrix<rtype,N>
* __restrict__ rhs)
61
{
62
for
(
int
c2=0;c2<N;c2++){
63
for
(
int
c1=0;c1<N;c1++){
64
add
(&ret->
_internal
[c1][c2],&lhs->
_internal
[c1][c2],&rhs->
_internal
[c1][c2]);
65
}}
66
return
;
67
}
68
template
<
class
vtype,
class
ltype,
class
rtype,
int
N>
accelerator_inline
void
add
(
iMatrix<vtype,N>
* __restrict__ ret,
69
const
iScalar<ltype>
* __restrict__ lhs,
70
const
iMatrix<rtype,N>
* __restrict__ rhs)
71
{
72
for
(
int
c2=0;c2<N;c2++){
73
for
(
int
c1=0;c1<N;c1++){
74
if
( c1==c2)
75
add
(&ret->
_internal
[c1][c2],&lhs->
_internal
,&rhs->
_internal
[c1][c2]);
76
else
77
ret->
_internal
[c1][c2]=lhs->
_internal
[c1][c2];
78
}}
79
return
;
80
}
81
template
<
class
vtype,
class
ltype,
class
rtype,
int
N>
accelerator_inline
void
add
(
iMatrix<vtype,N>
* __restrict__ ret,
82
const
iMatrix<ltype,N>
* __restrict__ lhs,
83
const
iScalar<rtype>
* __restrict__ rhs)
84
{
85
for
(
int
c2=0;c2<N;c2++){
86
for
(
int
c1=0;c1<N;c1++){
87
if
( c1==c2)
88
add
(&ret->
_internal
[c1][c2],&lhs->
_internal
[c1][c2],&rhs->
_internal
);
89
else
90
ret->
_internal
[c1][c2]=lhs->
_internal
[c1][c2];
91
}}
92
return
;
93
}
94
95
96
// + operator for scalar, vector, matrix
97
template
<
class
ltype,
class
rtype>
98
accelerator_inline
auto
operator +
(
const
iScalar<ltype>
& lhs,
const
iScalar<rtype>
& rhs) ->
iScalar
<
decltype
(lhs._internal + rhs._internal)>
99
{
100
typedef
iScalar
<
decltype
(lhs._internal+rhs._internal)> ret_t;
101
ret_t ret ;
102
add
(&ret,&lhs,&rhs);
103
return
ret;
104
}
105
template
<
class
ltype,
class
rtype,
int
N>
106
accelerator_inline
auto
operator +
(
const
iVector<ltype,N>
& lhs,
const
iVector<rtype,N>
& rhs) ->iVector<
decltype
(lhs._internal[0]+rhs._internal[0]),N>
107
{
108
typedef
iVector
<
decltype
(lhs._internal[0]+rhs._internal[0]),N> ret_t;
109
ret_t ret ;
110
add
(&ret,&lhs,&rhs);
111
return
ret;
112
}
113
template
<
class
ltype,
class
rtype,
int
N>
114
accelerator_inline
auto
operator +
(
const
iMatrix<ltype,N>
& lhs,
const
iMatrix<rtype,N>
& rhs) ->iMatrix<
decltype
(lhs._internal[0][0]+rhs._internal[0][0]),N>
115
{
116
typedef
iMatrix
<
decltype
(lhs._internal[0][0]+rhs._internal[0][0]),N> ret_t;
117
ret_t ret ;
118
add
(&ret,&lhs,&rhs);
119
return
ret;
120
}
121
template
<
class
ltype,
class
rtype,
int
N>
122
accelerator_inline
auto
operator +
(
const
iScalar<ltype>
& lhs,
const
iMatrix<rtype,N>
& rhs)->iMatrix<
decltype
(lhs._internal+rhs._internal[0][0]),N>
123
{
124
typedef
iMatrix
<
decltype
(lhs._internal+rhs._internal[0][0]),N> ret_t;
125
ret_t ret ;
126
add
(&ret,&lhs,&rhs);
127
return
ret;
128
}
129
130
template
<
class
ltype,
class
rtype,
int
N>
131
accelerator_inline
auto
operator +
(
const
iMatrix<ltype,N>
& lhs,
const
iScalar<rtype>
& rhs)->iMatrix<
decltype
(lhs._internal[0][0]+rhs._internal),N>
132
{
133
typedef
iMatrix
<
decltype
(lhs._internal[0][0]+rhs._internal),N> ret_t;
134
ret_t ret ;
135
add
(&ret,&lhs,&rhs);
136
return
ret;
137
}
138
139
NAMESPACE_END
(
Grid
);
140
141
142
#endif
accelerator_inline
#define accelerator_inline
Definition
Accelerator.h:608
NAMESPACE_BEGIN
#define NAMESPACE_BEGIN(A)
Definition
Namespace.h:35
NAMESPACE_END
#define NAMESPACE_END(A)
Definition
Namespace.h:36
add
accelerator_inline void add(iScalar< vtype > *__restrict__ ret, const iScalar< ltype > *__restrict__ lhs, const iScalar< rtype > *__restrict__ rhs)
Definition
Tensor_arith_add.h:42
operator+
accelerator_inline auto operator+(const iScalar< ltype > &lhs, const iScalar< rtype > &rhs) -> iScalar< decltype(lhs._internal+rhs._internal)>
Definition
Tensor_arith_add.h:98
iMatrix
Definition
Tensor_class.h:301
iMatrix::_internal
vtype _internal[N][N]
Definition
Tensor_class.h:303
iScalar
Definition
Tensor_class.h:77
iScalar::_internal
vtype _internal
Definition
Tensor_class.h:79
iVector
Definition
Tensor_class.h:189
iVector::_internal
vtype _internal[N]
Definition
Tensor_class.h:191
Grid
Definition
Deflation.h:31
Grid
tensors
Tensor_arith_add.h
Generated by
1.16.1