Home

BlockDiagonals.jl

StableDevCICodecov

Functionality for working efficiently with block diagonal matrices.

BlockDiagonal{T, V<:AbstractMatrix{T}} <: AbstractMatrix{T}

A matrix with matrices on the diagonal, and zeros off the diagonal.

blocks(B::BlockDiagonal{T, V}) -> Vector{V}

Return the on-diagonal blocks of B.

blocksize(B::BlockDiagonal, p::Integer, q::Integer=p) -> Tuple

Return the size of the p^th on-diagonal block. Optionally specify q to return the size of block p, q.

Example

julia> X = rand(2, 2); Y = rand(3, 3);

julia> B = BlockDiagonal([X, Y]);

julia> blocksize(B, 1)
(2, 2)

julia> blocksize(B, 1, 2)
(2, 3)

See also blocksizes for accessing the size of all on-diagonal blocks easily.

blocksizes(B::BlockDiagonal) -> Vector{Tuple}

Return the size of each on-diagonal block in order.

Example

julia> B = BlockDiagonal([rand(2, 2), rand(3, 3)]);

julia> blocksizes(B)
2-element Vector{Tuple{Int64, Int64}}:
 (2, 2)
 (3, 3)

See also blocksize for accessing the size of a single block efficiently.

nblocks(B::BlockDiagonal[, dim])

Return the number of on-diagonal blocks.

The total number of blocks in the matrix is nblocks(B)^2.

eigen_blockwise(B::BlockDiagonal, args...; kwargs...) -> values, vectors

Computes the eigendecomposition for each block separately and keeps the block diagonal structure in the matrix of eigenvectors. Hence any parameters given are applied to each eigendecomposition separately, but there is e.g. no global sorting of eigenvalues.