I am struggling to define a new extension of the existing descriptor state space structure, to cover new functionality with structured or sparse system matrices. Recall that the basic definition used in DescriptorSystems is
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
which restricts the matrices A, B, C, and D to have the same type (they can be, for example, all sparse matrices), while E may have its own type (e.g., sparse, Diagonal, UpperTriangular, ... etc.).
I started to use the following definition of an extended data structure, which ensures full flexibility regarding the types of system matrices
struct DescriptorStateSpaceExt{T} <: AbstractDescriptorStateSpace
A::AbstractMatrix
E::Union{AbstractMatrix,UniformScaling}
B::AbstractMatrix
C::AbstractMatrix
D::AbstractMatrix
Ts::Float64
function DescriptorStateSpaceExt{T}(A::AbstractMatrix{T}, E::Union{AbstractMatrix{T},UniformScaling{Bool}},
B::AbstractMatrix{T}, C::AbstractMatrix{T}, D::AbstractMatrix{T}, Ts::Real) where {T}
dss_validation(A, E, B, C, D, Ts)
new(A, E, B, C, D, Float64(Ts))
end
end
Using this data type I extended several functions such as gbalmr, gh2norm, ghanorm, evalfr, c2d, 'inv' (WIP), to handle large scale matrix models with the A and E matrices sparse or banded. These functions parallel and extend the functionality of the MATLAB's Control System Toolbox for sparse models. To support all operations with descriptor systems involving this data type involves however a substantial effort to cover all possible cases. This is still a WIP and very error prone.
To handle sparse models, I was practically forced to include SparseArrays among the dependencies of DescriptorSystems and to use explicitly the inquiry function issparse to detect sparse models. This implies that type testing occurs at runtime and there is no support during compilation for sparse models. A typical example is the function iszero to detect if a descriptor system has a null transfer function matrix. Here, the rank computations involve calling the function rank with different tolerance parameters for dense and sparse models.
A remedy would be to define another data type for sparse descriptor system state space objects to cover exclussively the functions involving sparse models. A variant with more flexibility would be to define this object with only A and E enforced to be sparse, while B, C and D just AbstractMatrices. This would prevent conversions which are almost always necessary in computations involving these matrices.
I would appreciate any opinion regarding the above aspects.
@baggepinnen What do you think what is the best balance between flexibility and efficiency?
I am struggling to define a new extension of the existing descriptor state space structure, to cover new functionality with structured or sparse system matrices. Recall that the basic definition used in
DescriptorSystemsiswhich restricts the matrices A, B, C, and D to have the same type (they can be, for example, all sparse matrices), while E may have its own type (e.g., sparse, Diagonal, UpperTriangular, ... etc.).
I started to use the following definition of an extended data structure, which ensures full flexibility regarding the types of system matrices
Using this data type I extended several functions such as
gbalmr,gh2norm,ghanorm,evalfr,c2d, 'inv' (WIP), to handle large scale matrix models with the A and E matrices sparse or banded. These functions parallel and extend the functionality of the MATLAB's Control System Toolbox for sparse models. To support all operations with descriptor systems involving this data type involves however a substantial effort to cover all possible cases. This is still a WIP and very error prone.To handle sparse models, I was practically forced to include
SparseArraysamong the dependencies ofDescriptorSystemsand to use explicitly the inquiry functionissparseto detect sparse models. This implies that type testing occurs at runtime and there is no support during compilation for sparse models. A typical example is the functioniszeroto detect if a descriptor system has a null transfer function matrix. Here, the rank computations involve calling the functionrankwith different tolerance parameters for dense and sparse models.A remedy would be to define another data type for sparse descriptor system state space objects to cover exclussively the functions involving sparse models. A variant with more flexibility would be to define this object with only A and E enforced to be sparse, while B, C and D just AbstractMatrices. This would prevent conversions which are almost always necessary in computations involving these matrices.
I would appreciate any opinion regarding the above aspects.
@baggepinnen What do you think what is the best balance between flexibility and efficiency?