Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix transfer function colon indexing #872

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix transfer function colon indexing
  • Loading branch information
baggepinnen committed Sep 13, 2023
commit c185025875f120d08668f522411d58e584912251
6 changes: 5 additions & 1 deletion lib/ControlSystemsBase/src/types/TransferFunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ function Base.getindex(G::TransferFunction{TE,S}, inds...) where {TE,S<:SisoTf}
error("Must specify 2 indices to index TransferFunction model")
end
rows, cols = index2range(inds...)
mat = Matrix{S}(undef, length(rows), length(cols))
mat = Matrix{S}(
undef,
rows isa Colon ? noutputs(G) : length(rows),
cols isa Colon ? ninputs(G) : length(cols)
)
mat[:, :] = G.matrix[rows, cols]
return TransferFunction(mat, G.timeevol)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/ControlSystemsBase/test/test_transferfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ M = randn(2,1)
@test C_222[1,1] == tf([1, 2, 3], [1, 8, 15])
@test C_222[1:1,1] == tf([1, 2, 3], [1, 8, 15])
@test C_222[1,1:2] == C_221
@test C_222[1,:] == C_221
@test C_222[:,:] == C_222
@test size(C_222[1,[]]) == (1,0)

# Accessing Ts through .Ts
Expand Down