/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/tensors/Tensor_arith_mul.h Copyright (C) 2015 Author: Peter Boyle This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ #ifndef GRID_MATH_ARITH_MUL_H #define GRID_MATH_ARITH_MUL_H NAMESPACE_BEGIN(Grid); /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////// MUL /////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// template accelerator_inline void mult(iScalar * __restrict__ ret,const iScalar * __restrict__ lhs,const iScalar * __restrict__ rhs){ mult(&ret->_internal,&lhs->_internal,&rhs->_internal); } template accelerator_inline void mult(iMatrix * __restrict__ ret,const iMatrix * __restrict__ lhs,const iMatrix * __restrict__ rhs){ for(int c1=0;c1_internal[c1][c2],&lhs->_internal[c1][0],&rhs->_internal[0][c2]); } } for(int c1=0;c1_internal[c1][c2],&lhs->_internal[c1][c3],&rhs->_internal[c3][c2]); } } } return; } template accelerator_inline void mult(iMatrix * __restrict__ ret,const iMatrix * __restrict__ lhs,const iScalar * __restrict__ rhs){ for(int c2=0;c2_internal[c1][c2],&lhs->_internal[c1][c2],&rhs->_internal); }} return; } template accelerator_inline void mult(iMatrix * __restrict__ ret,const iScalar * __restrict__ lhs,const iMatrix * __restrict__ rhs){ for(int c2=0;c2_internal[c1][c2],&lhs->_internal,&rhs->_internal[c1][c2]); }} return; } // Matrix left multiplies vector template accelerator_inline void mult(iVector * __restrict__ ret,const iMatrix * __restrict__ lhs,const iVector * __restrict__ rhs) { for(int c1=0;c1_internal[c1],&lhs->_internal[c1][0],&rhs->_internal[0]); for(int c2=1;c2_internal[c1],&lhs->_internal[c1][c2],&rhs->_internal[c2]); } } return; } template accelerator_inline void mult(iVector * __restrict__ ret, const iScalar * __restrict__ lhs, const iVector * __restrict__ rhs){ for(int c1=0;c1_internal[c1],&lhs->_internal,&rhs->_internal[c1]); } } template accelerator_inline void mult(iVector * __restrict__ ret, const iVector * __restrict__ rhs, const iScalar * __restrict__ lhs){ for(int c1=0;c1_internal[c1],&rhs->_internal[c1],&lhs->_internal); } } template accelerator_inline iVector operator * (const iMatrix& lhs,const iVector& rhs) { iVector ret; mult(&ret,&lhs,&rhs); return ret; } template accelerator_inline iVector operator * (const iScalar& lhs,const iVector& rhs) { iVector ret; mult(&ret,&lhs,&rhs); return ret; } template accelerator_inline iVector operator * (const iVector& lhs,const iScalar& rhs) { iVector ret; mult(&ret,&lhs,&rhs); return ret; } ////////////////////////////////////////////////////////////////// // Divide by scalar ////////////////////////////////////////////////////////////////// template accelerator_inline iScalar operator / (const iScalar& lhs,const iScalar& rhs) { iScalar ret; ret._internal = lhs._internal/rhs._internal; return ret; } template accelerator_inline iVector operator / (const iVector& lhs,const iScalar& rhs) { iVector ret; for(int i=0;i accelerator_inline iMatrix operator / (const iMatrix& lhs,const iScalar& rhs) { iMatrix ret; for(int i=0;i x matrix-> matrix // while matrix x matrix-> matrix // so return type depends on argument types in nasty way. ////////////////////////////////////////////////////////////////// // scal x scal = scal // mat x mat = mat // mat x scal = mat // scal x mat = mat // mat x vec = vec // vec x scal = vec // scal x vec = vec // // We can special case scalar_type ?? template accelerator_inline auto operator * (const iScalar& lhs,const iScalar& rhs) -> iScalar { typedef iScalar ret_t; ret_t ret; mult(&ret,&lhs,&rhs); return ret; } template accelerator_inline auto operator * (const iMatrix& lhs,const iMatrix& rhs) -> iMatrix { typedef decltype(lhs._internal[0][0]*rhs._internal[0][0]) ret_t; iMatrix ret; mult(&ret,&lhs,&rhs); return ret; } template accelerator_inline auto operator * (const iMatrix& lhs,const iScalar& rhs) -> iMatrix { typedef decltype(lhs._internal[0][0]*rhs._internal) ret_t; iMatrix ret; for(int c1=0;c1 accelerator_inline auto operator * (const iScalar& lhs,const iMatrix& rhs) -> iMatrix { typedef decltype(lhs._internal*rhs._internal[0][0]) ret_t; iMatrix ret; for(int c1=0;c1 accelerator_inline auto operator * (const iMatrix& lhs,const iVector& rhs) -> iVector { typedef decltype(lhs._internal[0][0]*rhs._internal[0]) ret_t; iVector ret; for(int c1=0;c1 accelerator_inline auto operator * (const iScalar& lhs,const iVector& rhs) -> iVector { typedef decltype(lhs._internal*rhs._internal[0]) ret_t; iVector ret; for(int c1=0;c1 accelerator_inline auto operator * (const iVector& lhs,const iScalar& rhs) -> iVector { typedef decltype(lhs._internal[0]*rhs._internal) ret_t; iVector ret; for(int c1=0;c1