JuliaStats / PDMats.jl

Uniform Interface for positive definite matrices of various structures
Other
104 stars 43 forks source link

Symmetry failure in `inv` with `StaticArrays.SMatrix` #208

Closed timholy closed 2 weeks ago

timholy commented 2 weeks ago
julia> C = PDMat(@SMatrix([0.2958383840919454 -0.19638474565333153; -0.19638474565333153 0.29835205505598084]))
2×2 PDMat{Float64, SMatrix{2, 2, Float64, 4}}:
  0.295838  -0.196385
 -0.196385   0.298352

julia> inv(C)
ERROR: PosDefException: matrix is not Hermitian; Cholesky factorization failed.
Stacktrace:
 [1] non_hermitian_error()
   @ StaticArrays ~/.julia/packages/StaticArrays/MSJcA/src/cholesky.jl:2
 [2] #cholesky#549
   @ ~/.julia/packages/StaticArrays/MSJcA/src/cholesky.jl:4 [inlined]
 [3] cholesky
   @ ~/.julia/packages/StaticArrays/MSJcA/src/cholesky.jl:3 [inlined]
 [4] PDMat(mat::SMatrix{2, 2, Float64, 4})
   @ PDMats ~/.julia/dev/PDMats/src/pdmat.jl:19
 [5] inv(a::PDMat{Float64, SMatrix{2, 2, Float64, 4}})
   @ PDMats ~/.julia/dev/PDMats/src/pdmat.jl:92
 [6] top-level scope
   @ REPL[31]:1

julia> invC = inv(C.chol); @show invC - invC'
invC - invC' = [0.0 -4.440892098500626e-16; 4.440892098500626e-16 0.0]
2×2 SMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2):
 0.0          -4.44089e-16
 4.44089e-16   0.0

Not sure if this should be viewed as a bug in StaticArrays or here.

timholy commented 2 weeks ago

Ah, xref https://github.com/JuliaArrays/StaticArrays.jl/issues/1218.