mcabbott / mcabbott/AxisKeys.jl

`cholesky` of a Symmetric KeyedArray strips out the Symmetric

Open
#97 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
154
Forks
31
PR merge metrics
No merged PRs in 30d

Description

Hello, I got tripped up by this:

julia> X = Symmetric(KeyedArray([1.0 0.1; 0.2 1.0], ([:a, :b], [:a, :b])))
2×2 Symmetric{Float64, KeyedArray{Float64, 2, Matrix{Float64}, Tuple{Vector{Symbol}, Vector{Symbol}}}}:
 1.0  0.1
 0.1  1.0

julia> isposdef(X) # Doesn't give expected answer
false

julia> isposdef(collect(X)) # Gives expected answer
true

Note that

julia> X = Symmetric([1.0 0.1; 0.2 1.0])
2×2 Symmetric{Float64, Matrix{Float64}}:
 1.0  0.1
 0.1  1.0

julia> isposdef(X) # Gives expected answer
true

As far as I can tell, this is because we reach this method in this package:

LinearAlgebra.cholesky(A::Hermitian{T, <:KeyedArray{T}}; kwargs...) where {T} =
    cholesky(parent(A); kwargs...)

And

julia> parent(Hermitian(X))
2-dimensional KeyedArray(...) with keys:
↓   2-element Vector{Symbol}
→   2-element Vector{Symbol}
And data, 2×2 Matrix{Float64}:
        (:a)  (:b)
  (:a)   1.0   0.1
  (:b)   0.2   1.0

which does not satisfy isposdef since it's not Hermitian.

This is with AxisKeys v0.1.22 and julia v1.6.0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Julia examples in the issue, then locate the LinearAlgebra.cholesky method for Hermitian values containing KeyedArray data. Compare its behavior with Symmetric and collect(X), and determine how the reported wrapper or symmetry information is lost. Done means the keyed symmetric case gives the expected positive-definiteness result without breaking the existing method behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.