Skip to content

Commit

Permalink
Display triangular matrices with dots
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Jan 8, 2024
1 parent 950e29f commit 71b0c16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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 @@ -634,6 +634,20 @@ end
@test_broken inv(TU)::TriangularToeplitz inv(Matrix(TU))
@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
end

@testset "Cholesky" begin
Expand Down

0 comments on commit 71b0c16

Please sign in to comment.