Skip to content

Commit 347d5fb

Browse files
authored
Fix show for BlockRange (#280)
1 parent b03703f commit 347d5fb

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

src/blockaxis.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ julia> A = BlockArray([1,2,3],[2,1])
171171
3
172172
173173
julia> blockaxes(A,1)
174-
2-element BlockRange{1, Tuple{Base.OneTo{Int64}}}:
174+
BlockRange(Base.OneTo(2))
175+
176+
julia> blockaxes(A,1) |> collect
177+
2-element Vector{Block{1, Int64}}:
175178
Block(1)
176179
Block(2)
177180
```

src/blockindices.jl

+8-12
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,18 @@ The relationship between `Block` and `BlockRange` mimics the relationship betwee
321321
322322
# Examples
323323
```jldoctest
324-
julia> BlockRange(2,2)
325-
2×2 BlockRange{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}:
326-
Block(1, 1) Block(1, 2)
327-
Block(2, 1) Block(2, 2)
328-
329-
julia> BlockRange(2:3, 3:4)
330-
2×2 BlockRange{2, Tuple{UnitRange{Int64}, UnitRange{Int64}}}:
324+
julia> BlockRange(2:3, 3:4) |> collect
325+
2×2 Matrix{Block{2, Int64}}:
331326
Block(2, 3) Block(2, 4)
332327
Block(3, 3) Block(3, 4)
333328
329+
julia> BlockRange(2, 2) |> collect # number of elements, starting at 1
330+
2×2 Matrix{Block{2, Int64}}:
331+
Block(1, 1) Block(1, 2)
332+
Block(2, 1) Block(2, 2)
333+
334334
julia> Block(1):Block(2)
335-
2-element BlockRange{1, Tuple{UnitRange{Int64}}}:
336-
Block(1)
337-
Block(2)
335+
BlockRange(1:2)
338336
```
339337
"""
340338
BlockRange
@@ -416,8 +414,6 @@ _in(b, ::Tuple{}, ::Tuple{}, ::Tuple{}) = b
416414
# We sometimes need intersection of BlockRange to return a BlockRange
417415
intersect(a::BlockRange{1}, b::BlockRange{1}) = BlockRange(intersect(a.indices[1], b.indices[1]))
418416

419-
Base.show(io::IO, br::BlockRange) = print(io, "BlockRange(", br.indices..., ")")
420-
421417
# needed for scalar-like broadcasting
422418

423419
BlockSlice{Block{1,BT},RT}(a::Base.OneTo) where {BT,RT<:AbstractUnitRange} =

src/blocklinalg.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ julia> B = BlockArray(collect(reshape(1:9, 3, 3)), [1,2], [1,1,1])
1313
2 │ 5 │ 8
1414
3 │ 6 │ 9
1515
16-
julia> BlockArrays.blockrowsupport(B, 2)
17-
3-element BlockRange{1, Tuple{Base.OneTo{Int64}}}:
16+
julia> BlockArrays.blockrowsupport(B, 2) |> collect
17+
3-element Vector{Block{1, Int64}}:
1818
Block(1)
1919
Block(2)
2020
Block(3)
@@ -39,8 +39,8 @@ julia> B = BlockArray(collect(reshape(1:9, 3, 3)), [1,2], [1,1,1])
3939
2 │ 5 │ 8
4040
3 │ 6 │ 9
4141
42-
julia> BlockArrays.blockcolsupport(B, 2)
43-
2-element BlockRange{1, Tuple{Base.OneTo{Int64}}}:
42+
julia> BlockArrays.blockcolsupport(B, 2) |> collect
43+
2-element Vector{Block{1, Int64}}:
4444
Block(1)
4545
Block(2)
4646
```

src/show.jl

+5
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,8 @@ end
147147

148148
Base.show(io::IO, mimetype::MIME"text/plain", a::BlockedUnitRange) =
149149
Base.invoke(show, Tuple{typeof(io),MIME"text/plain",AbstractArray},io, mimetype, a)
150+
151+
# BlockRange
152+
153+
Base.show(io::IO, br::BlockRange) = print(io, "BlockRange(", join(br.indices, ", "), ")")
154+
Base.show(io::IO, ::MIME"text/plain", br::BlockRange) = show(io, br)

test/test_blockindices.jl

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice
110110
@test stringmime("text/plain", Block{0,BigInt}()) == "Block{0, BigInt}(())"
111111
@test stringmime("text/plain", Block{1,BigInt}(1)) == "Block{1, BigInt}((1,))"
112112
@test stringmime("text/plain", Block{2}(1,2)) == "Block(1, 2)"
113+
114+
@test sprint(show, BlockRange(1:2, 2:3)) == "BlockRange(1:2, 2:3)"
115+
@test sprint(show, "text/plain", BlockRange(1:2, 2:3)) == "BlockRange(1:2, 2:3)"
113116
end
114117
end
115118

0 commit comments

Comments
 (0)