diff --git a/src/named_systems2.jl b/src/named_systems2.jl index b96a88d6..516e3a07 100644 --- a/src/named_systems2.jl +++ b/src/named_systems2.jl @@ -864,6 +864,8 @@ end names2indices(::Colon, allnames) = 1:length(allnames) +names2indices(inds::Union{Integer, AbstractVector{<:Int}}, allnames) = inds + function names2indices(names, allnames) inds = Union{Nothing, Int}[findfirst(==(n), allnames) for n in names] snames = string.(allnames) @@ -980,6 +982,10 @@ function partition(P::NamedStateSpace; u=nothing, y=nothing, y = setdiff(1:P.ny, inds) z = inds end + u = names2indices(identity.(u), P.u) + y = names2indices(identity.(y), P.y) + z = names2indices(identity.(z), P.y) + w = names2indices(identity.(w), P.u) u = vcat(u) y = vcat(y) z = vcat(z) diff --git a/test/test_named_systems2.jl b/test/test_named_systems2.jl index 20a9b95b..869b2fdd 100644 --- a/test/test_named_systems2.jl +++ b/test/test_named_systems2.jl @@ -43,6 +43,10 @@ s3 = named_ss(G3, x = :x, u = :u, y=:y, z=:z, w=:w) @test length(s3.u) == 3 @test length(s3.y) == 2 +s3part = partition(s3, y=:y, z=:z, w=:w, u=:u) +@test s3part == G3 +@test performance_mapping(s3part) == s3[:z, :w].sys + # Test prefix matching G4 = ControlSystemsBase.ssrand(1,2,3) s4 = named_ss(G4, x = :x, u = [:u1, :u2], y=[:y])