I have an application where I want to have a type to represent block 
matrices and then call various linear algebra function which are 
specialized to different situations. This can be neatly accomplished by 
writing (for 2x2 blocks)

type BlockMatrix{TA,TB,TC,TD}
    A::TA
    B::TB
    C::TC
    D::TD
end

So that you can do things like

A,B,C = rand(4,4),Diagonal([1:1.:4]),Diagonal([2:1.:5])
Δ = rand(2,2)
D = BlockMatrix(Diagonal([1.,2.]),Δ,Diagonal([1.,2.]),Δ)
M= BlockMatrix(A,B,C,D)
typeof(M)
>>BlockMatrix{Array{Float64,2},Diagonal{Float64},Diagonal{Float64},
BlockMatrix{Diagonal{Float64},Array{Float64,2},Diagonal{Float64},Array{
Float64,2}}}

at which point it is indeed possible to do fine grained dispatch depending 
on block types. Now, I don't want my block matrix type to accept just 
anything though. Even before doing dimension checking I would at least like 
to ensure that all the arguments are of Matrix type. It would also make 
sense that the element type should be enforced. Since the blocks can be 
composed of blocks themselves it would also seem prudent to make sure that 
BlockMatrix has the same abstract type as its super. So I was able to write

type BlockMatrix{S,TA<:AbstractMatrix{S},TB<:AbstractMatrix{S},TC<:
AbstractMatrix{S},TD<:AbstractMatrix{S}}<:AbstractMatrix{S}
    A::TA
    B::TB
    C::TC
    D::TD
end

however, I then get

M= BlockMatrix(A,B,B,B)

`BlockMatrix{S,TA<:AbstractArray{S,2},TB<:AbstractArray{S,2},TC<:AbstractArray{S,2},TD<:AbstractArray{S,2}}`
 has no method matching 
BlockMatrix{S,TA<:AbstractArray{S,2},TB<:AbstractArray{S,2},TC<:AbstractArray{S,2},TD<:AbstractArray{S,2}}(::Array{Float64,2},
 ::Diagonal{Float64}, ::Diagonal{Float64}, ::Diagonal{Float64})


Indeed, calling methods(BlockMatrix) reveals that no constructors are 
available. So basically, I am not really sure what is going on, having 
apparently reached the limit of my current parametric type no jutsu. Can 
anyone give any pointer (yes I saw the manual, but still not 
understanding)? I am on 0.3.5.

Reply via email to