From 5fe8d3bde7479a3bb53563cfff838d5ea149e2ae Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Mon, 20 Jan 2025 13:46:18 +0100 Subject: [PATCH] handle identical types --- lib/ControlSystemsBase/src/connections.jl | 3 +++ lib/ControlSystemsBase/src/types/StateSpace.jl | 8 +++++++- lib/ControlSystemsBase/test/test_connections.jl | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ControlSystemsBase/src/connections.jl b/lib/ControlSystemsBase/src/connections.jl index 335ce4432..b002214c5 100644 --- a/lib/ControlSystemsBase/src/connections.jl +++ b/lib/ControlSystemsBase/src/connections.jl @@ -144,6 +144,9 @@ function Base.vect(X::LTISystem...) LTISystem[X...] end +function Base.vect(X::T...) where T <: LTISystem + T[X...] +end """ add_input(sys::AbstractStateSpace, B2::AbstractArray, D2 = 0) diff --git a/lib/ControlSystemsBase/src/types/StateSpace.jl b/lib/ControlSystemsBase/src/types/StateSpace.jl index a58967956..ee3c89a5f 100644 --- a/lib/ControlSystemsBase/src/types/StateSpace.jl +++ b/lib/ControlSystemsBase/src/types/StateSpace.jl @@ -248,7 +248,13 @@ end ## Approximate ## function isapprox(sys1::ST1, sys2::ST2; kwargs...) where {ST1<:AbstractStateSpace,ST2<:AbstractStateSpace} fieldnames(ST1) == fieldnames(ST2) || (return false) - return all(isapprox(getfield(sys1, f), getfield(sys2, f); kwargs...) for f in fieldnames(ST1)) + return all(fieldnames(ST1)) do f + if fieldtype(ST1, f) <: Union{Number, AbstractArray{<:Number}, LTISystem} + isapprox(getfield(sys1, f), getfield(sys2, f); kwargs...) + else + getfield(sys1, f) == getfield(sys2, f) + end + end end ## ADDITION ## diff --git a/lib/ControlSystemsBase/test/test_connections.jl b/lib/ControlSystemsBase/test/test_connections.jl index 84c5f985a..7a34969df 100644 --- a/lib/ControlSystemsBase/test/test_connections.jl +++ b/lib/ControlSystemsBase/test/test_connections.jl @@ -154,6 +154,10 @@ v = [ssrand(1,1,1), tf(1)] @test v[1] isa StateSpace{Continuous, Float64} @test v[2] isa TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}} +# Test vector creation +v = [tf(1), tf(1)] +@test v isa Vector{TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}} + # Combination tfRational and sisoZpk Czpk_111 = zpk([-2],[-5],1) Czpk_211 = zpk([-1+sqrt(2)im,-1-sqrt(2)im], [-5,-3],1)