-
-
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
Inline rendering of 3d array confusing; proposed syntax for displaying/initializing 3d array #30467
Comments
Not a bad idea. See #7128 for some past discussion on this, where I think multi-semicolon was also proposed at one point. |
Where in the codebase would something like this go, if I wanted to play around with implementing it? |
julia-parser.scm (the parser) would be the place to start. Unfortunately this is breaking, since multiple semicolons are accepted now. However I imagine that must occur in code very rarely. |
Tried to take a stab but there are a couple critical parts I don't quite get yet. I think I can tell that It would help me to know what's going on in the line If that's the case, I suppose I would need to know how to write a call to the Since it appears "rewinding" the input stream isn't done anywhere, I suppose I would just build an array containing the information I need like into an intermediate form like: Any[:(1 2), :(4 5), 2, :(5 3), :(4 5)], (where the single value 2 is the semicolon count) and the julia_syntax.scm function I'd also write would recurssively convert that into e.g. cat(hvcat(), hvcat(), dims = 3). Aside from the pieces I'm missing, does this sound like the right approach? |
Oh, the latter wouldn't work obviously because [3;4;5] would produce Any[3,1,4,1,5]. I suppose maybe I'd need a new object to stick in, like Maybe I'll tinker more later, probably shouldn't sink much time into this now :-) |
Ah!
where the first argument is the dims argument. Idk if it's okay to call a "private" function like that, but I figure I'll just make it work first. |
Has printing 3D arrays using Instead of Perhaps |
@mcabbott - I can't speak to if it has been considered, but that would be a reasonable advance from the status quo IMO. Though I also think nested calls for higher dimensions becomes cumbersome quickly, if you want to quickly type it on the REPL. Something like the below, from one of my tests for SimpleANOVA.jl is what I'd like to find easier to read and enter:
An advantage of a syntax approach, I feel, is that there's less stuff to remove if you want to make it a nicely formatted array in text. Just hit enter in the right spots. Your suggestion on automatically inferring dims would make it easier to type by omitting the argument, but also makes it harder to read perhaps? For the moment, what I've coded for the ;; syntax just maps directly to cat(), so no improvement. I see now that it's possible to do with a single allocation. But you're probably right that the main usage would be testing and development, so that isn't the most important thing. |
Re nice formatting, one use of this is to be able to copy what
With
Conversely, when something prints this out (your example) it's not so easy to spot that it's a 4-array:
whereas a long string starting with |
Another possible printing to consider is |
Yes, the parser in my PR also handles typed array blocks. Re: "reshaped", that's not bad, though I assume they'd want In my PR, an array of 3d arrays would print like this:
Here, the type is clear even if it was so long you couldn't see the semicolons. But if the array had mixed array types, then there could be an issue:
If the array is long enough to hide the semicolons, I take your point. Maybe instead it should show the specific element type if the array is a more general type? Something like:
It's not as clean in most cases, but it is clear. Could also modify the display code to ensure the major separators are displayed. In testing this I just noticed my PR doesn't handle long arrays well right now, splitting across multiple lines, but it could look something like this to emphasize the largest dimension, similar to how a 2d array is handled:
|
Worth saying that I'm not suggesting to change the full n-d array printing mode, which is like this:
|
Re
I guess the precedent for printing constructor functions is this:
Not committed to any of these, I just find the existing hcat / vcat / hvcat syntax with spaces &
|
Fair point on long type names. Idk what's best there. "reshape of an Array does not return a ReshapedArray" -- Ah you are correct, I was confusing that with ReinterpetArray. So perhaps that would be a useful way to display it...
Not bad. Re: my example, yes I was testing the data in two forms (array of vectors and a full multidimensional array) so it was just easier to copy the vectors there. |
Code to try this out:
|
BTW, #37196 makes |
#33697 implements most of this. The printing aspect may still need refining, but a new issue can be opened to address that. |
The third entry of the array, a 3d array with 2 elements across the 3rd dimension is displayed with an extra line break and no indent.
I propose that arrays beyond 2 dimensions may be displayed as, and specified by, multiple semicolons.
E.g. the above output would instead look like:
And a 3d array could be compactly specified by e.g.
[1 2 3; 4 5 6; 7 8 9;; 0 9 8; 7 6 5; 4 3 2]
Each additional dimension would use another semicolon. Normally, extra semicolons are just ignored.
The text was updated successfully, but these errors were encountered: