-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Display sparse matrices by showing their structure with braille patterns #33821
Display sparse matrices by showing their structure with braille patterns #33821
Conversation
ecafd6f
to
4d0c386
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so beautiful! I have just a minor comment below. I found the scaling steps hard to digest, so you may wish to consider leaving some more comments on the rationale, in case someone wants to debug this or change behavior slightly later.
Ok, so in case the matrix is really really large, the "downscaling" may lump nonzeros together, which is somewhat clear and fine, but I didn't get that from the code alone. |
@goggle Could you please rebase your branch? One failing test has been resolved in the meantime. I'd say we merge when all (except the windows "hard repl kill" thing) pass. |
57409e1
to
1774cbf
Compare
e671817
to
c8aa9de
Compare
print(io, "\n \u22ee") | ||
_format_line.(s2:e2, cols2, padr, padc) | ||
function Base.show(io::IOContext, S::AbstractSparseMatrixCSC) | ||
if size(S, 1) <= 20 && size(S, 2) <= 20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use displaysize
to determine this cutoff? It'll need a very rough estimate of how long each column will be once printed, but we can at least take a shot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This threshold (currently set to 20) was introduced because displaying small sparse matrices with braille patterns isn't really helpful. If the matrix is still too big to be printed on the screen, the print_matrix
function already wraps it. That's in my opinion a better solution than displaying such small matrices with braille patterns. Also note that making this dependent on displaysize
would imply that two users would see a sparse matrix sprandn(10, 10, 0.4)
differently depending on their screen size. I'm not sure if this is a good idea.
Maybe some other opinions on this would be helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the cutoff isn't determined by the size of the display, it's determined by the minimum size for braille output to be comprehensible.
I picked 20
out of a hat, however, so one might want to experiment a bit to see how things look. Maybe show the braille output in a comment for a bunch of small matrix sizes and we can judge how they look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
16x16 would probably be fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might change the condition for non-braille printing to
if max(size(S)...) < 16 && !get(io, :compact, false)
so that a compact
IOContext ensures braille display.
Monospaced font support seems to be very poor for braille characters:
I hope it's not too late, but maybe we should think twice before using braille as default. |
As long as the text rendering supports fallback fonts (i.e. everything except for the Windows console), it should be fine. It would be good to check if the Windows console displays braille, though. |
If anybody with access to a Windows console could paste this code println([join(Char.(x))*"\n" for x in [x:x+15 for i=0:11 for x=10304+16*i]]...) into a Julia REPL session and post a screenshot of the output, we should be able to see if Windows displays braille patterns correctly. |
I tried in Windows 8 (via a VMware emulator), and the results were not good: |
Sure, the new Terminal finally supports fallback fonts. But it’s not the default console, and it will be years before it is the default for most of the installed base, so it’s not relevant at the moment. |
@stevengj What about the code point Edit: And I guess the empty braille pattern |
Bump. What remains to get this merged? |
@ViralBShah We need to make sure that older Windows systems can display braille Unicode points correctly, so there is probably no other way than to have #7267 solved first. |
Would it be possible to just use individual dots on Windows? Or just keep the old code on Windows. |
Either of the things @StefanKarpinski mentions would be fine for Windows. Is there a way to know if the terminal can display the unicode correctly and automatically use the new braille scheme, falling back to single dot or current behaviour if it is not a nice terminal? |
I'm still not convinced that it is really not possible to display these braille characters on older Windows systems (Windows 7 and 8). I have found this: Here they suggest to use the command
and to use Lucida console fonts.
I don't know, I've asked myself the same. I assume it is not trivial... (but I could be wrong).
That would be possible if we are able to check if these braille characters are displayed correctly. Windows systems that provide PowerShell do not have any problems, so we shouldn't include these. |
I posted a solution to try out mintty in #7267. Would be nice if anyone with Windows can try it out. |
Fixed merge conflicts. Can we merge this when green, since it's been decided that Windows console users are no longer a concern? |
Something is wrong with the tests, they are pending for over 14 hours now... |
…rns (JuliaLang#33821) * Display sparse matrices by showing their structure with braille patterns * Adopt test which involves showing of sparse matrix * Adopt docstrings * Call `rowvals(S)` only once * Extend code documentation * Simplify calculation of `scaleHeight` and `scaleWidth` * Make `brailleBlocks` a `const` * Initialize `brailleGrid` with `UInt16(10240)` * Let the compiler do the conversion of `\n` * Improve printing to `io` * Unwrap the helper functions directly into the loop * Show small sparse matrix in traditional manner * Add tests for `isstored` * Adapt tests for `show` * Adapt doctests * Use `m` and `n` instead of `size` calls * Initialize `scaleHeight` and `scaleWidth` in `else` clause * Reenable commented test * Declare type of `maxHeight` and `maxWidth` * Do not print leading newline in `_show_with_braille_patterns` * Reenable test for issue 30589 * Shorten type declarations of `maxHeight` and `maxWidth` * Add `isstored` to Base * Add `isstored` for sparse vectors * Make use of Base function `isstored` * Add `boundscheck` macro * Clarify news * Call `issorted` by `Base.issored` * Use `Base.isstored` in tests * Set cutoff value to print sparse matrices with braille to 16 Co-authored-by: Steven G. Johnson <stevenj@alum.mit.edu>
This is not convenient anymore, as Julia represents big sparse matrices with Braille patterns since v1.6 (JuliaLang/julia#33821). Actually, perhaps we could even use that representation for `AbstractRecurrenceMatrix`.
* Do not pirate `show` for sparse matrices This is not convenient anymore, as Julia represents big sparse matrices with Braille patterns since v1.6 (JuliaLang/julia#33821). Actually, perhaps we could even use that representation for `AbstractRecurrenceMatrix`. * update Project.toml
This PR closes #30587.
I have created some screenshots of this braille pattern printing. You can have a look at them here.