Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

character art: line wrapping for matrices #29203

Closed
mwageringel opened this issue Feb 15, 2020 · 12 comments
Closed

character art: line wrapping for matrices #29203

mwageringel opened this issue Feb 15, 2020 · 12 comments

Comments

@mwageringel
Copy link

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⎠

Component: misc

Keywords: ascii_art, unicode_art

Author: Markus Wageringel

Branch/Commit: 448cdcd

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/29203

@mwageringel mwageringel added this to the sage-9.1 milestone Feb 15, 2020
@mwageringel
Copy link
Author

comment:1

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

sage: %display unicode_art 80
sage: set_random_seed(0)
sage: [matrix.random(RDF, 3, 2), matrix.random(RDF, 3, 3)]
⎡ ⎛ -0.27440062056807446    0.5031965950979831⎞  ⎛-0.033673314214051286
⎢ ⎜-0.001975438590219314   -0.9467802263760512⎟  ⎜   0.5084492941557279
⎣ ⎝   0.5056889961514748  -0.05461130074681608⎠, ⎝   0.6026443545751128

   -0.9401270875197381  -0.35104242112828943⎞ ⎤
   0.19906256610645512    0.3242250183948632⎟ ⎥
   -0.9541798283979341   -0.8948790563276592⎠ ⎦

while previously the matrices were displayed in one piece:

⎡ ⎛ -0.27440062056807446    0.5031965950979831⎞
⎢ ⎜-0.001975438590219314   -0.9467802263760512⎟
⎣ ⎝   0.5056889961514748  -0.05461130074681608⎠,

 ⎛-0.033673314214051286   -0.9401270875197381  -0.35104242112828943⎞ ⎤
 ⎜   0.5084492941557279   0.19906256610645512    0.3242250183948632⎟ ⎥
 ⎝   0.6026443545751128   -0.9541798283979341   -0.8948790563276592⎠ ⎦

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.

@mwageringel
Copy link
Author

Branch: u/gh-mwageringel/29203

@mwageringel
Copy link
Author

Author: Markus Wageringel

@mwageringel
Copy link
Author

Commit: 448cdcd

@mwageringel
Copy link
Author

Changed keywords from none to ascii_art, unicode_art

@mwageringel
Copy link
Author

New commits:

448cdcd29203: add breakpoints to character art of matrices

@videlec
Copy link
Contributor

videlec commented Feb 15, 2020

comment:3

What is the rationale for the globally defined max_rows = 20 and max_cols = 50 (that are used in _ascii_art_)?

@mwageringel
Copy link
Author

comment:4

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.

@videlec
Copy link
Contributor

videlec commented Feb 16, 2020

Reviewer: Vincent Delecroix

@videlec
Copy link
Contributor

videlec commented Feb 16, 2020

comment:5

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).

@mwageringel
Copy link
Author

comment:7

Thank you for the reviews.

@vbraun
Copy link
Member

vbraun commented Feb 19, 2020

Changed branch from u/gh-mwageringel/29203 to 448cdcd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants