diff --git a/lib/ControlSystemsBase/src/types/StateSpace.jl b/lib/ControlSystemsBase/src/types/StateSpace.jl index 2cd66eb09..45fae041a 100644 --- a/lib/ControlSystemsBase/src/types/StateSpace.jl +++ b/lib/ControlSystemsBase/src/types/StateSpace.jl @@ -564,18 +564,18 @@ end Base.print(io::IO, sys::AbstractStateSpace) = show(io, sys) function Base.show(io::IO, sys::AbstractStateSpace) - # Compose the name vectors - #inputs = format_names(s.inputnames, "u", "?") - #outputs = format_names(s.outputnames, "y", "?") - #println(io, "StateSpace:") println(io, typeof(sys)) + A, B, C, D = ssdata(sys) if nstates(sys) > 0 - #states = format_names(s.statenames, "x", "?") - println(io, "A = \n", _string_mat_with_headers(sys.A)) - println(io, "B = \n", _string_mat_with_headers(sys.B)) - println(io, "C = \n", _string_mat_with_headers(sys.C)) + length(A) < 200 ? println(io, "A = \n", _string_mat_with_headers(A)) : + println(io, "A = $(typeof(A))$(size(A))") + length(B) < 200 ? println(io, "B = \n", _string_mat_with_headers(B)) : + println(io, "B = $(typeof(B))$(size(B))") + length(C) < 200 ? println(io, "C = \n", _string_mat_with_headers(C)) : + println(io, "C = $(typeof(C))$(size(C))") end - println(io, "D = \n", _string_mat_with_headers(sys.D), "\n") + length(D) < 200 ? println(io, "D = \n", _string_mat_with_headers(D), "\n") : + println(io, "D = ", iszero(D) ? " 0" : "$(typeof(D))$(size(D))", "\n") # Print sample time if isdiscrete(sys) println(io, "Sample Time: ", sys.Ts, " (seconds)") diff --git a/lib/ControlSystemsBase/test/test_statespace.jl b/lib/ControlSystemsBase/test/test_statespace.jl index 0de7ed37e..4938923f0 100644 --- a/lib/ControlSystemsBase/test/test_statespace.jl +++ b/lib/ControlSystemsBase/test/test_statespace.jl @@ -221,6 +221,20 @@ @test sprint(show, C_022) == "StateSpace{Continuous, Float64}\nD = \n 4.0 0.0\n 0.0 4.0\n\nContinuous-time state-space model" @test sprint(show, D_022) == "StateSpace{Discrete{Float64}, Float64}\nD = \n 4.0 0.0\n 0.0 4.0\n\nSample Time: 0.005 (seconds)\nDiscrete-time state-space model" @test sprint(show, D_222) == "StateSpace{Discrete{Float64}, Float64}\nA = \n 0.2 -0.8\n -0.8 0.07\nB = \n 1.0 0.0\n 0.0 2.0\nC = \n 1.0 0.0\n 0.0 1.0\nD = \n 0.0 0.0\n 0.0 0.0\n\nSample Time: 0.005 (seconds)\nDiscrete-time state-space model" + + # Large systems use a compressed format + G_large_zeroD = ss(zeros(15,15), zeros(15,15), zeros(15,15), zeros(15,15)) + @test sprint(show, G_large_zeroD) == "StateSpace{Continuous, Float64}\nA = Matrix{Float64}(15, 15)\nB = Matrix{Float64}(15, 15)\nC = Matrix{Float64}(15, 15)\nD = 0\n\nContinuous-time state-space model" + + G_large_nonzeroD = ss(zeros(15,15), zeros(15,15), zeros(15,15), ones(15,15)) + @test sprint(show, G_large_nonzeroD) == "StateSpace{Continuous, Float64}\nA = Matrix{Float64}(15, 15)\nB = Matrix{Float64}(15, 15)\nC = Matrix{Float64}(15, 15)\nD = Matrix{Float64}(15, 15)\n\nContinuous-time state-space model" + + G_large_A = ss(zeros(15,15), zeros(15,1), zeros(1,15), 0) + out_large_A = sprint(show, G_large_A) + @test occursin("A = Matrix{Float64}(15, 15)", out_large_A) + @test occursin("B = \n", out_large_A) + @test occursin("C = \n", out_large_A) + @test occursin("D = \n", out_large_A) end G = ssrand(1,2,3)