@@ -2102,13 +2102,18 @@ where
21022102 {
21032103 let view_len = self . len_of ( axis) ;
21042104 let view_stride = self . strides . axis ( axis) ;
2105- // use the 0th subview as a map to each 1d array view extended from
2106- // the 0th element.
2107- self . index_axis ( axis, 0 ) . map ( |first_elt| {
2108- unsafe {
2109- mapping ( ArrayView :: new_ ( first_elt, Ix1 ( view_len) , Ix1 ( view_stride) ) )
2110- }
2111- } )
2105+ if view_len == 0 {
2106+ let new_dim = self . dim . remove_axis ( axis) ;
2107+ Array :: from_shape_fn ( new_dim, move |_| mapping ( ArrayView :: from ( & [ ] ) ) )
2108+ } else {
2109+ // use the 0th subview as a map to each 1d array view extended from
2110+ // the 0th element.
2111+ self . index_axis ( axis, 0 ) . map ( |first_elt| {
2112+ unsafe {
2113+ mapping ( ArrayView :: new_ ( first_elt, Ix1 ( view_len) , Ix1 ( view_stride) ) )
2114+ }
2115+ } )
2116+ }
21122117 }
21132118
21142119 /// Reduce the values along an axis into just one value, producing a new
@@ -2130,12 +2135,17 @@ where
21302135 {
21312136 let view_len = self . len_of ( axis) ;
21322137 let view_stride = self . strides . axis ( axis) ;
2133- // use the 0th subview as a map to each 1d array view extended from
2134- // the 0th element.
2135- self . index_axis_mut ( axis, 0 ) . map_mut ( |first_elt : & mut A | {
2136- unsafe {
2137- mapping ( ArrayViewMut :: new_ ( first_elt, Ix1 ( view_len) , Ix1 ( view_stride) ) )
2138- }
2139- } )
2138+ if view_len == 0 {
2139+ let new_dim = self . dim . remove_axis ( axis) ;
2140+ Array :: from_shape_fn ( new_dim, move |_| mapping ( ArrayViewMut :: from ( & mut [ ] ) ) )
2141+ } else {
2142+ // use the 0th subview as a map to each 1d array view extended from
2143+ // the 0th element.
2144+ self . index_axis_mut ( axis, 0 ) . map_mut ( |first_elt| {
2145+ unsafe {
2146+ mapping ( ArrayViewMut :: new_ ( first_elt, Ix1 ( view_len) , Ix1 ( view_stride) ) )
2147+ }
2148+ } )
2149+ }
21402150 }
21412151}
0 commit comments