Skip to content

Commit 087cf3c

Browse files
committed
Use Zip in all_close
1 parent beb4edb commit 087cf3c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/numeric/impl_numeric.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use numeric_util;
1515

1616
use {
1717
LinalgScalar,
18+
FoldWhile,
19+
Zip,
1820
};
1921

2022
/// Numerical methods for arrays.
@@ -124,8 +126,20 @@ impl<A, S, D> ArrayBase<S, D>
124126
S2: Data<Elem=A>,
125127
E: Dimension,
126128
{
127-
let rhs_broadcast = rhs.broadcast_unwrap(self.raw_dim());
128-
self.iter().zip(rhs_broadcast.iter()).all(|(x, y)| (*x - *y).abs() <= tol)
129+
let result =
130+
Zip::from(self)
131+
.and(rhs.broadcast_unwrap(self.raw_dim()))
132+
.fold_while((), |_, x, y| {
133+
if (*x - *y).abs() <= tol {
134+
FoldWhile::Continue(())
135+
} else {
136+
FoldWhile::Done(())
137+
}
138+
});
139+
match result {
140+
FoldWhile::Continue(_) => true,
141+
FoldWhile::Done(_) => false,
142+
}
129143
}
130144
}
131145

0 commit comments

Comments
 (0)