Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/named_systems2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ function merge_nonunique_inputs(sys)
# Check that the B-matrix entries are non-overlapping
Bi = sys.B[:, inds]
Di = sys.D[:, inds]
any(>(1), sum(.! iszero.(Bi), dims=2)) && @warn("Input names are not unique and the multiple B-matrix columns associated with the name $(u[i]) have a non-empty intersection of non-zero entries.")
any(>(1), sum(.! iszero.(Di), dims=2)) && @warn("Input names are not unique and the multiple D-matrix columns associated with the name $(u[i]) have a non-empty intersection of non-zero entries.")
any(>(1), sum(.! iszero.(Bi), dims=2)) && @warn("Input names are not unique and the multiple B-matrix columns associated with the name $(inputnames[i]) have a non-empty intersection of non-zero entries.")
any(>(1), sum(.! iszero.(Di), dims=2)) && @warn("Input names are not unique and the multiple D-matrix columns associated with the name $(inputnames[i]) have a non-empty intersection of non-zero entries.")
B = copy(sys.B)
D = copy(sys.D)
B[:, inds[1]] = sum(Bi, dims=2)
Expand Down
17 changes: 16 additions & 1 deletion test/test_named_systems2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,19 @@ isys = 2/s1
# Test https://github.com/JuliaControl/RobustAndOptimalControl.jl/issues/130
P = named_ss(ssrand(1,1,2, Ts=1.0))
C = named_ss(ssrand(1,1,2, Ts=1.0))
@test gangoffour(P, C) isa NTuple{4, NamedStateSpace{Discrete{Float64}, StateSpace{Discrete{Float64}, Float64}}}
@test gangoffour(P, C) isa NTuple{4, NamedStateSpace{Discrete{Float64}, StateSpace{Discrete{Float64}, Float64}}}

## merge_nonunique_inputs: warning path must not crash on overlapping B/D columns
# Regression: previous code interpolated an undefined variable `u` and raised
# UndefVarError instead of issuing the documented warning.
let
A = -I(2)
B = [1.0 1.0; 0.0 1.0] # both columns nonzero in row 1 -> overlap
C = [1.0 0.0]
D = [0.0 0.0]
nsys = named_ss(ss(A, B, C, D); u=[:u_dup, :u_dup], y=:y, unique=false)
merged = @test_logs (:warn, r"B-matrix columns") RobustAndOptimalControl.merge_nonunique_inputs(nsys)
@test merged.nu == 1
@test merged.u == [:u_dup]
@test merged.B == sum(B, dims=2)
end
Loading