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

Showing sparse arrays in dictionaries #10257

Closed
ViralBShah opened this issue Feb 20, 2015 · 5 comments
Closed

Showing sparse arrays in dictionaries #10257

ViralBShah opened this issue Feb 20, 2015 · 5 comments
Labels
sparse Sparse arrays
Milestone

Comments

@ViralBShah
Copy link
Member

This is probably more general than sparse, but at least for the sparse matrix case, I would love to show something better than .... Something like m x n sparse matrix with nnz nonzeros.

julia> a = Dict()
Dict{Any,Any} with 0 entries

julia> a["sparse"] = speye(5)
5x5 sparse matrix with 5 Float64 entries:
    [1, 1]  =  1.0
    [2, 2]  =  1.0
    [3, 3]  =  1.0
    [4, 4]  =  1.0
    [5, 5]  =  1.0

julia> a
Dict{Any,Any} with 1 entry:
  "sparse" => …
@ViralBShah ViralBShah added the sparse Sparse arrays label Feb 20, 2015
@jakebolewski
Copy link
Member

Related performance issue with current implementation

julia> @time a = sprandn(50_000, 100_000, 0.01);
elapsed time: 3.249520351 seconds (1474 MB allocated, 7.23% gc time in 5 pauses with 3 full sweep)

julia> D = Dict("a"=>a);

julia> @time display(D)
Dict{ASCIIString,Base.SparseMatrix.SparseMatrixCSC{Float64,Int64}} with 1 entry:
  "a" => 
elapsed time: 72.493628928 seconds (29965 MB allocated, 4.88% gc time in 1291 pauses with 1 full sweep)

@mbauman
Copy link
Member

mbauman commented Feb 20, 2015

Hah, yes, that's unfortunate. It's happening because sparse matrices print with a leading '\n'. It'd make sense for showdict to trim leading newlines, but it'd also probably be sensible to get rid of that newline in the sparse print method.

@mbauman mbauman added the io Involving the I/O subsystem: libuv, read, write, etc. label Feb 20, 2015
@JeffBezanson JeffBezanson removed the io Involving the I/O subsystem: libuv, read, write, etc. label Feb 20, 2015
@ViralBShah ViralBShah added this to the 0.4.0 milestone Mar 25, 2015
@mbauman
Copy link
Member

mbauman commented Mar 25, 2015

This is significantly better now, but still not ideal:

julia> a
Dict{Any,Any} with 1 entry:
  "sparse" => 5x5 sparse matrix with 5 Float64 entries:

@mbauman
Copy link
Member

mbauman commented Mar 25, 2015

Actually, it now matches dense matrices. Is there more you want done here? If so, either the title should change or it should be closed in favor of a more general printing issue.

julia> a
Dict{Any,Any} with 2 entries:
  "dense"  => 5x5 Array{Float64,2}:
  "sparse" => 5x5 sparse matrix with 5 Float64 entries:

@ViralBShah
Copy link
Member Author

This is completely fine. I think we can close this specific issue.

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

No branches or pull requests

4 participants