JuliaLinearAlgebra / IterativeSolvers.jl

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

cg returns NaNs #272

Closed ranjanan closed 4 years ago

ranjanan commented 4 years ago

On Julia v1.4, run the following code:

julia> g() = (a = rand(10,10); b = rand(10); v = cg(rand(10,10), rand(10)); return a, b, v)
julia> for i = 1:1000
           a,b,v = g()
           check = any(isnan.(v))
           check && return a, b, v
       end

Run this a few times if need be to see the bug. You'll find that v is all NaNs although if you run cg on the matrix and vector again you won't find NaNs.

FWIW, I also seem to see this pop up more often when I do @spawn g() and I have multiple threads.

haampie commented 4 years ago

cg expects real-symmetric / complex-hermitian, positive definite matrices.

Also you might want to review your definition of g(), as it is not returning the matrices you feed to cg ;)

ViralBShah commented 4 years ago

Use a'*a for the tests.