You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LinearAlgebra: round-trippable 2-argument show for Tridiagonal/SymTridiagonal (#55415)
This makes the displayed form of a `Tridiaognal` and a `SymTridiagonal`
valid constructors.
```julia
julia> T = Tridiagonal(1:3, 1:4, 1:3)
4×4 Tridiagonal{Int64, UnitRange{Int64}}:
1 1 ⋅ ⋅
1 2 2 ⋅
⋅ 2 3 3
⋅ ⋅ 3 4
julia> show(T)
Tridiagonal(1:3, 1:4, 1:3)
julia> S = SymTridiagonal(1:4, 1:3)
4×4 SymTridiagonal{Int64, UnitRange{Int64}}:
1 1 ⋅ ⋅
1 2 2 ⋅
⋅ 2 3 3
⋅ ⋅ 3 4
julia> show(S)
SymTridiagonal(1:4, 1:3)
```
Displaying the bands has several advantages: firstly, it's briefer than
printing the full array, and secondly, it displays the special structure
in the bands, if any. E.g.:
```julia
julia> T = Tridiagonal(spzeros(3), spzeros(4), spzeros(3));
julia> show(T)
Tridiagonal(sparsevec(Int64[], Float64[], 3), sparsevec(Int64[], Float64[], 4), sparsevec(Int64[], Float64[], 3))
```
It's clear from the displayed form that `T` has sparse bands.
A special handling for `SymTridiagonal` matrices is necessary, as the
diagonal band is symmetrized. This means:
```julia
julia> using StaticArrays
julia> m = SMatrix{2,2}(1:4);
julia> S = SymTridiagonal(fill(m,3), fill(m,2))
3×3 SymTridiagonal{SMatrix{2, 2, Int64, 4}, Vector{SMatrix{2, 2, Int64, 4}}}:
[1 3; 3 4] [1 3; 2 4] ⋅
[1 2; 3 4] [1 3; 3 4] [1 3; 2 4]
⋅ [1 2; 3 4] [1 3; 3 4]
julia> show(S)
SymTridiagonal(SMatrix{2, 2, Int64, 4}[[1 3; 3 4], [1 3; 3 4], [1 3; 3 4]], SMatrix{2, 2, Int64, 4}[[1 3; 2 4], [1 3; 2 4]])
```
The displayed values correspond to the symmetrized band, and not the
actual input arguments. I think displaying the symmetrized elements
makes more sense here, as this matches the form in the 3-argument
`show`.
0 commit comments