@@ -70,7 +70,9 @@ fn format_array<A, S, D, F>(
70
70
view : & ArrayBase < S , D > ,
71
71
f : & mut fmt:: Formatter ,
72
72
mut format : F ,
73
- limit : Ix ) -> fmt:: Result
73
+ limit : Ix ,
74
+ depth : usize ,
75
+ ) -> fmt:: Result
74
76
where
75
77
F : FnMut ( & A , & mut fmt:: Formatter ) -> fmt:: Result + Clone ,
76
78
D : Dimension ,
@@ -98,21 +100,27 @@ where
98
100
99
101
let n_to_be_printed = to_be_printed. len ( ) ;
100
102
103
+ let indent = " " . repeat ( depth + 1 ) ;
104
+
101
105
write ! ( f, "[" ) ?;
102
106
for ( j, index) in to_be_printed. into_iter ( ) . enumerate ( ) {
103
107
match index {
104
108
PrintableCell :: ElementIndex ( i) => {
109
+ // Indent all but the first line.
110
+ if j != 0 {
111
+ write ! ( f, "{}" , indent) ?;
112
+ }
105
113
// Proceed recursively with the (n-1)-dimensional slice
106
114
format_array (
107
- & view. index_axis ( Axis ( 0 ) , i) , f, format. clone ( ) , limit
115
+ & view. index_axis ( Axis ( 0 ) , i) , f, format. clone ( ) , limit, depth + 1
108
116
) ?;
109
117
// We need to add a separator after each slice,
110
118
// apart from the last one
111
119
if j != n_to_be_printed - 1 {
112
- write ! ( f, ",\n " ) ?
120
+ write ! ( f, ",\n " ) ?
113
121
}
114
122
} ,
115
- PrintableCell :: Ellipses => write ! ( f, "...,\n " ) ?
123
+ PrintableCell :: Ellipses => write ! ( f, "{} ...,\n " , indent ) ? ,
116
124
}
117
125
}
118
126
write ! ( f, "]" ) ?;
@@ -130,7 +138,7 @@ impl<'a, A: fmt::Display, S, D: Dimension> fmt::Display for ArrayBase<S, D>
130
138
where S : Data < Elem =A > ,
131
139
{
132
140
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
133
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
141
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
134
142
}
135
143
}
136
144
@@ -143,7 +151,7 @@ impl<'a, A: fmt::Debug, S, D: Dimension> fmt::Debug for ArrayBase<S, D>
143
151
{
144
152
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
145
153
// Add extra information for Debug
146
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT ) ?;
154
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 ) ?;
147
155
write ! ( f, " shape={:?}, strides={:?}, layout={:?}" ,
148
156
self . shape( ) , self . strides( ) , layout=self . view( ) . layout( ) ) ?;
149
157
match D :: NDIM {
@@ -162,7 +170,7 @@ impl<'a, A: fmt::LowerExp, S, D: Dimension> fmt::LowerExp for ArrayBase<S, D>
162
170
where S : Data < Elem =A > ,
163
171
{
164
172
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
165
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
173
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
166
174
}
167
175
}
168
176
@@ -174,7 +182,7 @@ impl<'a, A: fmt::UpperExp, S, D: Dimension> fmt::UpperExp for ArrayBase<S, D>
174
182
where S : Data < Elem =A > ,
175
183
{
176
184
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
177
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
185
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
178
186
}
179
187
}
180
188
/// Format the array using `LowerHex` and apply the formatting parameters used
@@ -185,7 +193,7 @@ impl<'a, A: fmt::LowerHex, S, D: Dimension> fmt::LowerHex for ArrayBase<S, D>
185
193
where S : Data < Elem =A > ,
186
194
{
187
195
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
188
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
196
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
189
197
}
190
198
}
191
199
@@ -197,7 +205,7 @@ impl<'a, A: fmt::Binary, S, D: Dimension> fmt::Binary for ArrayBase<S, D>
197
205
where S : Data < Elem =A > ,
198
206
{
199
207
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
200
- format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT )
208
+ format_array ( self , f, <_ >:: fmt, PRINT_ELEMENTS_LIMIT , 0 )
201
209
}
202
210
}
203
211
0 commit comments