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

inv returns wrong result for this SymTridiagonal([1., 0., 0.], [0., 1.]) #30860

Open
atbug opened this issue Jan 27, 2019 · 2 comments
Open

inv returns wrong result for this SymTridiagonal([1., 0., 0.], [0., 1.]) #30860

atbug opened this issue Jan 27, 2019 · 2 comments
Labels

Comments

@atbug
Copy link

atbug commented Jan 27, 2019

julia> using LinearAlgebra
julia> A = SymTridiagonal([1., 0., 0.], [0., 1.])
3×3 SymTridiagonal{Float64,Array{Float64,1}}:
 1.0  0.0   
 0.0  0.0  1.0
     1.0  0.0

julia> inv(A)
3×3 Array{Float64,2}:
 NaN  NaN  NaN
 NaN  NaN  NaN
 NaN  NaN  NaN

julia> inv(convert(Array, A))
3×3 Array{Float64,2}:
 1.0  -0.0  -0.0
 0.0  -0.0   1.0
 0.0   1.0   0.0

julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = "C:\Users\wangc\AppData\Local\atom\app-1.34.0\atom.exe" -a
  JULIA_NUM_THREADS = 2
@runapp
Copy link

runapp commented Jan 27, 2019

This issue is caused by #30861 by further check.
In detail, fatorize failed to check if the array was pos-def and uses LDLt decomposition rather than LU decomp, resulting nan elements.

@brenhinkeller
Copy link
Sponsor Contributor

Looks like we now get an error, instead of silently wrong results (progress?)

julia> A = SymTridiagonal([1., 0., 0.], [0., 1.])
3×3 SymTridiagonal{Float64, Vector{Float64}}:
 1.0  0.0   ⋅
 0.0  0.0  1.0
  ⋅   1.0  0.0

julia> inv(A)
ERROR: ZeroPivotException: factorization encountered one or more zero pivots. Consider switching to a pivoted LU factorization.
Stacktrace:
 [1] ldlt!(S::SymTridiagonal{Float64, Vector{Float64}})
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/ldlt.jl:122
 [2] ldlt(M::SymTridiagonal{Float64, Vector{Float64}}; shift::Bool)
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/ldlt.jl:169
 [3] ldlt
   @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/ldlt.jl:163 [inlined]
 [4] factorize
   @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/ldlt.jl:172 [inlined]
 [5] inv(A::SymTridiagonal{Float64, Vector{Float64}})
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/generic.jl:1039
 [6] top-level scope
   @ REPL[16]:1

julia> inv(convert(Array, A))
3×3 Matrix{Float64}:
 1.0  -0.0  0.0
 0.0  -0.0  1.0
 0.0   1.0  0.0

julia> versioninfo()
Julia Version 1.8.3
Commit 0434deb161e (2022-11-14 20:14 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.3.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores

@brenhinkeller brenhinkeller added the domain:linear algebra Linear algebra label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants