#ifndef GRID_MATH_ARITH_MUL_H #define GRID_MATH_ARITH_MUL_H namespace Grid { /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////// MUL /////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// template strong_inline void mult(iScalar * __restrict__ ret,const iScalar * __restrict__ lhs,const iScalar * __restrict__ rhs){ mult(&ret->_internal,&lhs->_internal,&rhs->_internal); } template strong_inline void mult(iMatrix * __restrict__ ret,const iMatrix * __restrict__ lhs,const iMatrix * __restrict__ rhs){ for(int c2=0;c2_internal[c1][c2],&lhs->_internal[c1][0],&rhs->_internal[0][c2]); for(int c3=1;c3_internal[c1][c2],&lhs->_internal[c1][c3],&rhs->_internal[c3][c2]); } }} return; } template strong_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 strong_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 strong_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 strong_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 strong_inline void mult(iVector * __restrict__ ret, const iVector * __restrict__ rhs, const iScalar * __restrict__ lhs){ mult(ret,lhs,rhs); } template strong_inline iVector operator * (const iMatrix& lhs,const iVector& rhs) { iVector ret; mult(&ret,&lhs,&rhs); return ret; } template strong_inline iVector operator * (const iScalar& lhs,const iVector& rhs) { iVector ret; mult(&ret,&lhs,&rhs); return ret; } template strong_inline iVector operator * (const iVector& lhs,const iScalar& rhs) { iVector ret; mult(&ret,&lhs,&rhs); return ret; } ////////////////////////////////////////////////////////////////// // Glue operators to mult routines. Must resolve return type cleverly from typeof(internal) // since nesting matrix 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 strong_inline auto operator * (const iScalar& lhs,const iScalar& rhs) -> iScalar { typedef iScalar ret_t; ret_t ret; mult(&ret,&lhs,&rhs); return ret; } template strong_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 strong_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 strong_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 strong_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 strong_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 strong_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