Matrix vs. AbstractMatrix

Typically, this would be done as

struct DescriptorStateSpace{T, ET <: ETYPE{T}, MT<:AbstractMatrix{T}} <: AbstractDescriptorStateSpace
    A::MT
    E::ET
    B::MT
    C::MT
    D::MT
    Ts::Float64
    function DescriptorStateSpace{T}(A::MT, E::ETYPE{T},
                                     B::MT, C::MT, D::MT,  Ts::Real) where {T, MT<:AbstractMatrix{T}}
        dss_validation(A, E, B, C, D, Ts)
        new{T, typeof(E), MT}(A, E, B, C, D, Float64(Ts))
    end
end

This would be equally efficient, as all the types are concrete, but it would be more general. The alternative as posed in the post would also work, but it might be less performant, as it would involve dynamically dispatching to the correct methods. Whether the difference in performance is a factor for actual problems remains to be seen, and may be checked by benchmarking.

3 Likes