/*************************************************************************** * blitz/array/ops.cc Basic operators for arrays. * * $Id$ * * Copyright (C) 1997-2011 Todd Veldhuizen * * This file is a part of Blitz. * * Blitz is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Blitz 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with Blitz. If not, see . * * Suggestions: blitz-devel@lists.sourceforge.net * Bugs: blitz-support@lists.sourceforge.net * * For more information, please see the Blitz++ Home Page: * https://sourceforge.net/projects/blitz/ * ****************************************************************************/ #ifndef BZ_ARRAYOPS_CC #define BZ_ARRAYOPS_CC #ifndef BZ_ARRAY_H #error must be included via #endif #include #include BZ_NAMESPACE(blitz) /* * Constant operands */ template _bz_forceinline Array& Array::initialize(T_numtype x) { // we can't use asExpr here, because if we are initializing an array // whose components are also ETBase, it would parse as an array // expression, not as an initialization with a scalar. (*this) = _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } #ifdef BZ_NEW_EXPRESSION_TEMPLATES // need to do operator= separately from the generic templates below so // that operator=(T_numtype) will be the best match for list // initializations. template template _bz_forceinline Array& Array::operator=(const ETBase& expr) { _bz_evaluate(*this, _bz_typename asExpr::T_expr(expr.unwrap()), _bz_update::T_expr::T_result>()); return *this; } // do NOT remove this operator. it won't work without it, trust me... template _bz_forceinline Array& Array::operator=(const Array& x) { typedef typename asExpr >::T_expr T_expr; _bz_evaluate(*this, asExpr >::getExpr(x), _bz_update()); return *this; } #define BZ_ARRAY_UPDATE(op,name) \ template \ template \ _bz_forceinline \ Array& \ Array::operator op(const ETBase& expr) \ { \ _bz_evaluate(*this, _bz_typename asExpr::T_expr(expr.unwrap()), \ name::T_expr::T_result>()); \ return *this; \ } \ template \ _bz_forceinline \ Array& \ Array::operator op(const Array& x) \ { \ typedef typename asExpr >::T_expr T_expr; \ _bz_evaluate(*this, asExpr >::getExpr(x), \ name()); \ return *this; \ } \ template \ _bz_forceinline \ Array& \ Array::operator op(const T_numtype& x) \ { \ typedef typename asExpr::T_expr T_expr; \ _bz_evaluate(*this, asExpr::getExpr(x), \ name()); \ return *this; \ } BZ_ARRAY_UPDATE(+=, _bz_plus_update) BZ_ARRAY_UPDATE(-=, _bz_minus_update) BZ_ARRAY_UPDATE(*=, _bz_multiply_update) BZ_ARRAY_UPDATE(/=, _bz_divide_update) BZ_ARRAY_UPDATE(%=, _bz_mod_update) BZ_ARRAY_UPDATE(^=, _bz_xor_update) BZ_ARRAY_UPDATE(&=, _bz_bitand_update) BZ_ARRAY_UPDATE(|=, _bz_bitor_update) BZ_ARRAY_UPDATE(<<=, _bz_shiftl_update) BZ_ARRAY_UPDATE(>>=, _bz_shiftr_update) #else template inline Array& Array::operator+=(T_numtype x) { (*this) += _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator-=(T_numtype x) { (*this) -= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator*=(T_numtype x) { (*this) *= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator/=(T_numtype x) { (*this) /= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator%=(T_numtype x) { (*this) %= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator^=(T_numtype x) { (*this) ^= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator&=(T_numtype x) { (*this) &= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator|=(T_numtype x) { (*this) |= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator>>=(T_numtype x) { (*this) <<= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } template inline Array& Array::operator<<=(T_numtype x) { (*this) <<= _bz_ArrayExpr<_bz_ArrayExprConstant >(x); return *this; } /* * Array operands */ template inline Array& Array::operator=(const Array& x) { (*this) = _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator=(const Array& x) { (*this) = _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator+=(const Array& x) { (*this) += _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator-=(const Array& x) { (*this) -= _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator*=(const Array& x) { (*this) *= _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator/=(const Array& x) { (*this) /= _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator%=(const Array& x) { (*this) %= _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator^=(const Array& x) { (*this) ^= _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator&=(const Array& x) { (*this) &= _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator|=(const Array& x) { (*this) |= _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator>>=(const Array& x) { (*this) >>= _bz_ArrayExpr >(x.beginFast()); return *this; } template template inline Array& Array::operator<<=(const Array& x) { (*this) <<= _bz_ArrayExpr >(x.beginFast()); return *this; } /* * Array expression operands */ template template inline Array& Array::operator=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_update()); return *this; } template template inline Array& Array::operator+=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_plus_update()); return *this; } template template inline Array& Array::operator-=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_minus_update()); return *this; } template template inline Array& Array::operator*=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_multiply_update()); return *this; } template template inline Array& Array::operator/=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_divide_update()); return *this; } template template inline Array& Array::operator%=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_mod_update()); return *this; } template template inline Array& Array::operator^=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_xor_update()); return *this; } template template inline Array& Array::operator&=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_bitand_update()); return *this; } template template inline Array& Array::operator|=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_bitor_update()); return *this; } template template inline Array& Array::operator>>=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_shiftr_update()); return *this; } template template inline Array& Array::operator<<=(BZ_ETPARM(_bz_ArrayExpr) expr) { evaluate(expr, _bz_shiftl_update()); return *this; } #endif // BZ_NEW_EXPRESSION_TEMPLATES BZ_NAMESPACE_END #endif // BZ_ARRAYOPS_CC