Skip to content

Commit 92ecab0

Browse files
authored
Simplify show methods (#23)
1 parent e128b18 commit 92ecab0

File tree

3 files changed

+3
-53
lines changed

3 files changed

+3
-53
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.2.4"
4+
version = "0.2.5"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

ext/BlockSparseArraysTensorAlgebraExt/BlockSparseArraysTensorAlgebraExt.jl

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -134,52 +134,4 @@ function GradedUnitRanges.blocklabels(a::BlockSparseVector)
134134
end
135135
end
136136

137-
# This is a temporary fix for `show` being broken for BlockSparseArrays
138-
# with mixed dual and non-dual axes. This shouldn't be needed once
139-
# GradedUnitRanges is rewritten using BlockArrays v1.
140-
# TODO: Delete this once GradedUnitRanges is rewritten.
141-
@interface ::AbstractBlockSparseArrayInterface function Base.show(
142-
io::IO, mime::MIME"text/plain", a::AbstractArray, axes_a::Tuple; kwargs...
143-
)
144-
println(io, "typeof(axes) = ", typeof(axes_a), "\n")
145-
println(
146-
io,
147-
"Warning: To temporarily circumvent a bug in printing BlockSparseArrays with mixtures of dual and non-dual axes, the types of the dual axes printed below might not be accurate. The types printed above this message are the correct ones.\n",
148-
)
149-
return invoke(show, Tuple{IO,MIME"text/plain",AbstractArray}, io, mime, a; kwargs...)
150-
end
151-
152-
# This is a temporary fix for `show` being broken for BlockSparseArrays
153-
# with mixed dual and non-dual axes. This shouldn't be needed once
154-
# GradedUnitRanges is rewritten using BlockArrays v1.
155-
# TODO: Delete this once GradedUnitRanges is rewritten.
156-
function Base.show(io::IO, mime::MIME"text/plain", a::BlockSparseArray; kwargs...)
157-
axes_a = axes(a)
158-
a_nondual = BlockSparseArray(blocks(a), nondual.(axes(a)))
159-
return @interface BlockSparseArrayInterface() show(io, mime, a_nondual, axes_a; kwargs...)
160-
end
161-
162-
# This is a temporary fix for `show` being broken for BlockSparseArrays
163-
# with mixed dual and non-dual axes. This shouldn't be needed once
164-
# GradedUnitRanges is rewritten using BlockArrays v1.
165-
# TODO: Delete this once GradedUnitRanges is rewritten.
166-
function Base.show(
167-
io::IO, mime::MIME"text/plain", a::Adjoint{<:Any,<:BlockSparseMatrix}; kwargs...
168-
)
169-
axes_a = axes(a)
170-
a_nondual = BlockSparseArray(blocks(a'), dual.(nondual.(axes(a'))))'
171-
return @interface BlockSparseArrayInterface() show(io, mime, a_nondual, axes_a; kwargs...)
172-
end
173-
174-
# This is a temporary fix for `show` being broken for BlockSparseArrays
175-
# with mixed dual and non-dual axes. This shouldn't be needed once
176-
# GradedUnitRanges is rewritten using BlockArrays v1.
177-
# TODO: Delete this once GradedUnitRanges is rewritten.
178-
function Base.show(
179-
io::IO, mime::MIME"text/plain", a::Transpose{<:Any,<:BlockSparseMatrix}; kwargs...
180-
)
181-
axes_a = axes(a)
182-
a_nondual = tranpose(BlockSparseArray(transpose(blocks(a)), nondual.(axes(a))))
183-
return @interface BlockSparseArrayInterface() show(io, mime, a_nondual, axes_a; kwargs...)
184-
end
185137
end

test/basics/test_basics.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,10 +1051,8 @@ arrayts = (Array, JLArray)
10511051
# spacing so it isn't easy to make the test general.
10521052
a = BlockSparseArray{elt}([2, 2], [2, 2])
10531053
a[1, 2] = 12
1054-
# TODO: Reenable this once we delete the hacky `Base.show` definitions
1055-
# in `BlockSparseArraysTensorAlgebraExt`.
1056-
@test_broken sprint(show, "text/plain", a) ==
1057-
"$(summary(a)):$(zero(eltype(a))) $(eltype(a)(12)) │ ⋅ ⋅\n $(zero(eltype(a))) $(zero(eltype(a))) │ ⋅ ⋅\n ───────────┼──────\n ⋅ ⋅ │ ⋅ ⋅\n ⋅ ⋅ │ ⋅ ⋅"
1054+
@test sprint(show, "text/plain", a) ==
1055+
"$(summary(a)):\n $(zero(eltype(a))) $(eltype(a)(12)) │ . .\n $(zero(eltype(a))) $(zero(eltype(a))) │ . .\n ───────────┼──────\n . . │ . .\n . . │ . ."
10581056
end
10591057
end
10601058
end

0 commit comments

Comments
 (0)