Skip to content

Commit

Permalink
Round-trippable show for Bidiagonal (#55347)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jishnub authored Aug 5, 2024
1 parent a163483 commit 996351f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 7 additions & 6 deletions stdlib/LinearAlgebra/src/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,13 @@ end
####################

function show(io::IO, M::Bidiagonal)
# TODO: make this readable and one-line
summary(io, M)
print(io, ":\n diag:")
print_matrix(io, (M.dv)')
print(io, M.uplo == 'U' ? "\n super:" : "\n sub:")
print_matrix(io, (M.ev)')
print(io, "Bidiagonal(")
show(io, M.dv)
print(io, ", ")
show(io, M.ev)
print(io, ", ")
show(io, sym_uplo(M.uplo))
print(io, ")")
end

size(M::Bidiagonal) = (n = length(M.dv); (n, n))
Expand Down
6 changes: 2 additions & 4 deletions stdlib/LinearAlgebra/test/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ Random.seed!(1)

@testset "show" begin
BD = Bidiagonal(dv, ev, :U)
dstring = sprint(Base.print_matrix,BD.dv')
estring = sprint(Base.print_matrix,BD.ev')
@test sprint(show,BD) == "$(summary(BD)):\n diag:$dstring\n super:$estring"
@test sprint(show,BD) == "Bidiagonal($(repr(dv)), $(repr(ev)), :U)"
BD = Bidiagonal(dv,ev,:L)
@test sprint(show,BD) == "$(summary(BD)):\n diag:$dstring\n sub:$estring"
@test sprint(show,BD) == "Bidiagonal($(repr(dv)), $(repr(ev)), :L)"
end

@testset for uplo in (:U, :L)
Expand Down

0 comments on commit 996351f

Please sign in to comment.