Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LU factorization on matrix with Inf/NaN errors in 1.9 #988

Closed
liushang0322 opened this issue Mar 3, 2023 · 4 comments
Closed

LU factorization on matrix with Inf/NaN errors in 1.9 #988

liushang0322 opened this issue Mar 3, 2023 · 4 comments

Comments

@liushang0322
Copy link

I want to port my code base from 1.7.3 to 1.9.0beta4 and test it, found some problems

Below is my version information

julia> versioninfo()
Julia Version 1.9.0-beta4
Commit b75ddb787f (2023-02-07 21:53 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 12 × Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 1 on 12 virtual cores
Environment:
  JULIA_DEPOT_PATH = C:\Users\Public\TongYuan\.julia
  JULIA_DIR = D:\MWorks.Syslab 2022\Tools\julia-1.7.0
  JULIA_IMAGE_THREADS = 1
  JULIA_NUM_THREADS-- = 0x0000000000000001
  JULIA_PKG_USE_CLI_GIT = true
  JULIA_PYTHONCALL_EXE = @PyCall

I locate the problem in the following code

using LinearAlgebra
JwJ = [NaN NaN; NaN NaN] 
lambda = 786.0229394073194 
Jwy = [NaN; NaN;;]
h = (JwJ + lambda * diagm(diag(JwJ))) \ Jwy

Julia1.9.0beta4 gave me the following error:

ERROR: ArgumentError: matrix contains Infs or NaNs
Stacktrace:
 [1] chkfinite
   @ E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lapack.jl:86 [inlined]
 [2] getrf!(A::Matrix{Float64})
   @ LinearAlgebra.LAPACK E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lapack.jl:559
 [3] #lu!#170
   @ E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lu.jl:81 [inlined]
 [4] #lu#176
   @ E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lu.jl:299 [inlined]
 [5] lu (repeats 2 times)
   @ E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lu.jl:298 [inlined]
 [6] \(A::Matrix{Float64}, B::Matrix{Float64})
   @ LinearAlgebra E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\generic.jl:1115
 [7] top-level scope
   @ REPL[216]:1

I locate this problem in\function.

Realized that the \ function is performed using lu decomposition, so I tried lu decomposition again, and also reported the following error to me

julia> luh = lu(JwJ + lambda * diagm(diag(JwJ)))
ERROR: ArgumentError: matrix contains Infs or NaNs
Stacktrace:
 [1] chkfinite
   @ E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lapack.jl:86 [inlined]
 [2] getrf!(A::Matrix{Float64})
   @ LinearAlgebra.LAPACK E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lapack.jl:559
 [3] #lu!#170
   @ E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lu.jl:81 [inlined]
 [4] #lu#176
   @ E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lu.jl:299 [inlined]
 [5] lu
   @ E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lu.jl:298 [inlined]
 [6] lu(A::Matrix{Float64})
   @ LinearAlgebra E:\Julia-1.9.0-beta4\share\julia\stdlib\v1.9\LinearAlgebra\src\lu.jl:298
 [7] top-level scope
   @ REPL[217]:1

This made me realize that it might be Julia1.9.0beta4 calling lapack getrf! Caused by not returning and processing Inf or NaN in advance before the function

Below is what I get in 1.7.3

julia> (JwJ + lambda * diagm(diag(JwJ)))
2×2 Matrix{Float64}:
 NaN  NaN
 NaN  NaN

julia> Jwy
2×1 Matrix{Float64}:
 NaN
 NaN

julia> (JwJ + lambda * diagm(diag(JwJ)))
2×2 Matrix{Float64}:
 NaN  NaN
 NaN  NaN

julia> h = lu(JwJ + lambda * diagm(diag(JwJ)))
LU{Float64, Matrix{Float64}}
L factor:
2×2 Matrix{Float64}:
   1.0  0.0
 NaN    1.0
U factor:
2×2 Matrix{Float64}:
 NaN    NaN
   0.0  NaN
julia> JwJ + lambda * diagm(diag(JwJ))2×2 Matrix{Float64}:
 NaN  NaN
 NaN  NaN
@fredrikekre fredrikekre changed the title bug in 1.9.0beta4 LU factorization on matrix with Inf/NaN errors in 1.9.0-beta4 Mar 3, 2023
@dkarrasch
Copy link
Member

That was changed on purpose, see JuliaLang/julia#47098.

@dkarrasch
Copy link
Member

What's the expected behavior? Is there anything actionable here or can we close this?

@oscardssmith
Copy link
Member

At the very least, this check should respect the check keyword. If it does this, it can be closed IMO.

@oscardssmith oscardssmith changed the title LU factorization on matrix with Inf/NaN errors in 1.9.0-beta4 LU factorization on matrix with Inf/NaN errors in 1.9 Jun 20, 2023
@dkarrasch
Copy link
Member

At the very least, this check should respect the check keyword. If it does this, it can be closed IMO.

This was done in JuliaLang/julia#50134.

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants