LinearAlgebra.jl icon indicating copy to clipboard operation
LinearAlgebra.jl copied to clipboard

`svd` of matrix with NaN entries: ArgumentError: invalid argument #4 to LAPACK call

Open jbrea opened this issue 1 year ago • 2 comments

I think it would be better to throw a more informative error message when svd is called with a matrix that contains NaN entries.


julia> using LinearAlgebra

julia> svd([0. NaN; 1. 2.])
ERROR: ArgumentError: invalid argument JuliaLang/julia#4 to LAPACK call
Stacktrace:
 [1] chklapackerror
   @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/LinearAlgebra/src/lapack.jl:38 [inlined]
 [2] gesdd!(job::Char, A::Matrix{Float64})
   @ LinearAlgebra.LAPACK ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/LinearAlgebra/src/lapack.jl:1680
 [3] _svd!
   @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/LinearAlgebra/src/svd.jl:125 [inlined]
 [4] svd!(A::Matrix{Float64}; full::Bool, alg::LinearAlgebra.DivideAndConquer)
   @ LinearAlgebra ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/LinearAlgebra/src/svd.jl:105
 [5] svd!
   @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/LinearAlgebra/src/svd.jl:100 [inlined]
 [6] svd(A::Matrix{Float64}; full::Bool, alg::LinearAlgebra.DivideAndConquer)
   @ LinearAlgebra ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/LinearAlgebra/src/svd.jl:179
 [7] svd(A::Matrix{Float64})
   @ LinearAlgebra ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/LinearAlgebra/src/svd.jl:178
 [8] top-level scope
   @ REPL[2]:1

julia> versioninfo()
Julia Version 1.12.0-DEV.138
Commit 90d84d4ab00 (2024-03-06 00:32 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 PRO 5850U with Radeon Graphics
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

The same happens on

julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 PRO 5850U with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

jbrea avatar Mar 06 '24 09:03 jbrea

This comes from the LAPACK error message (https://www.smcm.iqfr.csic.es/docs/intel/mkl/mkl_manual/lse/functn_gesdd.htm), which isn't any more informative. What we may easily do is to point to the offending variable instead of returning the index (in this case, say that the input array had invalid values). I wonder if there's a way to be more informative?

jishnub avatar Mar 06 '24 10:03 jishnub

What we may easily do is to point to the offending variable instead of returning the index (in this case, say that the input array had invalid values)

Sounds good to me.

jbrea avatar Mar 06 '24 10:03 jbrea