2121 if self . shape ( ) != other. shape ( ) {
2222 return false ;
2323 }
24+
2425 Zip :: from ( self )
2526 . 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 ( ) ) )
2728 }
2829}
2930
4950 if self . shape ( ) != other. shape ( ) {
5051 return false ;
5152 }
53+
5254 Zip :: from ( self )
5355 . 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 ( ) ) )
5557 }
5658}
5759
@@ -72,12 +74,51 @@ where
7274 if self . shape ( ) != other. shape ( ) {
7375 return false ;
7476 }
77+
7578 Zip :: from ( self )
7679 . 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) )
7881 }
7982}
8083
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+
81122#[ cfg( test) ]
82123mod tests {
83124 use crate :: prelude:: * ;
0 commit comments