Skip to content

Add simple functionality for filling diagonal with the same matrix #76

@thomasgudjonwright

Description

@thomasgudjonwright

Maybe this is unnecessary, or maybe there is an easy way to do this already, but could it be beneficial to add functionality like this?

julia> x = rand(2,2)
2×2 Matrix{Float64}:
 0.378402  0.484365
 0.799401  0.019679

julia> x_diag = BlockDiagonal(x, 2)
4×4 BlockDiagonal{Float64, Matrix{Float64}}:
 0.378402  0.484365  0.0       0.0
 0.799401  0.019679  0.0       0.0
 0.0       0.0       0.378402  0.484365
 0.0       0.0       0.799401  0.019679

julia> BlockDiagonal(x, 2) == BlockDiagonal([x, x])
true

So far the best way to do this at this point I have found is this:

julia> BlockDiagonal(FillArrays.fill(x,2))
4×4 BlockDiagonal{Float64, Matrix{Float64}}:
 0.378402  0.484365  0.0       0.0
 0.799401  0.019679  0.0       0.0
 0.0       0.0       0.378402  0.484365
 0.0       0.0       0.799401  0.019679

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions