#ifndef GRID_MATH_ARITH_SUB_H #define GRID_MATH_ARITH_SUB_H namespace Grid { /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////// SUB /////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// // SUB is simple for now; cannot mix types and straightforward template // Scalar +/- Scalar // Vector +/- Vector // Matrix +/- Matrix // Matrix /- scalar template inline void sub(iScalar * __restrict__ ret, const iScalar * __restrict__ lhs, const iScalar * __restrict__ rhs) { sub(&ret->_internal,&lhs->_internal,&rhs->_internal); } template inline void sub(iVector * __restrict__ ret, const iVector * __restrict__ lhs, const iVector * __restrict__ rhs) { for(int c=0;c_internal[c]=lhs->_internal[c]-rhs->_internal[c]; } return; } template inline void sub(iMatrix * __restrict__ ret, const iMatrix * __restrict__ lhs, const iMatrix * __restrict__ rhs){ for(int c2=0;c2_internal[c1][c2],&lhs->_internal[c1][c2],&rhs->_internal[c1][c2]); }} return; } template inline void sub(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]); } else { // Fails -- need unary minus. Catalogue other unops? ret->_internal[c1][c2]=zero; ret->_internal[c1][c2]=ret->_internal[c1][c2]-rhs->_internal[c1][c2]; } }} return; } template inline void sub(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); else ret->_internal[c1][c2]=lhs->_internal[c1][c2]; }} return; } // - operator for scalar, vector, matrix template inline auto operator - (const iScalar& lhs, const iScalar& rhs) -> iScalar { typedef iScalar ret_t; ret_t ret; sub(&ret,&lhs,&rhs); return ret; } template inline auto operator - (const iVector& lhs,const iVector& rhs) ->iVector { typedef iVector ret_t; ret_t ret; sub(&ret,&lhs,&rhs); return ret; } template inline auto operator - (const iMatrix& lhs,const iMatrix& rhs) ->iMatrix { typedef iMatrix ret_t; ret_t ret; sub(&ret,&lhs,&rhs); return ret; } template inline auto operator - (const iScalar& lhs,const iMatrix& rhs)->iMatrix { typedef iMatrix ret_t; ret_t ret; sub(&ret,&lhs,&rhs); return ret; } template inline auto operator - (const iMatrix& lhs,const iScalar& rhs)->iMatrix { typedef iMatrix ret_t; ret_t ret; sub(&ret,&lhs,&rhs); return ret; } } #endif