From e72223deafb636af538ba96a21006adfb641c670 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 24 Aug 2023 19:07:26 +0400 Subject: [PATCH 01/18] One-line show for SparseVector --- src/sparsevector.jl | 8 ++++++-- test/sparsevector.jl | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sparsevector.jl b/src/sparsevector.jl index 7e66bc06..a2e5f2ce 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -1006,13 +1006,17 @@ function show(io::IO, ::MIME"text/plain", x::AbstractSparseVector) " stored ", xnnz == 1 ? "entry" : "entries") if xnnz != 0 println(io, ":") - show(IOContext(io, :typeinfo => eltype(x)), x) + show(IOContext(io, :typeinfo => eltype(x)), MIME"text/plain"(), x) end end show(io::IO, x::AbstractSparseVector) = show(convert(IOContext, io), x) function show(io::IOContext, x::AbstractSparseVector) - # TODO: make this a one-line form + nzind = nonzeroinds(x) + nzval = nonzeros(x) + print(io, "sparsevec(", nzind, ", ", nzval, ", ", length(x), ")") +end +function show(io::IOContext, ::MIME"text/plain", x::AbstractSparseVector) nzind = nonzeroinds(x) nzval = nonzeros(x) if isempty(nzind) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index 44659939..f1492550 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1534,7 +1534,7 @@ mutable struct t20488 end show(io, MIME"text/plain"(), spzeros(Float64, Int64, 2)) @test String(take!(io)) == "2-element $(SparseArrays.SparseVector){Float64, Int64} with 0 stored entries" show(io, similar(sparsevec(rand(3) .+ 0.1), t20488)) - @test String(take!(io)) == " [1] = #undef\n [2] = #undef\n [3] = #undef" + @test String(take!(io)) == "sparsevec([1, 2, 3], $t20488[#undef, #undef, #undef], 3)" # Test that we don't introduce unnecessary padding for long sparse arrays show(io, MIME"text/plain"(), SparseVector(div(typemax(Int32), 2), Int32[1], Int32[1])) @test String(take!(io)) == "1073741823-element $(SparseArrays.SparseVector){Int32, Int32} with 1 stored entry:\n [1] = 1" From 8944160d2e40f41af6bdf2b9e28f2eb34daf444d Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 25 Aug 2023 14:52:56 +0400 Subject: [PATCH 02/18] fix empty show --- src/sparsevector.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sparsevector.jl b/src/sparsevector.jl index a2e5f2ce..ea14d1c3 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -1020,7 +1020,7 @@ function show(io::IOContext, ::MIME"text/plain", x::AbstractSparseVector) nzind = nonzeroinds(x) nzval = nonzeros(x) if isempty(nzind) - return show(io, MIME("text/plain"), x) + return show(io, x) end limit = get(io, :limit, false)::Bool half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int) From 99a0db2e9a115e4ecfa47c7fee8b44bfa952c2cf Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 15:06:11 +0530 Subject: [PATCH 03/18] Merge show methods --- docs/Project.toml | 4 ++++ docs/src/index.md | 2 +- src/sparsematrix.jl | 2 +- src/sparsevector.jl | 48 ++++++++++++++++++++++++-------------------- test/sparsevector.jl | 2 +- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index dfa65cd1..14dcc62c 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,2 +1,6 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[compat] +Documenter = "0.27" diff --git a/docs/src/index.md b/docs/src/index.md index f0eb9652..4a9d93d6 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -92,7 +92,7 @@ sparse array instead, you can use the same name with an `sp` prefix: ```jldoctest julia> spzeros(3) -3-element SparseVector{Float64, Int64} with 0 stored entries +sparsevec(Int64[], Float64[], 3) ``` The [`sparse`](@ref) function is often a handy way to construct sparse arrays. For diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index 1703c870..ceeba031 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -2085,7 +2085,7 @@ julia> spzeros(3, 3) ⋅ ⋅ ⋅ julia> spzeros(Float32, 4) -4-element SparseVector{Float32, Int64} with 0 stored entries +sparsevec(Int64[], Float32[], 4) ``` """ spzeros(m::Integer, n::Integer) = spzeros(Float64, m, n) diff --git a/src/sparsevector.jl b/src/sparsevector.jl index ea14d1c3..2d0f142f 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -1000,47 +1000,51 @@ end ### show and friends -function show(io::IO, ::MIME"text/plain", x::AbstractSparseVector) - xnnz = length(nonzeros(x)) - print(io, length(x), "-element ", typeof(x), " with ", xnnz, - " stored ", xnnz == 1 ? "entry" : "entries") - if xnnz != 0 - println(io, ":") - show(IOContext(io, :typeinfo => eltype(x)), MIME"text/plain"(), x) - end -end - -show(io::IO, x::AbstractSparseVector) = show(convert(IOContext, io), x) -function show(io::IOContext, x::AbstractSparseVector) +# function show(, ::MIME"text/plain", x::AbstractSparseVector) +# xnnz = length(nonzeros(x)) +# print(io, length(x), "-element ", typeof(x), " with ", xnnz, +# " stored ", xnnz == 1 ? "entry" : "entries") +# if xnnz != 0 +# println(io, ":") +# show(IOContext(io, :typeinfo => eltype(x)), MIME"text/plain"(), x) +# end +# end + +function show(io::IO, x::AbstractSparseVector) nzind = nonzeroinds(x) nzval = nonzeros(x) print(io, "sparsevec(", nzind, ", ", nzval, ", ", length(x), ")") end -function show(io::IOContext, ::MIME"text/plain", x::AbstractSparseVector) +function show(io::IO, ::MIME"text/plain", x::AbstractSparseVector) nzind = nonzeroinds(x) nzval = nonzeros(x) if isempty(nzind) return show(io, x) end - limit = get(io, :limit, false)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int) + xnnz = length(nzval) + println(io, length(x), "-element ", typeof(x), " with ", xnnz, + " stored ", xnnz == 1 ? "entry" : "entries", ":") + ioctxt = IOContext(io, :typeinfo => eltype(x)) + limit = get(ioctxt, :limit, false)::Bool + half_screen_rows = limit ? div(displaysize(ioctxt)[1] - 8, 2) : typemax(Int) pad = ndigits(nzind[end]) - if !haskey(io, :compact) - io = IOContext(io, :compact => true) + if !haskey(ioctxt, :compact) + ioctxt = IOContext(ioctxt, :compact => true) end for k = eachindex(nzind) if k < half_screen_rows || k > length(nzind) - half_screen_rows - print(io, " ", '[', rpad(nzind[k], pad), "] = ") + print(ioctxt, " ", '[', rpad(nzind[k], pad), "] = ") if isassigned(nzval, Int(k)) - show(io, nzval[k]) + show(ioctxt, nzval[k]) else - print(io, Base.undef_ref_str) + print(ioctxt, Base.undef_ref_str) end - k != length(nzind) && println(io) + k != length(nzind) && println(ioctxt) elseif k == half_screen_rows - println(io, " ", " "^pad, " \u22ee") + println(ioctxt, " ", " "^pad, " \u22ee") end end + return nothing end ### Conversion to matrix diff --git a/test/sparsevector.jl b/test/sparsevector.jl index f1492550..9fb0e8de 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1532,7 +1532,7 @@ mutable struct t20488 end show(io, MIME"text/plain"(), sparsevec(Int64[1], [1.0])) @test String(take!(io)) == "1-element $(SparseArrays.SparseVector){Float64, Int64} with 1 stored entry:\n [1] = 1.0" show(io, MIME"text/plain"(), spzeros(Float64, Int64, 2)) - @test String(take!(io)) == "2-element $(SparseArrays.SparseVector){Float64, Int64} with 0 stored entries" + @test String(take!(io)) == "$sparsevec($(Int64[]), $(Float64[]), 2)" show(io, similar(sparsevec(rand(3) .+ 0.1), t20488)) @test String(take!(io)) == "sparsevec([1, 2, 3], $t20488[#undef, #undef, #undef], 3)" # Test that we don't introduce unnecessary padding for long sparse arrays From 728e116b755f12d833cd8614646564565fccef97 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 15:06:39 +0530 Subject: [PATCH 04/18] ignore docs/build --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ba39cc53..1209b4f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ Manifest.toml +docs/build From 4449100d2288d1f538d57619a51d72ea66e96ce0 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 15:07:24 +0530 Subject: [PATCH 05/18] Remove commented out method --- src/sparsevector.jl | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/sparsevector.jl b/src/sparsevector.jl index 2d0f142f..570607f8 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -1000,16 +1000,6 @@ end ### show and friends -# function show(, ::MIME"text/plain", x::AbstractSparseVector) -# xnnz = length(nonzeros(x)) -# print(io, length(x), "-element ", typeof(x), " with ", xnnz, -# " stored ", xnnz == 1 ? "entry" : "entries") -# if xnnz != 0 -# println(io, ":") -# show(IOContext(io, :typeinfo => eltype(x)), MIME"text/plain"(), x) -# end -# end - function show(io::IO, x::AbstractSparseVector) nzind = nonzeroinds(x) nzval = nonzeros(x) From b5338183db1ae699d75ba96a6f8b65d383e80adf Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 15:11:47 +0530 Subject: [PATCH 06/18] Don't add SparseArrays to docs/Project.toml --- docs/Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/Project.toml b/docs/Project.toml index 14dcc62c..3a52a5db 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,6 +1,5 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] Documenter = "0.27" From 3e918e41eab669fecc0698e32ea32a6959e05fb6 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 15:42:46 +0530 Subject: [PATCH 07/18] Restore unfilled sparsevec display --- docs/src/index.md | 2 +- src/sparsematrix.jl | 2 +- src/sparsevector.jl | 12 ++++++------ test/sparsevector.jl | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 4a9d93d6..f0eb9652 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -92,7 +92,7 @@ sparse array instead, you can use the same name with an `sp` prefix: ```jldoctest julia> spzeros(3) -sparsevec(Int64[], Float64[], 3) +3-element SparseVector{Float64, Int64} with 0 stored entries ``` The [`sparse`](@ref) function is often a handy way to construct sparse arrays. For diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index ceeba031..1703c870 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -2085,7 +2085,7 @@ julia> spzeros(3, 3) ⋅ ⋅ ⋅ julia> spzeros(Float32, 4) -sparsevec(Int64[], Float32[], 4) +4-element SparseVector{Float32, Int64} with 0 stored entries ``` """ spzeros(m::Integer, n::Integer) = spzeros(Float64, m, n) diff --git a/src/sparsevector.jl b/src/sparsevector.jl index 570607f8..10e80a0b 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -1008,16 +1008,16 @@ end function show(io::IO, ::MIME"text/plain", x::AbstractSparseVector) nzind = nonzeroinds(x) nzval = nonzeros(x) - if isempty(nzind) - return show(io, x) - end xnnz = length(nzval) - println(io, length(x), "-element ", typeof(x), " with ", xnnz, - " stored ", xnnz == 1 ? "entry" : "entries", ":") + print(io, length(x), "-element ", typeof(x), " with ", xnnz, + " stored ", xnnz == 1 ? "entry" : "entries") + if xnnz > 0 + println(io, ":") + end ioctxt = IOContext(io, :typeinfo => eltype(x)) limit = get(ioctxt, :limit, false)::Bool half_screen_rows = limit ? div(displaysize(ioctxt)[1] - 8, 2) : typemax(Int) - pad = ndigits(nzind[end]) + pad = isempty(nzind) ? 0 : ndigits(nzind[end]) if !haskey(ioctxt, :compact) ioctxt = IOContext(ioctxt, :compact => true) end diff --git a/test/sparsevector.jl b/test/sparsevector.jl index 9fb0e8de..f1492550 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1532,7 +1532,7 @@ mutable struct t20488 end show(io, MIME"text/plain"(), sparsevec(Int64[1], [1.0])) @test String(take!(io)) == "1-element $(SparseArrays.SparseVector){Float64, Int64} with 1 stored entry:\n [1] = 1.0" show(io, MIME"text/plain"(), spzeros(Float64, Int64, 2)) - @test String(take!(io)) == "$sparsevec($(Int64[]), $(Float64[]), 2)" + @test String(take!(io)) == "2-element $(SparseArrays.SparseVector){Float64, Int64} with 0 stored entries" show(io, similar(sparsevec(rand(3) .+ 0.1), t20488)) @test String(take!(io)) == "sparsevec([1, 2, 3], $t20488[#undef, #undef, #undef], 3)" # Test that we don't introduce unnecessary padding for long sparse arrays From d21fc792f39d1c83810c0ceb6405b742b75987a9 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 16:31:32 +0530 Subject: [PATCH 08/18] Add test for showing a vector of sparsevec --- test/sparsevector.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index f1492550..9dc4560e 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1538,6 +1538,10 @@ mutable struct t20488 end # Test that we don't introduce unnecessary padding for long sparse arrays show(io, MIME"text/plain"(), SparseVector(div(typemax(Int32), 2), Int32[1], Int32[1])) @test String(take!(io)) == "1073741823-element $(SparseArrays.SparseVector){Int32, Int32} with 1 stored entry:\n [1] = 1" + + # ensure that a vector of sparsevecs doesn't use pretty printing for elements + S = sparsevec([1,4], [2,3]) + @test repr([S]) == "$(SparseArrays.SparseVector){Int64, Int64}[$(repr(S))]" end @testset "spzeros with index type" begin From b309da76c7c811bae966af90bd830d9d3648cf26 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 17:21:07 +0530 Subject: [PATCH 09/18] Explicit types --- test/sparsevector.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index 9dc4560e..a0912f31 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1540,7 +1540,8 @@ mutable struct t20488 end @test String(take!(io)) == "1073741823-element $(SparseArrays.SparseVector){Int32, Int32} with 1 stored entry:\n [1] = 1" # ensure that a vector of sparsevecs doesn't use pretty printing for elements - S = sparsevec([1,4], [2,3]) + S = sparsevec(Int64[1,4], Int64[2,3]) + @test repr(S) == "sparsevec([1, 4], [2, 3], 4)" @test repr([S]) == "$(SparseArrays.SparseVector){Int64, Int64}[$(repr(S))]" end From c1239529385245a661ca5e6a912f2af408ec6b26 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 17:21:53 +0530 Subject: [PATCH 10/18] Interpolate vectors in show test --- test/sparsevector.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index a0912f31..7e832b57 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1541,7 +1541,7 @@ mutable struct t20488 end # ensure that a vector of sparsevecs doesn't use pretty printing for elements S = sparsevec(Int64[1,4], Int64[2,3]) - @test repr(S) == "sparsevec([1, 4], [2, 3], 4)" + @test repr(S) == "sparsevec($([1, 4]), $([2, 3]), 4)" @test repr([S]) == "$(SparseArrays.SparseVector){Int64, Int64}[$(repr(S))]" end From 47e26dd6b9d72d2477daeb2799e30c2c95191a1a Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 29 Sep 2023 18:07:46 +0530 Subject: [PATCH 11/18] Explicit types in test RHS --- test/sparsevector.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index 7e832b57..0e199caa 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1541,7 +1541,7 @@ mutable struct t20488 end # ensure that a vector of sparsevecs doesn't use pretty printing for elements S = sparsevec(Int64[1,4], Int64[2,3]) - @test repr(S) == "sparsevec($([1, 4]), $([2, 3]), 4)" + @test repr(S) == "sparsevec($(Int64[1,4]), $(Int64[2,3]), 4)" @test repr([S]) == "$(SparseArrays.SparseVector){Int64, Int64}[$(repr(S))]" end From cb9b31ff79b308dcc32cd59da9b5429d7ce0325a Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 3 Oct 2023 23:38:06 +0530 Subject: [PATCH 12/18] rowvals instead of nonzeroinds --- src/sparsevector.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sparsevector.jl b/src/sparsevector.jl index 10e80a0b..ee0e0107 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -1001,12 +1001,10 @@ end ### show and friends function show(io::IO, x::AbstractSparseVector) - nzind = nonzeroinds(x) - nzval = nonzeros(x) - print(io, "sparsevec(", nzind, ", ", nzval, ", ", length(x), ")") + print(io, "sparsevec(", rowvals(x), ", ", nonzeros(x), ", ", length(x), ")") end function show(io::IO, ::MIME"text/plain", x::AbstractSparseVector) - nzind = nonzeroinds(x) + nzind = rowvals(x) nzval = nonzeros(x) xnnz = length(nzval) print(io, length(x), "-element ", typeof(x), " with ", xnnz, From 33d4bf573b114e7ef8fb41cef9605eb3b621869f Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 9 Oct 2023 12:20:45 +0530 Subject: [PATCH 13/18] Undef show with MIME text/plain --- test/sparsevector.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index a7718bfa..632d47db 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1564,6 +1564,8 @@ mutable struct t20488 end @test String(take!(io)) == "2-element $(SparseArrays.SparseVector){Float64, Int64} with 0 stored entries" show(io, similar(sparsevec(rand(3) .+ 0.1), t20488)) @test String(take!(io)) == "sparsevec([1, 2, 3], $t20488[#undef, #undef, #undef], 3)" + show(io, MIME"text/plain"(), similar(sparsevec(rand(3) .+ 0.1), t20488)) + @test String(take!(io)) == "3-element SparseVector{t20488, Int64} with 3 stored entries:\n [1] = #undef\n [2] = #undef\n [3] = #undef" # Test that we don't introduce unnecessary padding for long sparse arrays show(io, MIME"text/plain"(), SparseVector(div(typemax(Int32), 2), Int32[1], Int32[1])) @test String(take!(io)) == "1073741823-element $(SparseArrays.SparseVector){Int32, Int32} with 1 stored entry:\n [1] = 1" From c53e1f2acb371fe45c329d27c842a6608cb82ea2 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 9 Oct 2023 16:32:09 +0530 Subject: [PATCH 14/18] interpolate struct in display test --- test/sparsevector.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index 632d47db..d95243f6 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1565,7 +1565,7 @@ mutable struct t20488 end show(io, similar(sparsevec(rand(3) .+ 0.1), t20488)) @test String(take!(io)) == "sparsevec([1, 2, 3], $t20488[#undef, #undef, #undef], 3)" show(io, MIME"text/plain"(), similar(sparsevec(rand(3) .+ 0.1), t20488)) - @test String(take!(io)) == "3-element SparseVector{t20488, Int64} with 3 stored entries:\n [1] = #undef\n [2] = #undef\n [3] = #undef" + @test String(take!(io)) == "3-element SparseVector{$t20488, Int64} with 3 stored entries:\n [1] = #undef\n [2] = #undef\n [3] = #undef" # Test that we don't introduce unnecessary padding for long sparse arrays show(io, MIME"text/plain"(), SparseVector(div(typemax(Int32), 2), Int32[1], Int32[1])) @test String(take!(io)) == "1073741823-element $(SparseArrays.SparseVector){Int32, Int32} with 1 stored entry:\n [1] = 1" From 8f925f815f4894d279437c7a6a1f8fde80ec3465 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 9 Oct 2023 19:09:30 +0530 Subject: [PATCH 15/18] Interpolate Int in expected string --- test/sparsevector.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index d95243f6..3bf610e1 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1565,7 +1565,7 @@ mutable struct t20488 end show(io, similar(sparsevec(rand(3) .+ 0.1), t20488)) @test String(take!(io)) == "sparsevec([1, 2, 3], $t20488[#undef, #undef, #undef], 3)" show(io, MIME"text/plain"(), similar(sparsevec(rand(3) .+ 0.1), t20488)) - @test String(take!(io)) == "3-element SparseVector{$t20488, Int64} with 3 stored entries:\n [1] = #undef\n [2] = #undef\n [3] = #undef" + @test String(take!(io)) == "3-element SparseVector{$t20488, $Int} with 3 stored entries:\n [1] = #undef\n [2] = #undef\n [3] = #undef" # Test that we don't introduce unnecessary padding for long sparse arrays show(io, MIME"text/plain"(), SparseVector(div(typemax(Int32), 2), Int32[1], Int32[1])) @test String(take!(io)) == "1073741823-element $(SparseArrays.SparseVector){Int32, Int32} with 1 stored entry:\n [1] = 1" From 8c20ba1c18b1e64937aa0cd9de7a84ed2a7fbabd Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 9 Oct 2023 20:32:02 +0530 Subject: [PATCH 16/18] Test for truncation --- test/sparsevector.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/sparsevector.jl b/test/sparsevector.jl index 3bf610e1..814752db 100644 --- a/test/sparsevector.jl +++ b/test/sparsevector.jl @@ -1569,6 +1569,9 @@ mutable struct t20488 end # Test that we don't introduce unnecessary padding for long sparse arrays show(io, MIME"text/plain"(), SparseVector(div(typemax(Int32), 2), Int32[1], Int32[1])) @test String(take!(io)) == "1073741823-element $(SparseArrays.SparseVector){Int32, Int32} with 1 stored entry:\n [1] = 1" + # ensure that :limit=>true leads to truncation + show(IOContext(io, :limit=>true), MIME"text/plain"(), sparsevec([1:20;], [1:20;])) + @test contains(String(take!(io)), "\n \u22ee\n") # ensure that a vector of sparsevecs doesn't use pretty printing for elements S = sparsevec(Int64[1,4], Int64[2,3]) From 4217641c9973dbc02027a80b6d12e2330030f644 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 10 Oct 2023 19:56:19 +0530 Subject: [PATCH 17/18] don't set Documenter compat --- docs/Project.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index 3a52a5db..dfa65cd1 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,2 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" - -[compat] -Documenter = "0.27" From 12a1c3091cd97fdb7bb63b04362ca63a2644dbe9 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 10 Oct 2023 20:33:29 +0530 Subject: [PATCH 18/18] remove unnecessary inequality change --- src/sparsevector.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sparsevector.jl b/src/sparsevector.jl index b525ad6c..8cdf7d53 100644 --- a/src/sparsevector.jl +++ b/src/sparsevector.jl @@ -1046,7 +1046,7 @@ function show(io::IO, ::MIME"text/plain", x::AbstractSparseVector) xnnz = length(nzval) print(io, length(x), "-element ", typeof(x), " with ", xnnz, " stored ", xnnz == 1 ? "entry" : "entries") - if xnnz > 0 + if xnnz != 0 println(io, ":") end ioctxt = IOContext(io, :typeinfo => eltype(x))