In-place cholesky decomposition fails even if the matrix is hermitian

Hi,

I am encountering an issue with Cholesky decomposition in Julia. The code I am using is as follows:

using StaticArrays, LinearAlgebra

sigma = @MMatrix [20+1.0*cos(2.0) 3.0; 3.0 20-1.0 *cos(2.0)]
sigma1 = @SMatrix [0.01^2 0;0 0.01^2]

sigma2 = sigma1*inv(sigma1+sigma)*sigma
sigma3 = Symmetric(sigma2)

display(sigma3)
display(ishermitian(sigma3))

cholesky!(sigma3)

and the result is

2×2 Symmetric{Float64, SMatrix{2, 2, Float64, 4}}:
 9.99995e-5   7.67596e-11
 7.67596e-11  9.99995e-5
true
PosDefException: matrix is not Hermitian; Cholesky factorization failed.

I expected the Cholesky factorization to succeed since the matrix sigma3 is Hermitian, but it failed. I tried using cholesky(sigma3).L instead, and it succeeded. However, I would like to perform the Cholesky factorization in-place.

I would appreciate any assistance you can provide.

Please report this issue with StaticArrays.jl, they should be skipping the check in this case where the static matrix is wrapped in a Symmetric or Hermitian.

That being said, your matrix is immutable, so I don’t think an in-place operation is possible.

1 Like

Thanks for helping me understand the essence of issue.

As an immediate solution, instead of using the Symmetric, I found that directly assigning sigma2[2,1] = sigma2[1,2] worked fine when sigma1 is MMatrix.

1 Like