Opened 3 years ago
Closed 3 years ago
#29203 closed enhancement (fixed)
character art: line wrapping for matrices
Reported by:  Markus Wageringel  Owned by:  

Priority:  major  Milestone:  sage9.1 
Component:  misc  Keywords:  ascii_art, unicode_art 
Cc:  Merged in:  
Authors:  Markus Wageringel  Reviewers:  Vincent Delecroix 
Report Upstream:  N/A  Work issues:  
Branch:  448cdcd (Commits, GitHub, GitLab)  Commit:  448cdcda1d7ad24bd1e73baf1b25d6c8964b9037 
Dependencies:  Stopgaps: 
Description
This ticket adds breakpoints to the ASCII and unicode art representations of matrices, so that wide matrices are wrapped in a readable way:
sage: %display unicode_art 80 sage: set_random_seed(0) sage: matrix.random(RDF, 3, 8) ⎛ 0.27440062056807446 0.5031965950979831 0.001975438590219314 ⎜ 0.35104242112828943 0.5084492941557279 0.19906256610645512 ⎝ 0.20282268041839324 0.0728476884470246 0.9938082549986424 0.9467802263760512 0.5056889961514748 0.05461130074681608 0.3242250183948632 0.6026443545751128 0.9541798283979341 0.004239223023573491 0.6670085876677831 0.635743483594841 0.033673314214051286 0.9401270875197381⎞ 0.8948790563276592 0.5763034867990717⎟ 0.5778937006648461 0.9007365327499568⎠
Previously, the output was completely scrambled if the matrix was wider than the window size:
⎛ 0.27440062056807446 0.5031965950979831 0.001975438590219314 0.94678022 63760512 0.5056889961514748 0.05461130074681608 0.033673314214051286 0. 9401270875197381⎞ ⎜ 0.35104242112828943 0.5084492941557279 0.19906256610645512 0.32422501 83948632 0.6026443545751128 0.9541798283979341 0.8948790563276592 0. 5763034867990717⎟ ⎝ 0.20282268041839324 0.0728476884470246 0.9938082549986424 0.0042392230 23573491 0.6670085876677831 0.635743483594841 0.5778937006648461 0. 9007365327499568⎠
Change History (8)
comment:1 Changed 3 years ago by
comment:2 Changed 3 years ago by
Authors:  → Markus Wageringel 

Branch:  → u/ghmwageringel/29203 
Commit:  → 448cdcda1d7ad24bd1e73baf1b25d6c8964b9037 
Keywords:  ascii_art unicode_art added 
Status:  new → needs_review 
New commits:
448cdcd  29203: add breakpoints to character art of matrices

comment:3 followup: 4 Changed 3 years ago by
What is the rationale for the globally defined max_rows = 20
and max_cols = 50
(that are used in _ascii_art_
)?
comment:4 Changed 3 years ago by
In plain text mode, matrices larger than that do not show their entries by default, but print a summary instead:
sage: %display plain sage: matrix.identity(20) 20 x 20 dense matrix over Integer Ring (use the '.str()' method to see the entries)
This behavior is copied by ascii_art
and unicode_art
.
sage: %display ascii_art sage: matrix.identity(20) 20 x 20 dense matrix over Integer Ring
Being global variables, one can set different default values for these variables in init.sage
to customize this behavior.
Note that the message (use the '.str()' method to see the entries)
is not part of the repr, but is added by the display manager using LargeMatrixHelpRepr
, which is not used in ascii_art
display mode.
comment:5 Changed 3 years ago by
Reviewers:  → Vincent Delecroix 

I see. However, I doubt that among developers 20% know about the max_rows
/max_cols
customization... Note that integer partitions introduced Partitions.options.display
to deal with printing details.
Anyway, this is not the purpose of the ticket! I am running the doctests on my machine (since the patchbots seem to be on strike).
comment:6 Changed 3 years ago by
Status:  needs_review → positive_review 

comment:8 Changed 3 years ago by
Branch:  u/ghmwageringel/29203 → 448cdcda1d7ad24bd1e73baf1b25d6c8964b9037 

Resolution:  → fixed 
Status:  positive_review → closed 
There is one small caveat: In the case of lists of matrices that do not exceed the window width, it can happen that now the output is wrapped
while previously the matrices were displayed in one piece:
This is fixed by #29204, but – even without that ticket as a dependency – it would make sense to merge this ticket because the output of wide matrices is so vastly improved in all other cases.