Skip to content

Commit da115c9

Browse files
authored
Fix partition on empty arrays (#1502)
Closes #1501
1 parent 2324d2a commit da115c9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/impl_methods.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3229,16 +3229,22 @@ impl<A, D: Dimension> ArrayRef<A, D>
32293229

32303230
let mut result = self.to_owned();
32313231

3232+
// Must guarantee that the array isn't empty before checking for contiguity
3233+
if result.shape().iter().any(|s| *s == 0) {
3234+
return result;
3235+
}
3236+
32323237
// Check if the first lane is contiguous
32333238
let is_contiguous = result
32343239
.lanes_mut(axis)
32353240
.into_iter()
32363241
.next()
3242+
// This unwrap shouldn't cause panics because the array isn't empty
32373243
.unwrap()
32383244
.is_contiguous();
32393245

32403246
if is_contiguous {
3241-
Zip::from(result.lanes_mut(axis)).for_each(|mut lane| {
3247+
result.lanes_mut(axis).into_iter().for_each(|mut lane| {
32423248
lane.as_slice_mut().unwrap().select_nth_unstable(kth);
32433249
});
32443250
} else {

0 commit comments

Comments
 (0)