Skip to content

Commit

Permalink
Merge branch 'master' into jishnub/triconstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Mar 30, 2024
2 parents edc734e + ee9e796 commit 5cd64ec
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v3
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
Expand All @@ -58,9 +58,10 @@ jobs:
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
if: matrix.coverage
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
if: matrix.coverage
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: lcov.info
- uses: coverallsapp/github-action@master
if: matrix.coverage
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
exit(0) # Exit immediately, as a success
end
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Manifest.toml
Manifest-v*.*.toml
.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ToeplitzMatrices.jl
[![Build Status](https://github.com/JuliaLinearAlgebra/ToeplitzMatrices.jl/workflows/CI/badge.svg?branch=master)](https://github.com/JuliaLinearAlgebra/ToeplitzMatrices.jl/actions/workflows/CI.yml?query=branch%3Amaster)
[![Coverage](https://codecov.io/gh/JuliaLinearAlgebra/ToeplitzMatrices.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaLinearAlgebra/ToeplitzMatrices.jl)
[![Coverage](https://coveralls.io/repos/github/JuliaLinearAlgebra/ToeplitzMatrices.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaLinearAlgebra/ToeplitzMatrices.jl?branch=master)
[![pkgeval](https://juliahub.com/docs/General/ToeplitzMatrices/stable/pkgeval.svg)](https://juliaci.github.io/NanosoldierReports/pkgeval_badges/report.html)

Fast matrix multiplication and division
for Toeplitz, Hankel and circulant matrices in Julia
Expand Down
2 changes: 1 addition & 1 deletion src/hankel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Base.@propagate_inbounds function getindex(A::Hankel, i::Integer, j::Integer)
return A.v[i+j-1]
end
AbstractMatrix{T}(A::Hankel) where {T} = Hankel{T}(AbstractVector{T}(A.v), A.size)
for fun in (:zero, :conj, :copy, :-, :similar, :real, :imag)
for fun in (:zero, :conj, :copy, :-, :real, :imag)
@eval $fun(A::Hankel) = Hankel($fun(A.v), size(A))
end
for op in (:+, :-)
Expand Down
6 changes: 6 additions & 0 deletions src/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,9 @@ function factorize(A::UpperTriangularToeplitz)
dft = plan_fft!(tmp)
return ToeplitzFactorization{T,typeof(A),S,typeof(dft)}(dft * tmp, similar(tmp), dft)
end

# triangular
eigvals(T::TriangularToeplitz) = diag(T)
eigvecs(U::UpperTriangularToeplitz) = eigvecs(UpperTriangular(Matrix(U)))
eigvecs(L::LowerTriangularToeplitz) = eigvecs(LowerTriangular(Matrix(L)))
eigen(U::TriangularToeplitz) = Eigen(eigvals(U), eigvecs(U))
12 changes: 12 additions & 0 deletions src/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,15 @@ 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

# size for factorize
size(T::ToeplitzFactorization{<:Any, <:Circulant}) = (s = size(T.dft,1); (s, s))
size(T::ToeplitzFactorization{<:Any, <:Circulant}, i::Integer) = size(T)[i]
41 changes: 41 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ end
@test_throws ArgumentError Hankel(Int[], (3,4))
@test_throws ArgumentError Hankel(1:5, (3,4))
end

@testset "similar" begin
H = Hankel(1:4)
M = copyto!(similar(H), H)
@test triu(M) == triu(Matrix(H))
end
end

@testset "Convert" begin
Expand Down Expand Up @@ -634,6 +640,30 @@ 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

@testset "eigen" begin
for T in (UpperTriangularToeplitz, LowerTriangularToeplitz)
for p in ([1:6;], rand(ComplexF64, 5))
M = T(p)
λ, V = eigen(M)
@test M * V V * Diagonal(λ)
end
end
end
end

@testset "Cholesky" begin
Expand Down Expand Up @@ -740,3 +770,14 @@ end
end
end
end

@testset "ldiv! for ToeplitzFactorization (#73)" begin
b = rand(6)
x = zero(b)
P = Circulant([1., 0., 0., 0., 0., 0.])
Pfac = factorize(P)
@test size(Pfac) == size(P)
@test size(Pfac, 1) == size(P, 1)
ldiv!(x, Pfac, b)
@test x Pfac \ b
end

0 comments on commit 5cd64ec

Please sign in to comment.