Grid 0.7.0
Tensor_arith_mac.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_mac.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_ARITH_MAC_H
29#define GRID_MATH_ARITH_MAC_H
30
32
37
39// Legal multiplication table
41// scal x scal = scal
42// mat x mat = mat
43// mat x scal = mat
44// scal x mat = mat
45// mat x vec = vec
46// vec x scal = vec
47// scal x vec = vec
49template<class rtype,class vtype,class mtype>
50accelerator_inline void mac(iScalar<rtype> * __restrict__ ret,const iScalar<vtype> * __restrict__ lhs,const iScalar<mtype> * __restrict__ rhs)
51{
52 mac(&ret->_internal,&lhs->_internal,&rhs->_internal);
53}
54template<class rrtype,class ltype,class rtype,int N>
55accelerator_inline void mac(iMatrix<rrtype,N> * __restrict__ ret,const iMatrix<ltype,N> * __restrict__ lhs,const iMatrix<rtype,N> * __restrict__ rhs){
56 for(int c3=0;c3<N;c3++){
57 for(int c1=0;c1<N;c1++){
58 for(int c2=0;c2<N;c2++){
59 mac(&ret->_internal[c1][c2],&lhs->_internal[c1][c3],&rhs->_internal[c3][c2]);
60 }}}
61 return;
62}
63
64template<class rrtype,class ltype,class rtype,int N>
65accelerator_inline void mac(iMatrix<rrtype,N> * __restrict__ ret,const iMatrix<ltype,N> * __restrict__ lhs,const iScalar<rtype> * __restrict__ rhs){
66 for(int c1=0;c1<N;c1++){
67 for(int c2=0;c2<N;c2++){
68 mac(&ret->_internal[c1][c2],&lhs->_internal[c1][c2],&rhs->_internal);
69 }}
70 return;
71}
72template<class rrtype,class ltype,class rtype,int N>
73accelerator_inline void mac(iMatrix<rrtype,N> * __restrict__ ret,const iScalar<ltype> * __restrict__ lhs,const iMatrix<rtype,N> * __restrict__ rhs){
74 for(int c1=0;c1<N;c1++){
75 for(int c2=0;c2<N;c2++){
76 mac(&ret->_internal[c1][c2],&lhs->_internal,&rhs->_internal[c1][c2]);
77 }}
78 return;
79}
80template<class rrtype,class ltype,class rtype,int N>
81accelerator_inline void mac(iVector<rrtype,N> * __restrict__ ret,const iMatrix<ltype,N> * __restrict__ lhs,const iVector<rtype,N> * __restrict__ rhs)
82{
83 for(int c1=0;c1<N;c1++){
84 for(int c2=0;c2<N;c2++){
85 mac(&ret->_internal[c1],&lhs->_internal[c1][c2],&rhs->_internal[c2]);
86 }}
87 return;
88}
89template<class rrtype,class ltype,class rtype,int N>
90accelerator_inline void mac(iVector<rrtype,N> * __restrict__ ret,const iScalar<ltype> * __restrict__ lhs,const iVector<rtype,N> * __restrict__ rhs)
91{
92 for(int c1=0;c1<N;c1++){
93 mac(&ret->_internal[c1],&lhs->_internal,&rhs->_internal[c1]);
94 }
95 return;
96}
97template<class rrtype,class ltype,class rtype,int N>
98accelerator_inline void mac(iVector<rrtype,N> * __restrict__ ret,const iVector<ltype,N> * __restrict__ lhs,const iScalar<rtype> * __restrict__ rhs)
99{
100 for(int c1=0;c1<N;c1++){
101 mac(&ret->_internal[c1],&lhs->_internal[c1],&rhs->_internal);
102 }
103 return;
104}
106
107
108#endif
#define accelerator_inline
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
accelerator_inline void mac(iScalar< rtype > *__restrict__ ret, const iScalar< vtype > *__restrict__ lhs, const iScalar< mtype > *__restrict__ rhs)
vtype _internal[N][N]
vtype _internal
vtype _internal[N]