#ifndef GRID_MATH_ARITH_ADD_H #define GRID_MATH_ARITH_ADD_H namespace Grid { /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////// ADD /////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// // ADD is simple for now; cannot mix types and straightforward template // Scalar +/- Scalar // Vector +/- Vector // Matrix +/- Matrix template inline void add(iScalar * __restrict__ ret, const iScalar * __restrict__ lhs, const iScalar * __restrict__ rhs) { add(&ret->_internal,&lhs->_internal,&rhs->_internal); } template inline void add(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 add(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 add(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; } template inline void add(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 + (iScalar& lhs,iScalar&& rhs) -> iScalar inline auto operator + (const iScalar& lhs,const iScalar& rhs) -> iScalar { typedef iScalar ret_t; ret_t ret; add(&ret,&lhs,&rhs); return ret; } template inline auto operator + (const iVector& lhs,const iVector& rhs) ->iVector { typedef iVector ret_t; ret_t ret; add(&ret,&lhs,&rhs); return ret; } template inline auto operator + (const iMatrix& lhs,const iMatrix& rhs) ->iMatrix { typedef iMatrix ret_t; ret_t ret; add(&ret,&lhs,&rhs); return ret; } template inline auto operator + (const iScalar& lhs,const iMatrix& rhs)->iMatrix { typedef iMatrix ret_t; ret_t ret; add(&ret,&lhs,&rhs); return ret; } template inline auto operator + (const iMatrix& lhs,const iScalar& rhs)->iMatrix { typedef iMatrix ret_t; ret_t ret; add(&ret,&lhs,&rhs); return ret; } } #endif