Skip to content

Commit 40d5a4f

Browse files
committed
isnan check in issymetric/ishermitian for Numbers
1 parent 1f55352 commit 40d5a4f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/generic.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ function issymmetric(A::AbstractMatrix)
13501350
return true
13511351
end
13521352

1353-
issymmetric(x::Number) = x == x
1353+
issymmetric(x::Number) = !isnan(x)
13541354

13551355
"""
13561356
ishermitian(A) -> Bool
@@ -1389,7 +1389,7 @@ function ishermitian(A::AbstractMatrix)
13891389
return true
13901390
end
13911391

1392-
ishermitian(x::Number) = (x == conj(x))
1392+
ishermitian(x::Number) = issymmetric(x) && isreal(x)
13931393

13941394
# helper function equivalent to `iszero(v)`, but potentially without the fast exit feature
13951395
# of `all` if this improves performance

test/generic.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,4 +943,12 @@ end
943943
@test B == A2
944944
end
945945

946+
@testset "issymmetric/ishermitian for Numbers" begin
947+
fsym(x) = Val(issymmetric(x))
948+
@test @inferred(fsym(2)) isa Val{true}
949+
@test @inferred(fsym(2im)) isa Val{true}
950+
fherm(x) = Val(ishermitian(x))
951+
@test @inferred(fherm(2)) isa Val{true}
952+
end
953+
946954
end # module TestGeneric

0 commit comments

Comments
 (0)