Skip to content

Commit 8dde517

Browse files
apply Zip instead of naive for loop
1 parent 0a3b95f commit 8dde517

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/numeric/impl_numeric.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,12 @@ where
139139
let mut res = Array::ones(self.raw_dim());
140140
let mut acc = Array::ones(self.raw_dim().remove_axis(axis));
141141

142-
// Use fold_axis approach
143-
for i in 0..self.len_of(axis) {
144-
// Get view of current slice along axis, and update accumulator element-wise multiplication
145-
let view = self.index_axis(axis, i);
146-
acc = acc * &view;
147-
res.index_axis_mut(axis, i).assign(&acc);
148-
}
142+
Zip::from(self.axis_iter(axis))
143+
.and(res.axis_iter_mut(axis))
144+
.for_each(|view, mut res| {
145+
acc = acc.clone() * &view;
146+
res.assign(&acc);
147+
});
149148

150149
res
151150
}

0 commit comments

Comments
 (0)