JuliaLinearAlgebra / IterativeSolvers.jl

Iterative algorithms for solving linear systems, eigensystems, and singular value problems
MIT License
394 stars 106 forks source link

cg! sometimes returns NaNs #314

Closed fredrikekre closed 2 years ago

fredrikekre commented 2 years ago
julia> A
2×2 Matrix{Float64}:
 2.0  1.5
 1.5  3.0

julia> x
2-element Vector{Float64}:
 0.0
 0.0

julia> y = similar(x)
2-element Vector{Float64}:
 5.0e-324
 0.0

julia> IterativeSolvers.cg!(y, A, x)
2-element Vector{Float64}:
 NaN
 NaN

It seems to happen when the allocated output vector contains garbage like above, but not if y = zeros(2) for example. Edit: But maybe this is expected since x also doubles as the initial guess, not just a workspace vector. In particular, if x contains NaNs.