Skip to content

Commit eeab182

Browse files
committed
A few test fixes
1 parent 38806ed commit eeab182

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/cholesky.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ end
1818
end
1919
end
2020
# x < zero(x) is check used in `sqrt`, letting LLVM eliminate that check and remove error code.
21-
@inline _nonpdcheck(x::Real) = x < zero(x)
22-
@inline _nonpdcheck(x) = false
21+
@inline _nonpdcheck(x::Real) = x zero(x)
22+
@inline _nonpdcheck(x) = x == x
2323

2424
@generated function _cholesky(::Size{S}, A::StaticMatrix{M,M}, check::Bool) where {S,M}
2525
@assert (M,M) == S
@@ -38,7 +38,8 @@ end
3838
end
3939
L_n_n = Symbol(:L_,n,:_,n)
4040
L_n_n_ltz = Symbol(:L_,n,:_,n,:_,:ltz)
41-
push!(q.args, :($L_n_n = _nonpdcheck($L_n_n) ? (return _chol_failure(A, $n, check)) : sqrt($L_n_n)))
41+
push!(q.args, :(_nonpdcheck($L_n_n) || return _chol_failure(A, $n, check)))
42+
push!(q.args, :($L_n_n = Base.FastMath.sqrt_fast($L_n_n)))
4243
Linv_n_n = Symbol(:Linv_,n,:_,n)
4344
push!(q.args, :($Linv_n_n = inv($L_n_n)))
4445
for m n+1:M

test/chol.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ using LinearAlgebra: PosDefException
3434
m_a = randn(elty, 4,4)
3535
#non hermitian
3636
@test_throws PosDefException cholesky(SMatrix{4,4}(m_a))
37-
nonpd = SVector{4}(@view(m_a[:,1])) |> x -> x * x'
38-
if elty <: Real
39-
@test_throws PosDefException cholesky(nonpd)
40-
@test !issuccess(cholesky(nonpd,check=false))
41-
@test_throws PosDefException cholesky(Hermitian(nonpd))
42-
@test !issuccess(cholesky(Symmetric(nonpd),check=false))
43-
else
44-
@test issuccess(cholesky(Hermitian(nonpd),check=false))
45-
end
4637

4738
m_a = m_a*m_a'
4839
m = SMatrix{4,4}(m_a)
@@ -96,6 +87,21 @@ using LinearAlgebra: PosDefException
9687
@test (@inferred c \ v) isa SVector{3,elty}
9788
@test c \ v c_a \ v_a
9889
end
90+
91+
@testset "Check" begin
92+
for i [1,3,7,25]
93+
x = SVector(ntuple(elty, i))
94+
nonpd = x * x'
95+
if i > 1
96+
@test_throws PosDefException cholesky(nonpd)
97+
@test !issuccess(cholesky(nonpd,check=false))
98+
@test_throws PosDefException cholesky(Hermitian(nonpd))
99+
@test !issuccess(cholesky(Hermitian(nonpd),check=false))
100+
else
101+
@test issuccess(cholesky(Hermitian(nonpd),check=false))
102+
end
103+
end
104+
end
99105
end
100106

101107
@testset "static blockmatrix" for i = 1:10

0 commit comments

Comments
 (0)