Skip to content

Commit 2e98546

Browse files
authored
support pretty printing with BlockArray when blocks are sparse (#234)
1 parent eeb5dd3 commit 2e98546

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.16.22"
3+
version = "0.16.23"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/blockarray.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,13 @@ function _replace_in_print_matrix_inds(block_arr, i...)
426426
end
427427
function Base.replace_in_print_matrix(block_arr::BlockArray{<:Any,2}, i::Integer, j::Integer, s::AbstractString)
428428
try
429-
bl, inds = _replace_in_print_matrix_inds(block_arr, i, j)
430-
Base.replace_in_print_matrix(bl, inds..., s)
429+
I,J = findblock(axes(block_arr,1),i),findblock(axes(block_arr,2),j)
430+
if Int(I) in colsupport(block_arr.blocks, Int(J))
431+
bl, inds = _replace_in_print_matrix_inds(block_arr, i, j)
432+
Base.replace_in_print_matrix(bl, inds..., s)
433+
else
434+
Base.replace_with_centered_mark(s)
435+
end
431436
catch UndefRefError # thrown with undef_blocks
432437
s
433438
end

test/test_blockarrayinterface.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ end
126126
@test_throws BlockBoundsError A[Block(1, 3)]
127127
@test A == [1 2 0 0; 0 0 1 2]
128128
@test BlockArray(A) == A
129+
@test stringmime("text/plain", A) == "2×2-blocked 2×4 BlockMatrix{$Int, Diagonal{Matrix{$Int}, Vector{Matrix{$Int}}}, Tuple{BlockedUnitRange{Vector{$Int}}, BlockedUnitRange{Vector{$Int}}}}:\n 1 2 │ ⋅ ⋅\n ──────┼──────\n ⋅ ⋅ │ 1 2"
129130

130131
N = 3
131132
D = Diagonal(mortar(Fill.(-(0:N) - (0:N) .^ 2, 1:2:2N+1)))

0 commit comments

Comments
 (0)