Skip to content

Commit

Permalink
Non-allocating adjoint for Hankel (#137)
Browse files Browse the repository at this point in the history
* Non-allocating adjoint for Hankel

* Test setindex into adjoint matrix band
  • Loading branch information
jishnub authored Aug 10, 2024
1 parent 33bd343 commit 93d16cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/hankel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ for fun in (:fill!, :rmul!)
end

transpose(A::Hankel) = Hankel(A.v, reverse(size(A)))
adjoint(A::Hankel) = transpose(conj(A))
adjoint(A::Hankel) = Hankel(vec(adjoint(A.v)), reverse(size(A)))
issymmetric(A::Hankel) = size(A,1) == size(A,2)
ishermitian(A::Hankel{<:Number}) = isreal(A) && issymmetric(A)
(==)(A::Hankel, B::Hankel) = A.v == B.v && size(A) == size(B)
(*)(scalar::Number, C::Hankel) = Hankel(scalar * C.v, size(C))
(*)(C::Hankel,scalar::Number) = Hankel(C.v * scalar, size(C))
Expand Down
20 changes: 20 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,26 @@ end
M = copyto!(similar(H), H)
@test triu(M) == triu(Matrix(H))
end

@testset "issymmetric/ishermitian" begin
H = Hankel(1:4)
@test issymmetric(H)
@test ishermitian(H)
H = Hankel((1:4)*im)
@test issymmetric(H)
@test !ishermitian(H)
end

@testset "adjoint" begin
H = Hankel([(1:4)*im;])
H2 = H'
@test H2 isa Hankel
@test H2 == Matrix(H)'
H = Hankel([(1:4);])
H2 = H'
H.v[1] = 10
@test H2.v[1] == 10
end
end

@testset "Convert" begin
Expand Down

0 comments on commit 93d16cb

Please sign in to comment.