Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ end

"""
hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian
hermitianpart(x::Number) -> Real

Return the Hermitian part of the square matrix `A`, defined as `(A + A') / 2`, as a
[`Hermitian`](@ref) matrix. For real matrices `A`, this is also known as the symmetric part
Expand All @@ -987,6 +988,7 @@ See also [`hermitianpart!`](@ref) for the corresponding in-place operation.
This function requires Julia 1.10 or later.
"""
hermitianpart(A::AbstractMatrix, uplo::Symbol=:U) = Hermitian(_hermitianpart(A), uplo)
hermitianpart(x::Number) = real(x)

"""
hermitianpart!(A::AbstractMatrix, uplo::Symbol=:U) -> Hermitian
Expand Down
8 changes: 8 additions & 0 deletions test/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,14 @@ end
@test Aherm isa Hermitian
@test Aherm.uplo == LinearAlgebra.char_uplo(uplo)
end
@testset "hermitianpart for numbers" begin
@test hermitianpart(3 + 4im) == 3
@test hermitianpart(5) == 5
@test hermitianpart(2.5) == 2.5
@test hermitianpart(-1 + 0im) == -1
@test typeof(hermitianpart(3 + 4im)) == Int
@test typeof(hermitianpart(2.5 + 3im)) == Float64
end
end

@testset "Structured display" begin
Expand Down