Skip to content

Commit 5429d78

Browse files
authored
Improve sparse show internals (#14)
1 parent 9a34fa2 commit 5429d78

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseArraysBase"
22
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.2.4"
4+
version = "0.2.5"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

src/abstractsparsearray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ end
5151
function getunstoredindex(a::ReplacedUnstoredSparseArray, I::Int...)
5252
return a.getunstoredindex(a, I...)
5353
end
54+
eachstoredindex(a::ReplacedUnstoredSparseArray) = eachstoredindex(parent(a))
5455
@derive ReplacedUnstoredSparseArray AbstractArrayOps

src/abstractsparsearrayinterface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ end
388388
Base.show(io::IO, c::UnquotedChar) = print(io, c.char)
389389
Base.show(io::IO, ::MIME"text/plain", c::UnquotedChar) = show(io, c)
390390

391-
function show_getunstoredindex(a::AbstractArray, I::Int...)
391+
function getunstoredindex_show(a::AbstractArray, I::Int...)
392392
return UnquotedChar('')
393393
end
394394

@@ -399,7 +399,7 @@ end
399399
isempty(a) && return nothing
400400
print(io, ":")
401401
println(io)
402-
a′ = ReplacedUnstoredSparseArray(a, show_getunstoredindex)
402+
a′ = ReplacedUnstoredSparseArray(a, getunstoredindex_show)
403403
Base.print_array(io, a′)
404404
return nothing
405405
end

test/basics/test_sparsearraydok.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ arrayts = (Array,)
169169
@test b[1, 2] == 12
170170
@test b[4, 3] == 21
171171

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

0 commit comments

Comments
 (0)