Skip to content

istril, istriu, diag, etc for block diagonal matrices #31122

Open

Description

Currently, block diagonal matrices don't correctly support istril or istriu

julia> D = Diagonal([[1 2; 3 4], [5 6; 7 8]])
2×2 Diagonal{Array{Int64,2},Array{Array{Int64,2},1}}:
 [1 2; 3 4]           
            [5 6; 7 8]

julia> A = [1 2 0 0; 3 4 0 0; 0 0 5 6; 0 0 7 8] # full matrix of D
4×4 Array{Int64,2}:
 1  2  0  0
 3  4  0  0
 0  0  5  6
 0  0  7  8

julia> istriu(D)
true

julia> istriu(A)
false

These can be solved by adding

istril(D::Diagonal{<:Number}) = true
istril(D::Diagonal) = all(istril, D.diag)

etc.

Once this is fixed, what should the intended behavior of tril(D, k), triu(D, k), diag(D, k), etc. be?
tril(D, k) can just recursively check the blocks but should we make diag(D, k) actually return the k-th super diagonal of the 'full' matrix?

I realize this is quite low on the priority list, but it seems like block diagonal matrices were hastily added and a lot of support is missing.

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions