Skip to content

Commit 2450f50

Browse files
author
andrei.papou
committed
Fixed existing tests
1 parent fe4365c commit 2450f50

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/arrayformat.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ impl ArrayDisplayMode {
3636
where S: Data<Elem=A>,
3737
D: Dimension
3838
{
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+
};
4045

4146
let mut overflow_axis_pair: (Option<usize>, Option<usize>) = (None, None);
4247
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>,
8590
let display_mode = ArrayDisplayMode::from_array(view, limit);
8691

8792
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 };
8994

9095
// None will be an empty iter.
9196
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>,
169174

170175
if print_row {
171176
let mut print_elt = true;
172-
let nth_idx_val = index.slice().iter().last().unwrap();
177+
let nth_idx_op = index.slice().iter().last();
173178
match display_mode {
174179
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) {
176182
print_elt = false;
177183
if !printed_ellipses_v {
178184
write!(f, ", ...")?;

0 commit comments

Comments
 (0)