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

confusing repr of single-element SparseMatrix #41135

Closed
simeonschaub opened this issue Jun 8, 2021 · 2 comments · Fixed by #41150
Closed

confusing repr of single-element SparseMatrix #41135

simeonschaub opened this issue Jun 8, 2021 · 2 comments · Fixed by #41150
Labels
display and printing Aesthetics and correctness of printed representations of objects. sparse Sparse arrays

Comments

@simeonschaub
Copy link
Member

I think SparseMatrices should use the same printing as regular arrays, at least for small sizes:

julia> repr(SparseMatrixCSC([1;;]))
"\n 1"

julia> repr([1;;])
"[1;;]"

The original issue where I encountered this was a test failure similar to the following, which wasn't very fun to debug:

julia> @test SparseMatrixCSC([nextfloat(1.0);;]) == [1;;]
Test Failed at REPL[8]:1
  Expression: SparseMatrixCSC($(Expr(:ncat, 2, :(nextfloat(1.0))))) == $(Expr(:ncat, 2, 1))
   Evaluated: 
 1.0 == [1;;]
ERROR: There was an error during testing
@simeonschaub simeonschaub added sparse Sparse arrays display and printing Aesthetics and correctness of printed representations of objects. labels Jun 8, 2021
@ArunS-tack
Copy link
Contributor

Weird. For the same code, it's giving me this error.

MethodError: no method matching SparseMatrixCSC(::Vector{Int64})
Closest candidates are:
  SparseMatrixCSC(::LinearAlgebra.Symmetric) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/SparseArrays/src/sparseconvert.jl:21
  SparseMatrixCSC(::LinearAlgebra.Hermitian) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/SparseArrays/src/sparseconvert.jl:21
  SparseMatrixCSC(::LinearAlgebra.Bidiagonal{Tv, V} where V<:AbstractVector{Tv}) where Tv at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/SparseArrays/src/sparsematrix.jl:575
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

@simeonschaub
Copy link
Member Author

That syntax was only added recently, so you need to use a more recent build of 1.7

simeonschaub added a commit that referenced this issue Jun 9, 2021
This uses the same printing as all other `AbstractArray`s for small
sizes. The three-arg `show` used for REPL printing should still behave
the same but has been refactored to share more code with the existing
methods in Base.

closes #41135
simeonschaub added a commit that referenced this issue Jun 9, 2021
This uses the same printing as all other `AbstractArray`s for small
sizes. The three-arg `show` used for REPL printing should still behave
the same but has been refactored to share more code with the existing
methods in Base.

closes #41135
simeonschaub added a commit that referenced this issue Jun 14, 2021
This now always uses `sparse(I, J, K, m, n)` for showing sparse matrices.
The three-arg `show` used for REPL printing should still behave
the same but has been refactored to share more code with the existing
methods in Base.

closes #41135
KristofferC pushed a commit that referenced this issue Jun 17, 2021
This now always uses `sparse(I, J, K, m, n)` for showing sparse matrices.
The three-arg `show` used for REPL printing should still behave
the same but has been refactored to share more code with the existing
methods in Base.

closes #41135

(cherry picked from commit f280766)
johanmon pushed a commit to johanmon/julia that referenced this issue Jul 5, 2021
This now always uses `sparse(I, J, K, m, n)` for showing sparse matrices.
The three-arg `show` used for REPL printing should still behave
the same but has been refactored to share more code with the existing
methods in Base.

closes JuliaLang#41135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. sparse Sparse arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants