Skip to content

Commit 8bded8b

Browse files
authored
Fix ishermitian for zero-matrix (#121)
* check error with ≤ * add test * runic
1 parent 2de79e8 commit 8bded8b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/common/matrixproperties.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ function strided_ishermitian_approx(
157157
for j in 1:blocksize:n
158158
jb = min(blocksize, n - j + 1)
159159
ϵ² += _ishermitian_approx_diag(view(A, j:(j + jb - 1), j:(j + jb - 1)), anti)
160-
ϵ² < ϵ²max || return false
160+
ϵ² ϵ²max || return false
161161
for i in 1:blocksize:(j - 1)
162162
ib = blocksize
163163
ϵ² += 2 * _ishermitian_approx_offdiag(
164164
view(A, i:(i + ib - 1), j:(j + jb - 1)),
165165
view(A, j:(j + jb - 1), i:(i + ib - 1)),
166166
anti
167167
)
168-
ϵ² < ϵ²max || return false
168+
ϵ² ϵ²max || return false
169169
end
170170
end
171171
return true

test/projections.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MatrixAlgebraKit
2+
using MatrixAlgebraKit: check_hermitian, default_hermitian_tol
23
using Test
34
using TestExtras
45
using StableRNGs
@@ -10,6 +11,12 @@ const BLASFloats = (Float32, Float64, ComplexF32, ComplexF64)
1011
rng = StableRNG(123)
1112
m = 54
1213
noisefactor = eps(real(T))^(3 / 4)
14+
15+
mat0 = zeros(T, (1, 1))
16+
@test ishermitian(mat0)
17+
@test ishermitian(mat0; atol = default_hermitian_tol(mat0))
18+
@test isnothing(check_hermitian(mat0))
19+
1320
for alg in (NativeBlocked(blocksize = 16), NativeBlocked(blocksize = 32), NativeBlocked(blocksize = 64))
1421
for A in (randn(rng, T, m, m), Diagonal(randn(rng, T, m)))
1522
Ah = (A + A') / 2

0 commit comments

Comments
 (0)