Skip to content

Commit 23efec0

Browse files
committed
comment/style expand
1 parent 45a295f commit 23efec0

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/impl_expand.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,24 @@ where
124124
{
125125
assert_eq!(mem::size_of::<A>(), mem::size_of::<T>() * A::LEN);
126126

127-
let mut strides = self.strides.insert_axis(new_axis);
128127
let mut dim = self.dim.insert_axis(new_axis);
128+
let mut strides = self.strides.insert_axis(new_axis);
129+
130+
// Double the strides. In the zero-sized element case and for axes of
131+
// length <= 1, we leave the strides as-is to avoid possible overflow.
129132
let len = A::LEN as isize;
130-
for ax in 0..strides.ndim() {
131-
if Axis(ax) == new_axis {
132-
continue;
133-
}
134-
if dim[ax] > 1 {
135-
strides[ax] = ((strides[ax] as isize) * len) as usize;
133+
if mem::size_of::<T>() != 0 {
134+
for ax in 0..strides.ndim() {
135+
if Axis(ax) == new_axis {
136+
continue;
137+
}
138+
if dim[ax] > 1 {
139+
strides[ax] = ((strides[ax] as isize) * len) as usize;
140+
}
136141
}
137142
}
138143
dim[new_axis.index()] = A::LEN;
144+
139145
// TODO nicer assertion
140146
crate::dimension::size_of_shape_checked(&dim).unwrap();
141147

0 commit comments

Comments
 (0)