Skip to content

Commit c071473

Browse files
committed
Allow zero strides on empty arrays
1 parent bd3ade9 commit c071473

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/dimension/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ pub fn stride_offset(n: Ix, stride: Ix) -> isize
5757
/// possible offset along the preceding axes. (Axes of length ≤1 are ignored.)
5858
pub(crate) fn dim_stride_overlap<D: Dimension>(dim: &D, strides: &D) -> bool
5959
{
60+
if dim.slice().contains(&0) {
61+
return false;
62+
}
63+
6064
let order = strides._fastest_varying_stride_order();
6165
let mut sum_prev_offsets = 0;
6266
for &index in order.slice() {

tests/array.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,14 @@ fn test_view_from_shape_ptr()
22412241
assert_eq!(view, aview2(&[[0, 0, 2], [3, 4, 6]]));
22422242
}
22432243

2244+
#[test]
2245+
fn test_view_mut_from_shape_ptr_empty_zero_strides()
2246+
{
2247+
let ptr = std::ptr::dangling_mut::<f64>();
2248+
let view = unsafe { ArrayViewMut2::from_shape_ptr((2, 0).strides((0, 0)), ptr) };
2249+
assert_eq!(view.shape(), &[2, 0]);
2250+
}
2251+
22442252
#[should_panic(expected = "Unsupported")]
22452253
#[cfg(debug_assertions)]
22462254
#[test]

0 commit comments

Comments
 (0)