Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check=false for singular symmetric matrix #32086

Merged
merged 1 commit into from
Oct 3, 2019
Merged

Add check=false for singular symmetric matrix #32086

merged 1 commit into from
Oct 3, 2019

Conversation

alexandrebrilhante
Copy link
Contributor

@fredrikekre
Copy link
Member

I believe we need something like:

diff --git a/stdlib/LinearAlgebra/src/symmetric.jl b/stdlib/LinearAlgebra/src/symmetric.jl
index 14bae24..0fd5cda 100644
--- a/stdlib/LinearAlgebra/src/symmetric.jl
+++ b/stdlib/LinearAlgebra/src/symmetric.jl
@@ -474,18 +474,19 @@ mul!(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Hermitian{T,<:StridedMatrix})
 /(A::Symmetric, x::Number) = Symmetric(A.data/x, sym_uplo(A.uplo))
 /(A::Hermitian, x::Real) = Hermitian(A.data/x, sym_uplo(A.uplo))
 
-function factorize(A::HermOrSym{T}) where T
+factorize(A::HermOrSym) = _factorize(A)
+function _factorize(A::HermOrSym{T}; check::Bool=true) where T
     TT = typeof(sqrt(oneunit(T)))
     if TT <: BlasFloat
-        return bunchkaufman(A)
+        return bunchkaufman(A; check=check)
     else # fallback
-        return lu(A)
+        return lu(A; check=check)
     end
 end
 
-det(A::RealHermSymComplexHerm) = real(det(factorize(A)))
-det(A::Symmetric{<:Real}) = det(factorize(A))
-det(A::Symmetric) = det(factorize(A))
+det(A::RealHermSymComplexHerm) = real(det(_factorize(A; check=false)))
+det(A::Symmetric{<:Real}) = det(_factorize(A; check=false))
+det(A::Symmetric) = det(_factorize(A; check=false))
 
 \(A::HermOrSym{<:Any,<:StridedMatrix}, B::AbstractVector) = \(factorize(A), B)
 # Bunch-Kaufman solves can not utilize BLAS-3 for multiple right hand sides

alternatively add check::Bool kwarg to all factorize methods, and propagate check=false only from det in this case.

@andreasnoack
Copy link
Member

The problem was the rounding differences on 32 bit caused the matrix to detected as non-singular but with a tiny pivot so it failed when testing against 0.0. I've changed the test matrix to one that shouldn't cause rounding differences.

@fredrikekre Why not add the keyword to factorize?

@fredrikekre
Copy link
Member

@fredrikekre Why not add the keyword to factorize?

We could do that, but then we should probably add it to factorize(::AbstractMatrix) also, and then its more than just the minimal bugfix.

@andreasnoack
Copy link
Member

True. Let's keep it minimal here. Though, it would probably be good to make that change eventually.

@@ -596,6 +596,14 @@ end
@test Symmetric(B) == Symmetric(Matrix(B))
end

@testset "issue #32079: det for singular Symmetric matrix" begin
A = ones(3, 3)
@test det(Symmetrix(A)) == 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test det(Symmetrix(A)) == 0.0
@test det(Symmetric(A)) == 0.0

@kshyatt kshyatt added the domain:linear algebra Linear algebra label Jul 25, 2019
@fredrikekre fredrikekre self-assigned this Oct 3, 2019
@fredrikekre fredrikekre merged commit 018d9ae into JuliaLang:master Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants