@@ -7,19 +7,22 @@ use crate::imp_prelude::*;
7
7
macro_rules! boolean_op {
8
8
( $( $( #[ $meta1: meta] ) * fn $id1: ident $( #[ $meta2: meta] ) * fn $id2: ident -> $func: ident) +) => {
9
9
$( $( #[ $meta1] ) *
10
+ #[ must_use = "method returns a new array and does not mutate the original value" ]
10
11
pub fn $id1( & self ) -> Array <bool , D > {
11
12
self . mapv( A :: $func)
12
13
}
13
14
$( #[ $meta2] ) *
15
+ #[ must_use = "method returns a new boolean value and does not mutate the original value" ]
14
16
pub fn $id2( & self ) -> bool {
15
- self . mapv( A :: $func) . iter( ) . any( |& b|b)
17
+ self . mapv( A :: $func) . iter( ) . any( |& b| b)
16
18
} ) +
17
19
} ;
18
20
}
19
21
20
22
macro_rules! unary_op {
21
23
( $( $( #[ $meta: meta] ) * fn $id: ident) +) => {
22
24
$( $( #[ $meta] ) *
25
+ #[ must_use = "method returns a new array and does not mutate the original value" ]
23
26
pub fn $id( & self ) -> Array <A , D > {
24
27
self . mapv( A :: $id)
25
28
} ) +
@@ -29,6 +32,7 @@ macro_rules! unary_op {
29
32
macro_rules! binary_op {
30
33
( $( $( #[ $meta: meta] ) * fn $id: ident( $ty: ty) ) +) => {
31
34
$( $( #[ $meta] ) *
35
+ #[ must_use = "method returns a new array and does not mutate the original value" ]
32
36
pub fn $id( & self , rhs: $ty) -> Array <A , D > {
33
37
self . mapv( |v| A :: $id( v, rhs) )
34
38
} ) +
@@ -41,19 +45,19 @@ macro_rules! binary_op {
41
45
impl < A , S , D > ArrayBase < S , D >
42
46
where
43
47
A : Float ,
44
- S : RawData < Elem = A > + Data ,
48
+ S : Data < Elem = A > ,
45
49
D : Dimension ,
46
50
{
47
51
boolean_op ! {
48
52
/// If the number is `NaN` (not a number), then `true` is returned for each element.
49
53
fn is_nan
50
54
/// Return `true` if any element is `NaN` (not a number).
51
- fn is_nan_any -> is_nan
55
+ fn is_any_nan -> is_nan
52
56
53
57
/// If the number is infinity, then `true` is returned for each element.
54
58
fn is_infinite
55
59
/// Return `true` if any element is infinity.
56
- fn is_infinite_any -> is_infinite
60
+ fn is_any_infinite -> is_infinite
57
61
}
58
62
unary_op ! {
59
63
/// The largest integer less than or equal to each element.
87
91
/// Square root of each element.
88
92
fn sqrt
89
93
90
- /// `e^x` of each element. (Exponential function)
94
+ /// `e^x` of each element (exponential function).
91
95
fn exp
92
96
93
97
/// `2^x` of each element.
@@ -105,13 +109,13 @@ where
105
109
/// Cubic root of each element.
106
110
fn cbrt
107
111
108
- /// Sine of each element. (in radians)
112
+ /// Sine of each element (in radians).
109
113
fn sin
110
114
111
- /// Cosine of each element. (in radians)
115
+ /// Cosine of each element (in radians).
112
116
fn cos
113
117
114
- /// Tangent of each element. (in radians)
118
+ /// Tangent of each element (in radians).
115
119
fn tan
116
120
117
121
/// Converts radians to degrees for each element.
@@ -136,9 +140,10 @@ where
136
140
fn abs_sub( A )
137
141
}
138
142
139
- /// Square of each element.
140
- pub fn square ( & self ) -> Array < A , D > {
141
- self . mapv ( |v| v * v)
143
+ /// Square (two powers) of each element.
144
+ #[ must_use = "method returns a new array and does not mutate the original value" ]
145
+ pub fn pow2 ( & self ) -> Array < A , D > {
146
+ self . mapv ( |v : A | v * v)
142
147
}
143
148
144
149
/// Limit the values for each element.
0 commit comments