1×1 matrix 0 appears positive definite and cholesky doesn't fail
When an MMatrix or SMatrix is of dimension 1-by-1, it is detected as being positive definite even if its entry is 0, and its cholesky decomposition does not fail. Below I'm using StaticArrays v1.6.5 and julia v1.9.2.
julia> using LinearAlgebra, StaticArrays
julia> m = MArray{Tuple{1,1}}(0.0); # 1×1 MMatrix
julia> isposdef(m) # should be false
true
julia> isposdef(cholesky(m)) # also true: cholesky didn't fail
true
julia> cholesky(m).info # 0 so it's supposedly PosDef
0
same with an SMatrix:
julia> s = SArray{Tuple{1,1}}(0.0);
julia> isposdef(s)
true
julia> isposdef(cholesky(s)) # doesn't fail
true
Things are as expected if the 1×1 matrix has a negative entry, or it it's a regular matrix:
julia> isposdef(MArray{Tuple{1,1}}(-1.0))
false
julia> isposdef([0.0;;])
false
I believe this bug is fixed by https://github.com/JuliaLang/julia/pull/49417/commits/ee3b7796ea25cbad8eafa4d49d0c7c19554b274d (basically, a generic cholesky method is being called that does not throw an error for positive semidefinite matrices), though this has not been incorporated as of the latest stable release (1.9.3).
This package defines their own Cholesky implementation, which seems to still have this bug. The issue is fixed for general matrices, but not for StaticArrays.
Yes, thank you for this. To confirm: the bug is still here using julia v0.10.0 and StaticArrays v1.9.1.