@@ -65,6 +65,7 @@ fn format_array<A, S, D, F>(
65
65
f : & mut fmt:: Formatter < ' _ > ,
66
66
mut format : F ,
67
67
limit : Ix ,
68
+ depth : usize ,
68
69
) -> fmt:: Result
69
70
where
70
71
F : FnMut ( & A , & mut fmt:: Formatter < ' _ > ) -> fmt:: Result + Clone ,
@@ -98,19 +99,31 @@ where
98
99
99
100
let n_to_be_printed = to_be_printed. len ( ) ;
100
101
102
+ let indent = " " . repeat ( depth + 1 ) ;
103
+
101
104
write ! ( f, "[" ) ?;
102
105
for ( j, index) in to_be_printed. into_iter ( ) . enumerate ( ) {
103
106
match index {
104
107
PrintableCell :: ElementIndex ( i) => {
108
+ // Indent all but the first line.
109
+ if j != 0 {
110
+ write ! ( f, "{}" , indent) ?;
111
+ }
105
112
// Proceed recursively with the (n-1)-dimensional slice
106
- format_array ( & view. index_axis ( Axis ( 0 ) , i) , f, format. clone ( ) , limit) ?;
113
+ format_array (
114
+ & view. index_axis ( Axis ( 0 ) , i) ,
115
+ f,
116
+ format. clone ( ) ,
117
+ limit,
118
+ depth + 1 ,
119
+ ) ?;
107
120
// We need to add a separator after each slice,
108
121
// apart from the last one
109
122
if j != n_to_be_printed - 1 {
110
- write ! ( f, ",\n " ) ?
123
+ write ! ( f, ",\n " ) ?
111
124
}
112
125
}
113
- PrintableCell :: Ellipses => write ! ( f, "...,\n " ) ?,
126
+ PrintableCell :: Ellipses => write ! ( f, "{} ...,\n " , indent ) ?,
114
127
}
115
128
}
116
129
write ! ( f, "]" ) ?;
@@ -129,7 +142,7 @@ where
129
142
S : Data < Elem = A > ,
130
143
{
131
144
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
132
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
145
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
133
146
}
134
147
}
135
148
@@ -143,7 +156,7 @@ where
143
156
{
144
157
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
145
158
// Add extra information for Debug
146
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT ) ?;
159
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 ) ?;
147
160
write ! (
148
161
f,
149
162
" shape={:?}, strides={:?}, layout={:?}" ,
@@ -168,7 +181,7 @@ where
168
181
S : Data < Elem = A > ,
169
182
{
170
183
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
171
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
184
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
172
185
}
173
186
}
174
187
@@ -181,7 +194,7 @@ where
181
194
S : Data < Elem = A > ,
182
195
{
183
196
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
184
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
197
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
185
198
}
186
199
}
187
200
/// Format the array using `LowerHex` and apply the formatting parameters used
@@ -193,7 +206,7 @@ where
193
206
S : Data < Elem = A > ,
194
207
{
195
208
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
196
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
209
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
197
210
}
198
211
}
199
212
@@ -206,7 +219,7 @@ where
206
219
S : Data < Elem = A > ,
207
220
{
208
221
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
209
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
222
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
210
223
}
211
224
}
212
225
0 commit comments