Lufact throws error on symmetric matrix

linearalgebra

#1

I’m a bit surprised at the behavior of \ in the following experiment:

julia> A = sprand(Float32, 10, 10, .5);

julia> b = rand(Float32, 10);

julia> A \ b
10-element Array{Float64,1}:
   5.86217
   5.19403
  -6.70831
   2.55309
  -9.62651
   5.99579
   2.34133
  -5.06416
  10.9498 
 -34.0649 

julia> A = A + A';

julia> A \ b
ERROR: MethodError: no method matching lufact!(::Hermitian{Float32,SparseMatrixCSC{Float32,Int64}}, ::Type{Val{true}})
Closest candidates are:
  lufact!(::Union{Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:DenseArray, DenseArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2}, SubArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:DenseArray where N where T, DenseArray}, ::Union{Type{Val{false}}, Type{Val{true}}}) where T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64} at linalg/lu.jl:16
  lufact!(::Union{Base.ReshapedArray{T,2,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:DenseArray, DenseArray{T,2}, SubArray{T,2,A,I,L} where L} where I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex, Int64, Range{Int64}},N} where N} where A<:Union{Base.ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N} where N} where A<:DenseArray where N where T, DenseArray} where T, ::Union{Type{Val{false}}, Type{Val{true}}}) at linalg/lu.jl:31
  lufact!(::Tridiagonal{T}, ::Union{Type{Val{false}}, Type{Val{true}}}) where T at linalg/lu.jl:321
Stacktrace:
 [1] \(::Hermitian{Float32,SparseMatrixCSC{Float32,Int64}}, ::Array{Float32,1}) at ./linalg/generic.jl:817
 [2] \(::SparseMatrixCSC{Float32,Int64}, ::Array{Float32,1}) at ./sparse/linalg.jl:869

julia> VERSION
v"0.6.0"

I’m guessing the fact that the second A is detected to be symmetric is a result of the polyalgorithm behind \ but the LU factorization should accept symmetric matrices. It works if I call LU = lufact(A) explicitly and use LU \ b.

Thanks.