From eb6c46d925bac9457ac14fec5c648409dc29ec0a Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Thu, 20 May 2021 09:14:22 +0200 Subject: [PATCH 1/3] fix conversion for custom types --- src/types/conversion.jl | 2 +- src/utilities.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/conversion.jl b/src/types/conversion.jl index b49b02073..981f840ea 100644 --- a/src/types/conversion.jl +++ b/src/types/conversion.jl @@ -241,7 +241,7 @@ end balance_transform(sys::StateSpace, perm::Bool=false) = balance_transform(sys.A,sys.B,sys.C,perm) -convert(::Type{TransferFunction}, sys::AbstractStateSpace{TE}) where TE = convert(TransferFunction{TE,SisoRational}, sys) +convert(::Type{TransferFunction}, sys::AbstractStateSpace{TE}) where TE = convert(TransferFunction{TE,SisoRational{numeric_type(sys)}}, sys) function convert(::Type{TransferFunction{TE,SisoRational{T}}}, sys::AbstractStateSpace) where {TE,T<:Number} matrix = Matrix{SisoRational{T}}(undef, size(sys)) diff --git a/src/utilities.jl b/src/utilities.jl index b5fed1823..4a725707f 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -8,7 +8,7 @@ numeric_type(::Type{TransferFunction{TE,S}}) where {TE,S} = numeric_type(S) numeric_type(::Type{<:StateSpace{TE,T}}) where {TE,T} = T numeric_type(::Type{<:HeteroStateSpace{TE,AT}}) where {TE,AT} = eltype(AT) numeric_type(::Type{<:DelayLtiSystem{T}}) where {T} = T -numeric_type(sys::LTISystem) = numeric_type(typeof(sys)) +numeric_type(sys::LTISystem) = eltype(sys.A) to_matrix(T, A::AbstractVector) = Matrix{T}(reshape(A, length(A), 1)) From 12ebf633ab2fa5a8dd09abb220c135597db8850e Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Thu, 20 May 2021 13:55:56 +0200 Subject: [PATCH 2/3] special numeric_type for AbstractSS --- src/utilities.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utilities.jl b/src/utilities.jl index 4a725707f..ef4842a4f 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -8,7 +8,8 @@ numeric_type(::Type{TransferFunction{TE,S}}) where {TE,S} = numeric_type(S) numeric_type(::Type{<:StateSpace{TE,T}}) where {TE,T} = T numeric_type(::Type{<:HeteroStateSpace{TE,AT}}) where {TE,AT} = eltype(AT) numeric_type(::Type{<:DelayLtiSystem{T}}) where {T} = T -numeric_type(sys::LTISystem) = eltype(sys.A) +numeric_type(sys::AbstractStateSpace) = eltype(sys.A) +numeric_type(sys::LTISystem) = numeric_type(typeof(sys)) to_matrix(T, A::AbstractVector) = Matrix{T}(reshape(A, length(A), 1)) From b8a020723923d0145895b2f76eb607f7cea9f780 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Thu, 27 May 2021 06:38:54 +0200 Subject: [PATCH 3/3] fix conversion from ss to tf without type --- src/types/tf.jl | 2 +- test/framework.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/tf.jl b/src/types/tf.jl index be833b4f1..726f727b2 100644 --- a/src/types/tf.jl +++ b/src/types/tf.jl @@ -66,7 +66,7 @@ tf(D::AbstractArray{T}) where T = tf(D, Continuous()) tf(n::Number, args...; kwargs...) = tf([n], args...; kwargs...) -tf(sys::AbstractStateSpace) = convert(TransferFunction, sys) # NOTE: Would perhaps like to write TransferFunction{SisoRational}, but couldn't get this to work... +tf(sys::AbstractStateSpace{TE}) where TE = convert(TransferFunction{TE, SisoRational{float(numeric_type(sys))}}, sys) # the call to float is required since an eigenvalue-computation is performed that produces floats from Ints etc. function tf(G::TransferFunction{TE,<:SisoTf{T}}) where {TE<:TimeEvolution,T<:Number} convert(TransferFunction{TE,SisoRational{T}}, G) diff --git a/test/framework.jl b/test/framework.jl index de37bca77..314a7af04 100644 --- a/test/framework.jl +++ b/test/framework.jl @@ -1,3 +1,4 @@ +using ControlSystems # Local definition to make sure we get warnings if we use eye eye_(n) = Matrix{Int64}(I, n, n)