Skip to content

Commit

Permalink
Merge pull request #55 from maxfreu/dev-max
Browse files Browse the repository at this point in the history
Improve show
  • Loading branch information
mcabbott authored Apr 2, 2021
2 parents 5030485 + 3a16616 commit 34555ad
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,40 @@ function keyed_print_matrix(io::IO, A, reduce_size::Bool=false)
end

h, w = displaysize(io)
# If the matrix has millions of rows, avoid making huge ::Any array
ind1 = size(A,1) < h ? Colon() : vcat(1:(h÷2), size(A,1)-(h÷2):size(A,1))
wn = w÷3 # integers take 3 columns each when printed, floats more
ind2 = size(A,2) < wn ? Colon() : vcat(1:(wn÷2), (wn÷2)+1:size(A,2))

fakearray = if ndims(A) == 1
hcat(
ShowWith.(no_offset(axiskeys(A,1))[ind1]; color=colour(A,1)),
# showvec(A, 1, ind1),
getindex(no_offset(unname(keyless(A))), ind1) # avoid trailing index
)
top = size(A,1) < h ? Colon() : (1:(h÷2))
bottom = size(A,1) < h ? (1:0) : size(A,1)-(h÷2):size(A,1)
hcat(vcat(ShowWith.(no_offset(axiskeys(A,1))[top]; color=colour(A,1)),
ShowWith.(no_offset(axiskeys(A,1))[bottom]; color=colour(A,1))),
vcat(getindex(no_offset(unname(keyless(A))), top),
getindex(no_offset(unname(keyless(A))), bottom)))
else
fakearray = hcat(
ShowWith.(no_offset(axiskeys(A,1))[ind1]; color=colour(A,1)),
# showvec(A, 1, ind1),
getindex(no_offset(unname(keyless(A))), ind1, ind2)
)
toprow = vcat(
ShowWith(0, hide=true),
ShowWith.(no_offset(axiskeys(A,2))[ind2]; color=colour(A,2)),
# showvec(A, 2, ind2),
)
fakearray = vcat(permutedims(toprow), fakearray)
top = size(A,1) < h ? Colon() : (1:(h÷2))
bottom = size(A,1) < h ? (1:0) : size(A,1)-(h÷2):size(A,1)
left = size(A,2) < wn ? Colon() : (1:(wn÷2))
right = size(A,2) < wn ? (1:0) : size(A,2)-(wn÷2)+1:size(A,2)

topleft = hcat(ShowWith.(no_offset(axiskeys(A,1))[top]; color=colour(A,1)),
getindex(no_offset(unname(keyless(A))), top, left))

bottomleft = hcat(ShowWith.(no_offset(axiskeys(A,1))[bottom]; color=colour(A,1)),
getindex(no_offset(unname(keyless(A))), bottom, left))

leftblock = vcat(topleft, bottomleft)

bottomblock = hcat(leftblock,
# right block
vcat(getindex(no_offset(unname(keyless(A))), top, right),
getindex(no_offset(unname(keyless(A))), bottom, right)))

# permute it so it becomes a row
toprow = permutedims(vcat(ShowWith(0, hide=true),
ShowWith.(no_offset(axiskeys(A,2))[left]; color=colour(A,2)),
ShowWith.(no_offset(axiskeys(A,2))[right]; color=colour(A,2))))

vcat(toprow, bottomblock)
end
Base.print_matrix(io, fakearray)
end
Expand Down

0 comments on commit 34555ad

Please sign in to comment.