Skip to content

Commit 996351f

Browse files
authored
Round-trippable show for Bidiagonal (#55347)
This changes how a `Bidiagonal` is displayed using the 2-arg `show` to a form that may be parsed. After this, ```julia julia> B = Bidiagonal([1,2,3], [1,2], :U) 3×3 Bidiagonal{Int64, Vector{Int64}}: 1 1 ⋅ ⋅ 2 2 ⋅ ⋅ 3 julia> show(B) Bidiagonal([1, 2, 3], [1, 2], :U) ``` The displayed form is a valid constructor now.
1 parent a163483 commit 996351f

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

stdlib/LinearAlgebra/src/bidiag.jl

+7-6
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ end
264264
####################
265265

266266
function show(io::IO, M::Bidiagonal)
267-
# TODO: make this readable and one-line
268-
summary(io, M)
269-
print(io, ":\n diag:")
270-
print_matrix(io, (M.dv)')
271-
print(io, M.uplo == 'U' ? "\n super:" : "\n sub:")
272-
print_matrix(io, (M.ev)')
267+
print(io, "Bidiagonal(")
268+
show(io, M.dv)
269+
print(io, ", ")
270+
show(io, M.ev)
271+
print(io, ", ")
272+
show(io, sym_uplo(M.uplo))
273+
print(io, ")")
273274
end
274275

275276
size(M::Bidiagonal) = (n = length(M.dv); (n, n))

stdlib/LinearAlgebra/test/bidiag.jl

+2-4
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@ Random.seed!(1)
143143

144144
@testset "show" begin
145145
BD = Bidiagonal(dv, ev, :U)
146-
dstring = sprint(Base.print_matrix,BD.dv')
147-
estring = sprint(Base.print_matrix,BD.ev')
148-
@test sprint(show,BD) == "$(summary(BD)):\n diag:$dstring\n super:$estring"
146+
@test sprint(show,BD) == "Bidiagonal($(repr(dv)), $(repr(ev)), :U)"
149147
BD = Bidiagonal(dv,ev,:L)
150-
@test sprint(show,BD) == "$(summary(BD)):\n diag:$dstring\n sub:$estring"
148+
@test sprint(show,BD) == "Bidiagonal($(repr(dv)), $(repr(ev)), :L)"
151149
end
152150

153151
@testset for uplo in (:U, :L)

0 commit comments

Comments
 (0)