use std::ops::{
Add, Sub, Mul, Div, Rem, Neg, Not, Shr, Shl,
BitAnd,
BitOr,
BitXor,
};
use imp_prelude::*;
macro_rules! as_expr(
($e:expr) => ($e)
);
macro_rules! impl_binary_op_inplace(
($trt:ident, $operator:tt, $mth:ident, $imethod:ident, $imth_scalar:ident, $doc:expr) => (
#[cfg_attr(has_deprecated, deprecated(note="Use augmented assignment operator instead"))]
#[doc=$doc]
pub fn $imethod <E: Dimension, S2> (&mut self, rhs: &ArrayBase<S2, E>)
where A: Clone + $trt<A, Output=A>,
S2: Data<Elem=A>,
{
self.zip_mut_with(rhs, |x, y| {
*x = as_expr!(x.clone() $operator y.clone());
});
}
#[cfg_attr(has_deprecated, deprecated(note="Use augmented assignment operator instead"))]
#[doc=$doc]
pub fn $imth_scalar (&mut self, x: &A)
where A: Clone + $trt<A, Output=A>,
{
self.unordered_foreach_mut(move |elt| {
*elt = as_expr!(elt.clone() $operator x.clone());
});
}
);
);
impl<A, S, D> ArrayBase<S, D>
where S: DataMut<Elem=A>,
D: Dimension,
{
impl_binary_op_inplace!(Add, +, add, iadd, iadd_scalar, "addition");
impl_binary_op_inplace!(Sub, -, sub, isub, isub_scalar, "subtraction");
impl_binary_op_inplace!(Mul, *, mul, imul, imul_scalar, "multiplication");
impl_binary_op_inplace!(Div, /, div, idiv, idiv_scalar, "division");
impl_binary_op_inplace!(Rem, %, rem, irem, irem_scalar, "remainder");
impl_binary_op_inplace!(BitAnd, &, bitand, ibitand, ibitand_scalar, "bit and");
impl_binary_op_inplace!(BitOr, |, bitor, ibitor, ibitor_scalar, "bit or");
impl_binary_op_inplace!(BitXor, ^, bitxor, ibitxor, ibitxor_scalar, "bit xor");
impl_binary_op_inplace!(Shl, <<, shl, ishl, ishl_scalar, "left shift");
impl_binary_op_inplace!(Shr, >>, shr, ishr, ishr_scalar, "right shift");
#[cfg_attr(has_deprecated, deprecated(note="Use augmented assignment operator instead"))]
/// Perform an elementwise negation of `self`, *in place*.
pub fn ineg(&mut self)
where A: Clone + Neg<Output=A>,
{
self.unordered_foreach_mut(|elt| {
*elt = -elt.clone();
});
}
#[cfg_attr(has_deprecated, deprecated(note="Use augmented assignment operator instead"))]
/// Perform an elementwise unary not of `self`, *in place*.
pub fn inot(&mut self)
where A: Clone + Not<Output=A>,
{
self.unordered_foreach_mut(|elt| {
*elt = !elt.clone();
});
}
}