21
21
if self . shape ( ) != other. shape ( ) {
22
22
return false ;
23
23
}
24
+
24
25
Zip :: from ( self )
25
26
. and ( other)
26
- . all ( |a, b| A :: abs_diff_eq ( a, b, epsilon. clone ( ) ) )
27
+ . all ( move |a, b| A :: abs_diff_eq ( a, b, epsilon. clone ( ) ) )
27
28
}
28
29
}
29
30
49
50
if self . shape ( ) != other. shape ( ) {
50
51
return false ;
51
52
}
53
+
52
54
Zip :: from ( self )
53
55
. and ( other)
54
- . all ( |a, b| A :: relative_eq ( a, b, epsilon. clone ( ) , max_relative. clone ( ) ) )
56
+ . all ( move |a, b| A :: relative_eq ( a, b, epsilon. clone ( ) , max_relative. clone ( ) ) )
55
57
}
56
58
}
57
59
@@ -72,12 +74,51 @@ where
72
74
if self . shape ( ) != other. shape ( ) {
73
75
return false ;
74
76
}
77
+
75
78
Zip :: from ( self )
76
79
. and ( other)
77
- . all ( |a, b| A :: ulps_eq ( a, b, epsilon. clone ( ) , max_ulps) )
80
+ . all ( move |a, b| A :: ulps_eq ( a, b, epsilon. clone ( ) , max_ulps) )
78
81
}
79
82
}
80
83
84
+ impl < A , S , D > ArrayBase < S , D >
85
+ where
86
+ S : Data < Elem = A > ,
87
+ D : Dimension ,
88
+ {
89
+ /// A test for equality that uses the elementwise absolute difference to compute the
90
+ /// approximate equality of two arrays.
91
+ ///
92
+ /// **Requires crate feature `"approx"`**
93
+ pub fn abs_diff_eq < S2 > ( & self , other : & ArrayBase < S2 , D > , epsilon : A :: Epsilon ) -> bool
94
+ where
95
+ A : AbsDiffEq < S2 :: Elem > ,
96
+ A :: Epsilon : Clone ,
97
+ S2 : Data ,
98
+ {
99
+ <Self as AbsDiffEq < _ > >:: abs_diff_eq ( self , other, epsilon)
100
+ }
101
+
102
+ /// A test for equality that uses an elementwise relative comparison if the values are far
103
+ /// apart; and the absolute difference otherwise.
104
+ ///
105
+ /// **Requires crate feature `"approx"`**
106
+ pub fn relative_eq < S2 > (
107
+ & self ,
108
+ other : & ArrayBase < S2 , D > ,
109
+ epsilon : A :: Epsilon ,
110
+ max_relative : A :: Epsilon ,
111
+ ) -> bool
112
+ where
113
+ A : RelativeEq < S2 :: Elem > ,
114
+ A :: Epsilon : Clone ,
115
+ S2 : Data
116
+ {
117
+ <Self as RelativeEq < _ > >:: relative_eq ( self , other, epsilon, max_relative)
118
+ }
119
+ }
120
+
121
+
81
122
#[ cfg( test) ]
82
123
mod tests {
83
124
use crate :: prelude:: * ;
0 commit comments