Skip to content

cholesky() behaves differently with static matrices #1194

@ojwoodford

Description

@ojwoodford

Below I create identical non-Hermitian matrices of types Matrix and SMatrix, then call cholesky() with check=false, i.e. don't throw errors.

using LinearAlgebra, StaticArrays
mat = randn(10, 10)
v = rand(10)
mat -= v * v'
smat = SMatrix{10, 10, Float64, 100}(mat)
using LinearAlgebra, StaticArrays
mat = randn(10, 10)
v = rand(10)
mat -= v * v'
smat = SMatrix{10, 10, Float64, 100}(mat)
display(issuccess(cholesky(mat; check=false)))  # No error
display(issuccess(StaticArrays._cholesky(Size(smat), smat, false)))  # No error
display(issuccess(cholesky(smat; check=false)))  # Error

The Base implementation throws no error, as expected. However, the StaticArrays implementation throws a PosDefException error.

There is an issue with line 4 of src/cholesky.jl. I believe it should be:

!check || ishermitian(A) || non_hermitian_error()

The penultimate line of my script suggests this will work. However, there should probably be a test case or two to confirm.

I would submit a PR request, but I haven't yet started building and developing Julia and the standard library locally yet, and don't think I'm ready to start quite yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions