From 55328567cd6e2d70a059077c1c5ce1ea949d7827 Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Wed, 9 Apr 2025 23:15:49 -0400 Subject: [PATCH] Fix partition on empty arrays Closes #1501 --- src/impl_methods.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 42d843781..ea9c9a0d5 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -3229,16 +3229,22 @@ impl ArrayRef let mut result = self.to_owned(); + // Must guarantee that the array isn't empty before checking for contiguity + if result.shape().iter().any(|s| *s == 0) { + return result; + } + // Check if the first lane is contiguous let is_contiguous = result .lanes_mut(axis) .into_iter() .next() + // This unwrap shouldn't cause panics because the array isn't empty .unwrap() .is_contiguous(); if is_contiguous { - Zip::from(result.lanes_mut(axis)).for_each(|mut lane| { + result.lanes_mut(axis).into_iter().for_each(|mut lane| { lane.as_slice_mut().unwrap().select_nth_unstable(kth); }); } else {