BlockDiagonals.jl
BlockDiagonals.jl copied to clipboard
Abstract block diagonal matrix
We define an abstract block diagonal matrix with an interface similar to the BlockDiagonal of this package here:
https://github.com/JuliaOpt/SemidefiniteOptInterface.jl/blob/c83bfe9b521eafc5182465cba7c4ce0e9f43ab6b/src/mock.jl#L1-L30
It allows the block diagonal matrices returned by different SDP solvers such as CSDP or SDPA to share the same supertype.
Would it make sense for this package to have an AbstractBlockDiagonal type, replace:
https://github.com/invenia/BlockDiagonals.jl/blob/f374931fbe4e76a391ddd2ef19a9d44eff0e8f83/src/blockdiagonal.jl#L8
by BlockDiagonal <: AbstractBlockDiagonal and have functions be defined for AbstractBlockDiagonal when they are not accessing the blocks field directly ?
Thanks for opening! What do you see as the advantage of introducing an AbstractBlockDiagonal?
One example is this function which could be defined on AbstractBlockDiagonal:
https://github.com/invenia/BlockDiagonals.jl/blob/master/src/blockdiagonal.jl#L122-L126
So that we don't have to copy past it for SDPA and CSDP block diagonal matrices.
Why not just use BlockDiagonal?
I think I'm just not understanding the use-case yet. I don't want to add it if there's a easier/better way to achieve the same thing. But if it turns out to be useful to you I think I'd be happy to accept it. The PR would be small, e.g. something like
export AbstractBlockDiagonal, ...
abstract type AbstractBlockDiagonal{T} <: AbstractMatrix{T} end
struct BlockDiagonal{T, V<:AbstractMatrix{T}} <: AbstractBlockDiagonal{T}
...
This is due to the fact that the block diagonal matrix struct is a wrapper on top of a block diagonal matrix stored by a C-library. I have an API for accessing the matrix corresponding to a block but the matrix is not just a Julia Vector of the blocks. See for instance:
https://github.com/JuliaOpt/SDPA.jl/blob/b516ae767fa61e7536d5c67a1f3b7744a5fa64b7/src/blockmat.jl