Matrix padding

ok, I started opening things up to look at doing Pretty-printing small n-d arrays, but I came across a interesting choice which I wanted to make sure wasn’t a deliberate design decision. the left and right padding are completely independent, so arrays of type Any look like they have twice as many cols as they really do:

julia> [1039201 "string"; "tst" 8888; 10 'a'; "row4" 5]
2×2 Matrix{Any}:
 1039201            "string"
        "tst"   8888
      10            'a'
        "row4"     5

. is there any specific reason it shouldn’t be:

julia> [1039201 "string"; "tst" 8888; 10 'a'; "row4" 5]
2×2 Matrix{Any}:
 1039201  "string"
 "tst"        8888
      10  'a'
 "row4"          5

?

edit: ok, guess I figured out why it’s not like above:

julia> ["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 0, 0, 0]
4-element Vector{Any}:
  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 0
 0
 0

, but couldn’t it still be something like:

julia> [1039201 "string"; "tst" 8888; 10 'a'; "row4" 5]
2×2 Matrix{Any}:
 1039201  "string"
 "tst"    8888
      10  'a'
 "row4"      5

?

I’m going to assume it’s fine to fix this, because there are other little annoyances I’ve found with padding too.

matrices don’t take string elision into account:

julia> ["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 0 0 0 0;0 0 0 0 0]
2×5 Matrix{Any}:
  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ⋯ 23 bytes ⋯ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  0  0  0  0
 0                                                                                         0  0  0  0

and when it thinks it should be shortening the matrix because of this it doesn’t actually remove any columns of the matrix:

julia> ["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 0 0;0 0 0]
2×3 Matrix{Any}:
  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ⋯ 33 bytes ⋯ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  …  0  0
 0                                                                                                      0  
0

edit:

I actually did find something that aligns both directions, complex numbers:

julia> [1039201 "string"; "test" 8888; 10 'a'; 1+im 1021-4im]
4×2 Matrix{Any}:
 1039201             "string"                                
        "test"   8888
      10             'a'
      1+1im     1021-4im                                     

I think I can still overlap the columns if I’m careful about it though

I like this too, btw, if you keep adding edge cases like that, keep a hackmd proposol updated it will be simpler once you lauch PR.

eh, this thread wasn’t as interesting to follow. I put in prs to fix the dumbness I was complaining about once I figured out where they came from (fix elision for matrices with a wide first col by rokke-git · Pull Request #60814 · JuliaLang/julia · GitHub, Fix improper alignment of matrices with elided strings by rokke-git · Pull Request #60812 · JuliaLang/julia · GitHub), since they were little bugs rather than anything more fundamental.

I do still plan on proposing both changes (nd-array from the last thread, overlapping alignments from this thread), but they’d be separate prs; as they’re each independent, and kinda substantial changes. I’ll have to be rewriting lots of test cases…

You don’t have to do it all in 1PR, you could make an issue with items and see the response from there, also, not bad to get feedback asap to avoid changing too much in the end, the issue can be general like “proposol for changes on Arrays display”.

1 Like

that sounds like a great plan; I have now created an issue here to base things off of

Nice a litle slack message and yre good to go