Skip to content

Commit 59eadb5

Browse files
committed
zip_mut_with_same_shape also accept 'f' layout
1 parent 1a93b2c commit 59eadb5

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/impl_methods.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use std::cmp;
109
use std::ptr as std_ptr;
1110
use std::slice;
1211

@@ -1917,18 +1916,20 @@ where
19171916
F: FnMut(&mut A, &B),
19181917
{
19191918
debug_assert_eq!(self.shape(), rhs.shape());
1920-
if let Some(self_s) = self.as_slice_mut() {
1921-
if let Some(rhs_s) = rhs.as_slice() {
1922-
let len = cmp::min(self_s.len(), rhs_s.len());
1923-
let s = &mut self_s[..len];
1924-
let r = &rhs_s[..len];
1925-
for i in 0..len {
1926-
f(&mut s[i], &r[i]);
1919+
1920+
// Same shape and order should have same strides
1921+
if self.strides() == rhs.strides() {
1922+
if let Some(self_s) = self.as_slice_memory_order_mut() {
1923+
if let Some(rhs_s) = rhs.as_slice_memory_order() {
1924+
for (s, r) in self_s.iter_mut().zip(rhs_s) {
1925+
f(s, &r);
1926+
}
1927+
return;
19271928
}
1928-
return;
19291929
}
19301930
}
1931-
// otherwise, fall back to the outer iter
1931+
1932+
// Otherwise, fall back to the outer iter
19321933
self.zip_mut_with_by_rows(rhs, f);
19331934
}
19341935

0 commit comments

Comments
 (0)