Skip to content

Commit

Permalink
issymmetric/ishermitian for Circulant (#95)
Browse files Browse the repository at this point in the history
* issymmetric and ishermitian for Circulant

* import ishermitian

* don't use begin in indexing
  • Loading branch information
jishnub authored Jul 12, 2023
1 parent e028273 commit 52775d6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ToeplitzMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import LinearAlgebra: ldiv!, factorize, lmul!, pinv, eigvals, eigvecs, eigen, Ei
import LinearAlgebra: cholesky!, cholesky, tril!, triu!, checksquare, rmul!, dot, mul!, tril, triu
import LinearAlgebra: istriu, istril, isdiag
import LinearAlgebra: UpperTriangular, LowerTriangular, Symmetric, Adjoint
import LinearAlgebra: issymmetric, ishermitian
import LinearAlgebra: eigvals, eigvecs, eigen

import AbstractFFTs: Plan, plan_fft!
import StatsBase

Expand Down
17 changes: 17 additions & 0 deletions src/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,23 @@ function sqrt(C::CirculantFactorization)
return Circulant(maybereal(eltype(C), vc))
end

function _vc_first_rest_rev(C::Circulant)
v = _vc(C)
v1 = first(v)
vrest = @view v[firstindex(v)+1:lastindex(v)]
vrestrev = view(vrest, reverse(eachindex(vrest)))
v1, vrest, vrestrev
end

function issymmetric(C::Circulant)
v1, vrest, vrestrev = _vc_first_rest_rev(C)
issymmetric(v1) && all(((a,b),) -> a == transpose(b), zip(vrest, vrestrev))
end
function ishermitian(C::Circulant)
v1, vrest, vrestrev = _vc_first_rest_rev(C)
ishermitian(v1) && all(((a,b),) -> a == adjoint(b), zip(vrest, vrestrev))
end

# Triangular

# NB! only valid for lower triangular
Expand Down
27 changes: 27 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,33 @@ end

D = Diagonal(axes(C1,2))
@test mul!(similar(C1), C1, D) C1 * D

@testset "issymmetric/ishermitian" begin
C = Circulant([1,2,3,0,3,2])
@test issymmetric(C)
@test ishermitian(C)
C = Circulant([1,2])
@test issymmetric(C)
@test ishermitian(C)
C = Circulant([1,2,3])
@test !issymmetric(C)
@test !ishermitian(C)

C = Circulant([1,im,2-3im,0,2+3im,-im])
@test ishermitian(C)
@test !issymmetric(C)
C = Circulant([1,im])
@test !ishermitian(C)
@test issymmetric(C)

C = Circulant([2])
@test issymmetric(C)
@test ishermitian(C)

C = Circulant([NaN])
@test !issymmetric(C)
@test !ishermitian(C)
end
end

@testset "TriangularToeplitz" begin
Expand Down

0 comments on commit 52775d6

Please sign in to comment.