JuliaArrays / JuliaArrays/StaticArrays.jl
`cholesky(::Symmetric{<:Any,<:SMatrix})` doesn't respect `uplo`
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
StaticArrays' implementation of Cholesky decomposition assumes that uplo == 'U' in Symmetric and Hermitian wrappers. This gives incorrect results when uplo == 'L' and the underlying array is not actually symmetric/hermitian.
MWE:
julia> using LinearAlgebra, StaticArrays
julia> A = Symmetric(SA[1.5 -1; 1 2], :L)
2×2 Symmetric{Float64, SMatrix{2, 2, Float64, 4}}:
1.5 1.0
1.0 2.0
julia> C = cholesky(A);
julia> C.L * C.U
2×2 SMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2):
1.5 -1.0
-1.0 2.0
julia> C.L * C.U ≈ A
false
I suppose the easiest solution is to replace the following line:
with something like
if A.uplo == 'L'
return _cholesky(Size(A), A.data', check)
else
return _cholesky(Size(A), A.data, check)
end
However, it would be even nicer if uplo were preserved by the factorization, i.e., if cholesky(A).uplo == A.uplo, the way it currently works in Base. That would require a change slightly deeper in the code, but could use the same basic trick: if uplo == 'L', take the conjugate transpose, carry out the factorization as if uplo == 'U', and finally take the conjugate transpose of the output and use it to instantiate a Cholesky instance with uplo == 'L'.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/cholesky.jl at the linked implementation and reproduce the issue with the Julia MWE. Check how the Symmetric or Hermitian uplo value reaches the factorization. Done means cholesky(A) produces factors matching the selected lower or upper triangle, with uplo preserved if that behavior is implemented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100