@@ -9,12 +9,22 @@ use super::{ArrayBase, Axis, Data, Dimension, Ix, NdProducer};
9
9
use crate :: aliases:: Ix1 ;
10
10
use std:: fmt;
11
11
12
- /// Maximum axis length before overflowing with an ellipsis.
12
+ /// Default maximum axis length before overflowing with an ellipsis.
13
13
const AXIS_LEN_LIMIT : Ix = 6 ;
14
14
15
15
/// The string used as an ellipsis.
16
16
const ELLIPSIS : & str = "..." ;
17
17
18
+ /// Returns the axis length limit based on whether or not the alternate (`#`)
19
+ /// flag was specified on the formatter.
20
+ fn axis_len_limit ( f : & mut fmt:: Formatter < ' _ > ) -> usize {
21
+ if f. alternate ( ) {
22
+ std:: usize:: MAX
23
+ } else {
24
+ AXIS_LEN_LIMIT
25
+ }
26
+ }
27
+
18
28
/// Formats the contents of a list of items, using an ellipsis to indicate when
19
29
/// the `length` of the list is greater than `limit`.
20
30
///
@@ -129,7 +139,8 @@ where
129
139
S : Data < Elem = A > ,
130
140
{
131
141
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
132
- format_array ( self , f, <_ >:: fmt, AXIS_LEN_LIMIT , 0 )
142
+ let limit = axis_len_limit ( f) ;
143
+ format_array ( self , f, <_ >:: fmt, limit, 0 )
133
144
}
134
145
}
135
146
@@ -142,8 +153,10 @@ where
142
153
S : Data < Elem = A > ,
143
154
{
144
155
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
156
+ let limit = axis_len_limit ( f) ;
157
+ format_array ( self , f, <_ >:: fmt, limit, 0 ) ?;
158
+
145
159
// Add extra information for Debug
146
- format_array ( self , f, <_ >:: fmt, AXIS_LEN_LIMIT , 0 ) ?;
147
160
write ! (
148
161
f,
149
162
", shape={:?}, strides={:?}, layout={:?}" ,
@@ -168,7 +181,8 @@ 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, AXIS_LEN_LIMIT , 0 )
184
+ let limit = axis_len_limit ( f) ;
185
+ format_array ( self , f, <_ >:: fmt, limit, 0 )
172
186
}
173
187
}
174
188
@@ -181,7 +195,8 @@ where
181
195
S : Data < Elem = A > ,
182
196
{
183
197
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
184
- format_array ( self , f, <_ >:: fmt, AXIS_LEN_LIMIT , 0 )
198
+ let limit = axis_len_limit ( f) ;
199
+ format_array ( self , f, <_ >:: fmt, limit, 0 )
185
200
}
186
201
}
187
202
/// Format the array using `LowerHex` and apply the formatting parameters used
@@ -193,7 +208,8 @@ where
193
208
S : Data < Elem = A > ,
194
209
{
195
210
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
196
- format_array ( self , f, <_ >:: fmt, AXIS_LEN_LIMIT , 0 )
211
+ let limit = axis_len_limit ( f) ;
212
+ format_array ( self , f, <_ >:: fmt, limit, 0 )
197
213
}
198
214
}
199
215
@@ -206,7 +222,8 @@ where
206
222
S : Data < Elem = A > ,
207
223
{
208
224
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
209
- format_array ( self , f, <_ >:: fmt, AXIS_LEN_LIMIT , 0 )
225
+ let limit = axis_len_limit ( f) ;
226
+ format_array ( self , f, <_ >:: fmt, limit, 0 )
210
227
}
211
228
}
212
229
@@ -250,16 +267,25 @@ mod formatting_with_omit {
250
267
251
268
#[ test]
252
269
fn dim_1 ( ) {
253
- let overflow: usize = 5 ;
270
+ let overflow: usize = 2 ;
254
271
let a = Array1 :: from_elem ( AXIS_LEN_LIMIT + overflow, 1 ) ;
255
272
let actual = format ! ( "{}" , a) ;
256
273
let expected = "[1, 1, 1, ..., 1, 1, 1]" ;
257
274
assert_str_eq ( expected, & actual) ;
258
275
}
259
276
277
+ #[ test]
278
+ fn dim_1_alternate ( ) {
279
+ let overflow: usize = 2 ;
280
+ let a = Array1 :: from_elem ( AXIS_LEN_LIMIT + overflow, 1 ) ;
281
+ let actual = format ! ( "{:#}" , a) ;
282
+ let expected = "[1, 1, 1, 1, 1, 1, 1, 1]" ;
283
+ assert_str_eq ( expected, & actual) ;
284
+ }
285
+
260
286
#[ test]
261
287
fn dim_2_last_axis_overflow ( ) {
262
- let overflow: usize = 3 ;
288
+ let overflow: usize = 2 ;
263
289
let a = Array2 :: from_elem ( ( AXIS_LEN_LIMIT , AXIS_LEN_LIMIT + overflow) , 1 ) ;
264
290
let actual = format ! ( "{}" , a) ;
265
291
let expected = "\
@@ -272,9 +298,24 @@ mod formatting_with_omit {
272
298
assert_str_eq ( expected, & actual) ;
273
299
}
274
300
301
+ #[ test]
302
+ fn dim_2_last_axis_overflow_alternate ( ) {
303
+ let overflow: usize = 2 ;
304
+ let a = Array2 :: from_elem ( ( AXIS_LEN_LIMIT , AXIS_LEN_LIMIT + overflow) , 1 ) ;
305
+ let actual = format ! ( "{:#}" , a) ;
306
+ let expected = "\
307
+ [[1, 1, 1, 1, 1, 1, 1, 1],
308
+ [1, 1, 1, 1, 1, 1, 1, 1],
309
+ [1, 1, 1, 1, 1, 1, 1, 1],
310
+ [1, 1, 1, 1, 1, 1, 1, 1],
311
+ [1, 1, 1, 1, 1, 1, 1, 1],
312
+ [1, 1, 1, 1, 1, 1, 1, 1]]" ;
313
+ assert_str_eq ( expected, & actual) ;
314
+ }
315
+
275
316
#[ test]
276
317
fn dim_2_non_last_axis_overflow ( ) {
277
- let overflow: usize = 5 ;
318
+ let overflow: usize = 2 ;
278
319
let a = Array2 :: from_elem ( ( AXIS_LEN_LIMIT + overflow, AXIS_LEN_LIMIT ) , 1 ) ;
279
320
let actual = format ! ( "{}" , a) ;
280
321
let expected = "\
@@ -288,9 +329,26 @@ mod formatting_with_omit {
288
329
assert_str_eq ( expected, & actual) ;
289
330
}
290
331
332
+ #[ test]
333
+ fn dim_2_non_last_axis_overflow_alternate ( ) {
334
+ let overflow: usize = 2 ;
335
+ let a = Array2 :: from_elem ( ( AXIS_LEN_LIMIT + overflow, AXIS_LEN_LIMIT ) , 1 ) ;
336
+ let actual = format ! ( "{:#}" , a) ;
337
+ let expected = "\
338
+ [[1, 1, 1, 1, 1, 1],
339
+ [1, 1, 1, 1, 1, 1],
340
+ [1, 1, 1, 1, 1, 1],
341
+ [1, 1, 1, 1, 1, 1],
342
+ [1, 1, 1, 1, 1, 1],
343
+ [1, 1, 1, 1, 1, 1],
344
+ [1, 1, 1, 1, 1, 1],
345
+ [1, 1, 1, 1, 1, 1]]" ;
346
+ assert_str_eq ( expected, & actual) ;
347
+ }
348
+
291
349
#[ test]
292
350
fn dim_2_multi_directional_overflow ( ) {
293
- let overflow: usize = 5 ;
351
+ let overflow: usize = 2 ;
294
352
let a = Array2 :: from_elem ( ( AXIS_LEN_LIMIT + overflow, AXIS_LEN_LIMIT + overflow) , 1 ) ;
295
353
let actual = format ! ( "{}" , a) ;
296
354
let expected = "\
@@ -304,6 +362,23 @@ mod formatting_with_omit {
304
362
assert_str_eq ( expected, & actual) ;
305
363
}
306
364
365
+ #[ test]
366
+ fn dim_2_multi_directional_overflow_alternate ( ) {
367
+ let overflow: usize = 2 ;
368
+ let a = Array2 :: from_elem ( ( AXIS_LEN_LIMIT + overflow, AXIS_LEN_LIMIT + overflow) , 1 ) ;
369
+ let actual = format ! ( "{:#}" , a) ;
370
+ let expected = "\
371
+ [[1, 1, 1, 1, 1, 1, 1, 1],
372
+ [1, 1, 1, 1, 1, 1, 1, 1],
373
+ [1, 1, 1, 1, 1, 1, 1, 1],
374
+ [1, 1, 1, 1, 1, 1, 1, 1],
375
+ [1, 1, 1, 1, 1, 1, 1, 1],
376
+ [1, 1, 1, 1, 1, 1, 1, 1],
377
+ [1, 1, 1, 1, 1, 1, 1, 1],
378
+ [1, 1, 1, 1, 1, 1, 1, 1]]" ;
379
+ assert_str_eq ( expected, & actual) ;
380
+ }
381
+
307
382
#[ test]
308
383
fn dim_3_overflow_all ( ) {
309
384
let a = Array3 :: from_shape_fn ( ( 20 , 10 , 7 ) , |( i, j, k) | {
0 commit comments