Skip to content

Can't sum partially initialized Hermitian matrices that are not isbits with Hermitian Diagonal matrices #1056

@araujoms

Description

@araujoms
Collaborator

Edge case of JuliaLang/julia#52895, missed by the bugfix JuliaLang/julia#52942. @jishnub I think this will be easy for you.

id = Hermitian(I(2))
m = Hermitian(Matrix{BigFloat}(undef,2,2))
m.data[1,1] = 1
m.data[1,2] = 2
m.data[2,2] = 3
m+id

Activity

jishnub

jishnub commented on Mar 3, 2024

@jishnub
Member

The issue seems to be with summing a partially uninitialised Matrix and a Diagonal, which lacks a specialised method. I'll try to come up with a fix, which may also help with performance.

araujoms

araujoms commented on Mar 3, 2024

@araujoms
CollaboratorAuthor

I've looked into it. The problem is that when you call UpperTriangular(id.data) the result is a UpperTriangular{Bool, Diagonal{Bool, Vector{Bool}}}, that is, it is not a strided matrix, and therefore doesn't get caught by the specialized method for summing triangular matrices, but instead goes to the default sum, which cannot handle the undefs.

Argh, this means that whenever Hermitian is wrapping an abstract matrix the same problem will appear. There must be a better solution than writing a specialized method for every single type of abstract matrix. Maybe it's better to do the sum over the upper (or lower) triangular for everything, and let the sparse arrays define their own specialized methods?

jishnub

jishnub commented on Mar 3, 2024

@jishnub
Member

Yes, that makes sense. Perhaps we need to expose some function that falls back to summing over the triangular parts, and one that may be specialized by packages. The reason the current implementation was limited to StridedArrays was to avoid breakages by using scalar indexing for custom arrays, so we need to be a bit careful about that.

araujoms

araujoms commented on May 12, 2025

@araujoms
CollaboratorAuthor

This is fixed in 1.11.5, not sure since when.

dkarrasch

dkarrasch commented on May 12, 2025

@dkarrasch
Member

Probably since JuliaLang/julia#53573.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @araujoms@jishnub@dkarrasch

        Issue actions

          Can't sum partially initialized Hermitian matrices that are not isbits with Hermitian Diagonal matrices · Issue #1056 · JuliaLang/LinearAlgebra.jl