Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,11 @@ function mergeinds!(C::AbstractSparseMatrixCSC, A::AbstractSparseMatrixCSC)
end

# For an integer eltype the Hermitian branches of `\` and `factorize` below would reach
# LinearAlgebra's generic `factorize(::HermOrSym)`, a dense Bunch-Kaufman in
# `Rational{BigInt}`, so they take the `lu` branch instead, which converts to floating
# LinearAlgebra's generic `factorize(::HermOrSym)`, a dense Bunch-Kaufman in floating
# point, so they take the sparse `lu` branch instead, which converts to floating
# point like dense `\` does. Every other eltype keeps its path: floating point goes to
# the sparse Cholesky/LDLt, and `Rational` stays exact through the generic factorization.
# the sparse Cholesky/LDLt, and `Rational` to LinearAlgebra's Hermitian solve, which
# converts it to floating point.
_hermitian_solve(A::AbstractSparseMatrixCSC) =
!(eltype(A) <: Union{Integer, Complex{<:Integer}}) && ishermitian(A)

Expand Down
7 changes: 3 additions & 4 deletions test/solvers/solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,13 @@ end
end
end
@static if COMPREHENSIVE
# `Rational` is not rerouted: it stays exact, like dense
# a Hermitian `Rational` matrix is solved in floating point, as LinearAlgebra solves one
A = sparse(Rational{Int}[2 1; 1 2])
b = Rational{Int}[1, 0]
for M in (A, A')
x = M \ b
@test x isa Vector{Rational{Int}}
@test M * x == b
@test x == Matrix(M) \ b
@test x isa Vector{Float64}
@test x ≈ Hermitian(Matrix(M)) \ b
end
end
end
Expand Down
Loading