Grid
0.7.0
Tensor_outer.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_outer.h
6
7
Copyright (C) 2015
8
9
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 2 of the License, or
14
(at your option) any later version.
15
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
20
21
You should have received a copy of the GNU General Public License along
22
with this program; if not, write to the Free Software Foundation, Inc.,
23
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25
See the full license in the file "LICENSE" in the top level distribution directory
26
*************************************************************************************/
27
/* END LEGAL */
28
#ifndef GRID_MATH_OUTER_H
29
#define GRID_MATH_OUTER_H
30
31
NAMESPACE_BEGIN
(
Grid
);
32
34
// outerProduct Scalar x Scalar -> Scalar
35
// Vector x Vector -> Matrix
37
template
<
class
CC,IfComplex<CC> = 0>
38
accelerator_inline
CC
outerProduct
(
const
CC &l,
const
CC& r)
39
{
40
return
l*
conj
(r);
41
}
42
template
<
class
RR,IfReal<RR> = 0>
43
accelerator_inline
RR
outerProduct
(
const
RR &l,
const
RR& r)
44
{
45
return
l*r;
46
}
47
48
template
<
class
l,
class
r,
int
N>
accelerator_inline
49
auto
outerProduct
(
const
iVector<l,N>
& lhs,
const
iVector<r,N>
& rhs) ->
iMatrix
<
decltype
(
outerProduct
(lhs._internal[0],rhs._internal[0])),N>
50
{
51
typedef
decltype
(
outerProduct
(lhs._internal[0],rhs._internal[0])) ret_t;
52
iMatrix<ret_t,N>
ret;
53
for
(
int
c1=0;c1<N;c1++){
54
for
(
int
c2=0;c2<N;c2++){
55
ret._internal[c1][c2] =
outerProduct
(lhs._internal[c1],rhs._internal[c2]);
56
}}
57
return
ret;
58
}
59
60
61
template
<
class
l,
class
r>
accelerator_inline
62
auto
outerProduct
(
const
iScalar<l>
& lhs,
const
iScalar<r>
& rhs) ->
iScalar
<
decltype
(
outerProduct
(lhs._internal,rhs._internal))>
63
{
64
typedef
decltype
(
outerProduct
(lhs._internal,rhs._internal)) ret_t;
65
iScalar<ret_t>
ret;
66
ret.
_internal
=
outerProduct
(lhs._internal,rhs._internal);
67
return
ret;
68
}
69
70
NAMESPACE_END
(
Grid
);
71
72
#endif
accelerator_inline
#define accelerator_inline
Definition
Accelerator.h:608
conj
#define conj(a, b, i)
Definition
Grid_generic.h:219
NAMESPACE_BEGIN
#define NAMESPACE_BEGIN(A)
Definition
Namespace.h:35
NAMESPACE_END
#define NAMESPACE_END(A)
Definition
Namespace.h:36
outerProduct
accelerator_inline CC outerProduct(const CC &l, const CC &r)
Definition
Tensor_outer.h:38
iMatrix
Definition
Tensor_class.h:301
iScalar
Definition
Tensor_class.h:77
iScalar::_internal
vtype _internal
Definition
Tensor_class.h:79
iVector
Definition
Tensor_class.h:189
Grid
Definition
Deflation.h:31
Grid
tensors
Tensor_outer.h
Generated by
1.16.1