Skip to content

Commit

Permalink
Improve sparse show internals
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Jan 12, 2025
1 parent 9a34fa2 commit 9f09958
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseArraysBase"
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.2.4"
version = "0.2.5"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
1 change: 1 addition & 0 deletions src/abstractsparsearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ end
function getunstoredindex(a::ReplacedUnstoredSparseArray, I::Int...)
return a.getunstoredindex(a, I...)
end
eachstoredindex(a::ReplacedUnstoredSparseArray) = eachstoredindex(parent(a))

Check warning on line 54 in src/abstractsparsearray.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractsparsearray.jl#L54

Added line #L54 was not covered by tests
@derive ReplacedUnstoredSparseArray AbstractArrayOps
4 changes: 2 additions & 2 deletions src/abstractsparsearrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ end
Base.show(io::IO, c::UnquotedChar) = print(io, c.char)
Base.show(io::IO, ::MIME"text/plain", c::UnquotedChar) = show(io, c)

function show_getunstoredindex(a::AbstractArray, I::Int...)
function getunstoredindex_show(a::AbstractArray, I::Int...)
return UnquotedChar('')
end

Expand All @@ -399,7 +399,7 @@ end
isempty(a) && return nothing
print(io, ":")
println(io)
a′ = ReplacedUnstoredSparseArray(a, show_getunstoredindex)
a′ = ReplacedUnstoredSparseArray(a, getunstoredindex_show)
Base.print_array(io, a′)
return nothing
end
14 changes: 8 additions & 6 deletions test/basics/test_sparsearraydok.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ arrayts = (Array,)
@test b[1, 2] == 12
@test b[4, 3] == 21

# Printing
# Not testing other element types since they change the
# spacing so it isn't easy to make the test general.
a = SparseArrayDOK{Float64}(2, 2)
a[1, 2] = 12
@test sprint(show, "text/plain", a) == "$(summary(a)):\n$(eltype(a)(12))\n ⋅ ⋅"
if elt === Float64
# Printing
# Not testing other element types since they change the
# spacing so it isn't easy to make the test general.
a = SparseArrayDOK{elt}(2, 2)
a[1, 2] = 12
@test sprint(show, "text/plain", a) == "$(summary(a)):\n$(eltype(a)(12))\n ⋅ ⋅"
end
end

0 comments on commit 9f09958

Please sign in to comment.