Skip to content

Commit

Permalink
Display triangular matrices with dots (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Jan 10, 2024
1 parent 02f06e5 commit e541d9d
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 @@ -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

2 comments on commit e541d9d

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/98588

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.3 -m "<description of version>" e541d9dda552ec40c65483f9cd8e0a56366d015d
git push origin v0.8.3

Please sign in to comment.