@@ -36,7 +36,12 @@ impl ArrayDisplayMode {
36
36
where S : Data < Elem =A > ,
37
37
D : Dimension
38
38
{
39
- let last_dim = arr. shape ( ) . len ( ) - 1 ;
39
+ let last_dim = match arr. shape ( ) . len ( ) . checked_sub ( 1 ) {
40
+ Some ( v) => v,
41
+ None => {
42
+ return ArrayDisplayMode :: Full ;
43
+ }
44
+ } ;
40
45
41
46
let mut overflow_axis_pair: ( Option < usize > , Option < usize > ) = ( None , None ) ;
42
47
for ( axis, axis_size) in arr. shape ( ) . iter ( ) . enumerate ( ) . rev ( ) {
@@ -85,7 +90,7 @@ fn format_array_v2<A, S, D, F>(view: &ArrayBase<S, D>,
85
90
let display_mode = ArrayDisplayMode :: from_array ( view, limit) ;
86
91
87
92
let ndim = view. dim ( ) . into_dimension ( ) . slice ( ) . len ( ) ;
88
- let nth_idx_max = view. shape ( ) . iter ( ) . last ( ) . unwrap ( ) ;
93
+ let nth_idx_max = if ndim > 0 { Some ( view. shape ( ) . iter ( ) . last ( ) . unwrap ( ) ) } else { None } ;
89
94
90
95
// None will be an empty iter.
91
96
let mut last_index = match view. dim ( ) . into_dimension ( ) . first_index ( ) {
@@ -169,10 +174,11 @@ fn format_array_v2<A, S, D, F>(view: &ArrayBase<S, D>,
169
174
170
175
if print_row {
171
176
let mut print_elt = true ;
172
- let nth_idx_val = index. slice ( ) . iter ( ) . last ( ) . unwrap ( ) ;
177
+ let nth_idx_op = index. slice ( ) . iter ( ) . last ( ) ;
173
178
match display_mode {
174
179
ArrayDisplayMode :: VSplit | ArrayDisplayMode :: DoubleSplit ( _) => {
175
- if nth_idx_val >= & limit && nth_idx_val < & ( nth_idx_max - & limit) {
180
+ let nth_idx_val = nth_idx_op. unwrap ( ) ;
181
+ if nth_idx_val >= & limit && nth_idx_val < & ( nth_idx_max. unwrap ( ) - & limit) {
176
182
print_elt = false ;
177
183
if !printed_ellipses_v {
178
184
write ! ( f, ", ..." ) ?;
0 commit comments