Skip to content

Commit 732cabe

Browse files
committed
do not promote system type when creating a vector
1 parent 5b2b96d commit 732cabe

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

lib/ControlSystemsBase/src/ControlSystemsBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function __init__()
237237
print(io, " for automatic discretization (applicable to systems without delays or nonlinearities only).")
238238
end
239239
plots_id = Base.PkgId(UUID("91a5bcdd-55d7-5caf-9e0b-520d859cae80"), "Plots")
240-
if nameof(exc.f) === :plot && parentmodule(argtypes[1]) == @__MODULE__() && !haskey(Base.loaded_modules, plots_id)
240+
if exc.f !== nothing && nameof(exc.f) === :plot && parentmodule(argtypes[1]) == @__MODULE__() && !haskey(Base.loaded_modules, plots_id)
241241
printstyled(io, "\nPlotting is not available unless Plots.jl is loaded manually. Call `using Plots` before plotting.", color=:green, bold=true)
242242
elseif (exc.f == /) && argtypes[2] <: DelayLtiSystem
243243
print(io, "A delayed system can not be inverted. Consider use of the function `feedback`.")

lib/ControlSystemsBase/src/connections.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ end
138138
Base.typed_hcat(::Type{S}, X::Number...) where {S<:LTISystem} = hcat(convert.(S, X)...)
139139
Base.typed_hcat(::Type{S}, X::Union{AbstractArray{<:Number,1}, AbstractArray{<:Number,2}}...) where {S<:LTISystem} = hcat(convert.(S, X)...)
140140

141+
## Mixed-type array creation
142+
# When creating an array of systems, an error may be thrown if the default Base.vect is called that tries to promote all systems to a common type. E.g., when using non-proper transfer functions and statespace systems. We thus opt out of the conversion with the method below
143+
function Base.vect(X::LTISystem...)
144+
LTISystem[X...]
145+
end
146+
147+
141148
"""
142149
add_input(sys::AbstractStateSpace, B2::AbstractArray, D2 = 0)
143150

lib/ControlSystemsBase/src/types/conversion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ function siso_tf_to_ss(T::Type, f::SisoRational)
136136
num0, den0 = numvec(f), denvec(f)
137137
# Normalize the numerator and denominator to allow realization of transfer functions
138138
# that are proper, but not strictly proper
139-
num = num0 / den0[1]
140-
den = den0 / den0[1]
139+
num = num0 ./ den0[1]
140+
den = den0 ./ den0[1]
141141

142142
N = length(den) - 1 # The order of the rational function f
143143

lib/ControlSystemsBase/test/test_connections.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ P = ss(-1.0, 2.0, 3.0, 4.0)
148148
@test [2.5 P 3.5] == ss(-1.0, [0.0 2.0 0.0], 3.0, [2.5 4.0 3.5])
149149
@test [2.5; P; 3.5] == ss(-1.0, 2.0, [0.0; 3.0; 0.0], [2.5; 4.0; 3.5])
150150

151-
151+
# Test vector creation
152+
v = [ssrand(1,1,1), tf(1)]
153+
@test v isa Vector{LTISystem}
154+
@test v[1] isa StateSpace{Continuous, Float64}
155+
@test v[2] isa TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
152156

153157
# Combination tfRational and sisoZpk
154158
Czpk_111 = zpk([-2],[-5],1)

0 commit comments

Comments
 (0)