File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments