1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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"))]
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"))]
pub fn inot(&mut self)
where A: Clone + Not<Output=A>,
{
self.unordered_foreach_mut(|elt| {
*elt = !elt.clone();
});
}
}