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

@show output needs to be compactified #13

Open
dgleich opened this issue Dec 9, 2015 · 4 comments
Open

@show output needs to be compactified #13

dgleich opened this issue Dec 9, 2015 · 4 comments

Comments

@dgleich
Copy link
Contributor

dgleich commented Dec 9, 2015

If you run @show scomponents(A) then it outputs ALL of the information with no truncation. This breaks IJulia if you have a large matrix.

@dgleich
Copy link
Contributor Author

dgleich commented Dec 9, 2015

I have no idea how to do this, it might be a good idea to post a question on the julia-users page. Or see if you can find other packages that do it for their custom types. (Maybe look at LightGraphs.jl and see how they handle the show macro?)

@nassarhuda
Copy link
Collaborator

I don't think there's any way to get around this for now. I asked here.. and multiple issues opened on IJulia but none of the workarounds worked for me - I don't see one standard solution anyway.

@jpfairbanks
Copy link
Member

If you define a function show on your type then it should just work everywhere.
From the docs:

help?> show
search: show showall showerror showcompact @show Cshort Cushort print_shortest searchsorted

  show(x)

  Write an informative text representation of a value to the current output stream. New types should
  overload show(io, x) where the first argument is a stream. The representation used by show generally
  includes Julia-specific formatting and type information.

This is from LightGraphs.jl

function show(io::IO, g::Graph)
    if nv(g) == 0
        print(io, "empty undirected graph")
    else
        print(io, "{$(nv(g)), $(ne(g))} undirected graph")
    end
end

Does this not work for you in IJulia specifically?

In order to achieve the effect of "truncating," you could have a threshold that says: if number of vertices is more than threshold, print summary information, otherwise dump the whole COO representation.

@dgleich
Copy link
Contributor Author

dgleich commented Jan 6, 2016

Something like this should work for us...

It's just a matter of figuring out if there is a standard "Julia" way of handling this problem (doesn't seem to be) or if we should just roll something ourselves (not too hard...).

Most of our types are going to be structs of standard Julia types that would be fairly clean to "@show" using the truncated output that appears in the console, for instance.

I think the routine I was looking for was display

julia> A = sprand(1000,1000,2/1000)
1000x1000 sparse matrix with 1927 Float64 entries:
        [19  ,    1]  =  0.440316
        [59  ,    2]  =  0.515813
        [894 ,    4]  =  0.410991
        [265 ,    5]  =  0.252795
        [446 ,    5]  =  0.915974
        [809 ,    5]  =  0.500597
        [57  ,    6]  =  0.696426
        ⋮
        [992 ,  997]  =  0.823304
        [957 ,  998]  =  0.594415
        [959 ,  998]  =  0.737762
        [739 ,  999]  =  0.0838838
        [780 ,  999]  =  0.0170269
        [140 , 1000]  =  0.567277
        [776 , 1000]  =  0.241237
        [976 , 1000]  =  0.268831

julia> @show A
A =
        [19  ,    1]  =  0.440316
        [59  ,    2]  =  0.515813
        [894 ,    4]  =  0.410991
        [265 ,    5]  =  0.252795
        [446 ,    5]  =  0.915974
        [809 ,    5]  =  0.500597
        [57  ,    6]  =  0.696426
        [181 ,    6]  =  0.467683
        [252 ,    6]  =  0.0603458
        [801 ,    6]  =  0.407075
        [646 ,    7]  =  0.900516
        [647 ,    7]  =  0.455486
        [24  ,    8]  =  0.195954
        [130 ,    8]  =  0.577031
        [814 ,    8]  =  0.345331
        [881 ,   10]  =  0.247018
        [282 ,   12]  =  0.760647
        [726 ,   12]  =  0.0545768
        [735 ,   12]  =  0.188279
        [240 ,   13]  =  0.637445
        [803 ,   13]  =  0.190209
        [865 ,   13]  =  0.623422
        [992 ,   13]  =  0.342424
        [143 ,   14]  =  0.456742
        [42  ,   15]  =  0.0248334
        [204 ,   15]  =  0.693824
... very long output truncated ...

julia> display(A)
1000x1000 sparse matrix with 1964 Float64 entries:
        [685 ,    2]  =  0.302222
        [429 ,    3]  =  0.127655
        [983 ,    3]  =  0.0145682
        [846 ,    4]  =  0.306541
        [442 ,    5]  =  0.104485
        [178 ,    6]  =  0.676207
        [326 ,    6]  =  0.440433
        ⋮
        [971 ,  993]  =  0.111886
        [462 ,  994]  =  0.787298
        [971 ,  996]  =  0.727634
        [211 ,  997]  =  0.401875
        [219 , 1000]  =  0.0180393
        [423 , 1000]  =  0.176956
        [624 , 1000]  =  0.730512
        [680 , 1000]  =  0.520293

So the real question is how to structure show and display for new types.

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

No branches or pull requests

3 participants