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
9Author: 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
32
34// outerProduct Scalar x Scalar -> Scalar
35// Vector x Vector -> Matrix
37template<class CC,IfComplex<CC> = 0>
38accelerator_inline CC outerProduct(const CC &l, const CC& r)
39{
40 return l*conj(r);
41}
42template<class RR,IfReal<RR> = 0>
43accelerator_inline RR outerProduct(const RR &l, const RR& r)
44{
45 return l*r;
46}
47
48template<class l,class r,int N> accelerator_inline
49auto 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;
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
61template<class l,class r> accelerator_inline
62auto 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;
66 ret._internal = outerProduct(lhs._internal,rhs._internal);
67 return ret;
68}
69
71
72#endif
#define accelerator_inline
#define conj(a, b, i)
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
accelerator_inline CC outerProduct(const CC &l, const CC &r)
vtype _internal