Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display triangular matrices with dots #127

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,11 @@ triu(A::TriangularToeplitz, k::Integer=0) = triu!(_copymutable(A), k)

isdiag(A::Union{Circulant, LowerTriangularToeplitz, SymmetricToeplitz}) = all(iszero, @view _vc(A)[2:end])
isdiag(A::UpperTriangularToeplitz) = all(iszero, @view _vr(A)[2:end])

# display triangular matrices with dots
function Base.replace_in_print_matrix(A::UpperTriangularToeplitz, i::Integer, j::Integer, s::AbstractString)
i <= j ? s : Base.replace_with_centered_mark(s)
end
function Base.replace_in_print_matrix(A::LowerTriangularToeplitz, i::Integer, j::Integer, s::AbstractString)
i >= j ? s : Base.replace_with_centered_mark(s)
end
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,20 @@ end
@test inv(TL)::TriangularToeplitz ≈ inv(Matrix(TL))
end

@testset "display" begin
UT = UpperTriangularToeplitz([1,2,3,4])
U = UpperTriangular(Matrix(UT))
st = sprint(show, "text/plain", UT)
s = sprint(show, "text/plain", U)
@test split(st, '\n')[2:end] == split(s, '\n')[2:end]

LT = LowerTriangularToeplitz([1,2,3,4])
L = LowerTriangular(Matrix(LT))
st = sprint(show, "text/plain", LT)
s = sprint(show, "text/plain", L)
@test split(st, '\n')[2:end] == split(s, '\n')[2:end]
end

@testset "eigen" begin
for T in (UpperTriangularToeplitz, LowerTriangularToeplitz)
for p in ([1:6;], rand(ComplexF64, 5))
Expand Down
Loading