Skip to content

Commit 601f95f

Browse files
authored
Updates to work with julia 0.5 (#84)
* Updates to work with julia 0.5 * Updated version in travis, and minor typo * Tests pass even if ControlExamplePlots is missing * Minor depwarn fix
1 parent b7afcae commit 601f95f

29 files changed

+164
-227
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: julia
22
julia:
3-
- 0.4
3+
- 0.5
44
notifications:
55
email: false
66
script:

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
julia 0.4
1+
julia 0.5-
22
Plots v0.7.4
33
Polynomials

src/ControlSystems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export LTISystem,
6363
denpoly
6464

6565
import Plots
66-
import Base: +, -, *, /, (./), (==), (.+), (.-), (.*), (!=), isapprox, call, convert
66+
import Base: +, -, *, /, (./), (==), (.+), (.-), (.*), (!=), isapprox, call, convert, promote_op
6767

6868
include("types/lti.jl")
6969
include("types/transferfunction.jl")

src/connections.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Base.vcat(systems::StateSpace...)
7272
outputs = vcat([s.outputnames for s in systems]...)
7373
inputs = systems[1].inputnames
7474
if !all([s.inputnames == inputs for s in systems])
75-
inputs = fill(UTF8String(""),size(inputs, 1))
75+
inputs = fill(String(""),size(inputs, 1))
7676
end
7777
return StateSpace(A, B, C, D, Ts, states, inputs, outputs)
7878
end
@@ -91,7 +91,7 @@ function Base.vcat(systems::TransferFunction...)
9191
outputs = vcat([s.outputnames for s in systems]...)
9292
inputs = systems[1].inputnames
9393
if !all([s.inputnames == inputs for s in systems])
94-
inputs = fill(UTF8String(""),size(inputs, 1))
94+
inputs = fill(String(""),size(inputs, 1))
9595
end
9696
return TransferFunction(mat, Ts, inputs, outputs)
9797
end
@@ -124,7 +124,7 @@ function Base.hcat(systems::StateSpace...)
124124
inputs = vcat([s.inputnames for s in systems]...)
125125
outputs = systems[1].outputnames
126126
if !all([s.outputnames == outputs for s in systems])
127-
outputs = fill(UTF8String(""),size(outputs, 1))
127+
outputs = fill(String(""),size(outputs, 1))
128128
end
129129
return StateSpace(A, B, C, D, Ts, states, inputs, outputs)
130130
end
@@ -143,7 +143,7 @@ function Base.hcat(systems::TransferFunction...)
143143
inputs = vcat([s.inputnames for s in systems]...)
144144
outputs = systems[1].outputnames
145145
if !all([s.outputnames == outputs for s in systems])
146-
outputs = fill(UTF8String(""),size(outputs, 1))
146+
outputs = fill(String(""),size(outputs, 1))
147147
end
148148
return TransferFunction(mat, Ts, inputs, outputs)
149149
end

src/freqresp.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ Notation for frequency response evaluation.
8585
- F(omega,true) evaluates the discrete-time transfer function F at i*Ts*omega
8686
- F(z,false) evaluates the discrete-time transfer function F at z
8787
""" ->
88-
function Base.call(sys::TransferFunction, s)
88+
function (sys::TransferFunction)(s)
8989
evalfr(sys,s)
9090
end
9191

92-
function Base.call(sys::TransferFunction, z_or_omega::Number, map_to_unit_circle::Bool)
92+
function (sys::TransferFunction)(z_or_omega::Number, map_to_unit_circle::Bool)
9393
@assert !iscontinuous(sys) "It makes no sense to call this function with continuous systems"
9494
if map_to_unit_circle
9595
isreal(z_or_omega) ? evalfr(sys,exp(im*z_or_omega.*sys.Ts)) : error("To map to the unit circle, omega should be real")
@@ -98,7 +98,7 @@ function Base.call(sys::TransferFunction, z_or_omega::Number, map_to_unit_circle
9898
end
9999
end
100100

101-
function Base.call(sys::TransferFunction, s::AbstractVector, map_to_unit_circle::Bool)
101+
function (sys::TransferFunction)(s::AbstractVector, map_to_unit_circle::Bool)
102102
@assert !iscontinuous(sys) "It makes no sense to call this function with continuous systems"
103103
freqresp(sys,s)
104104
end
@@ -138,7 +138,7 @@ function sigma(sys::LTISystem, w::AbstractVector)
138138
nw, ny, nu = size(resp)
139139
sv = Array(Float64, nw, min(ny, nu))
140140
for i=1:nw
141-
sv[i, :] = svdvals(squeeze(resp[i, :, :],(1)))
141+
sv[i, :] = svdvals(resp[i, :, :])
142142
end
143143
return sv, w
144144
end

src/matrix_comps.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ Compute a similarity transform `T` resulting in `B = T\\A*T` such that the row
284284
and column norms of `B` are approximately equivalent. If `perm=false`, the
285285
transformation will only scale, and not permute `A`.""" ->
286286
function balance(A, perm::Bool=true)
287-
n = Base.LinAlg.chksquare(A)
287+
n = Base.LinAlg.checksquare(A)
288288
B = copy(A)
289289
job = perm ? 'B' : 'S'
290290
ilo, ihi, scaling = LAPACK.gebal!(job, B)

src/plotting.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ for (func, title) = ((:step, "Step Response"), (:impulse, "Impulse Response"))
8282
end
8383
ny, nu = size(systems[1])
8484
fig = Plots.plot(layout=(ny,nu))
85-
titles = fill("", ny*nu)
85+
titles = fill("", 1, ny*nu)
8686
s2i(i,j) = sub2ind((ny,nu),j,i)
8787
for (si,(s, Ts)) in enumerate(zip(systems, Ts_list))
8888
t = 0:Ts:Tf
@@ -98,7 +98,7 @@ for (func, title) = ((:step, "Step Response"), (:impulse, "Impulse Response"))
9898
end
9999
end
100100
end
101-
Plots.plot!(fig, title=titles')
101+
Plots.plot!(fig, title=titles)
102102
return fig
103103
end
104104
$funcname{T<:LTISystem}(systems::Vector{T}, Tf::Real; kwargs...) =

src/types/statespace.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ type StateSpace <: LTISystem
1111
nx::Int
1212
nu::Int
1313
ny::Int
14-
statenames::Vector{UTF8String}
15-
inputnames::Vector{UTF8String}
16-
outputnames::Vector{UTF8String}
14+
statenames::Vector{String}
15+
inputnames::Vector{String}
16+
outputnames::Vector{String}
1717

1818
function StateSpace(A::Matrix{Float64}, B::Matrix{Float64},
1919
C::Matrix{Float64}, D::Matrix{Float64}, Ts::Float64,
20-
statenames::Vector{UTF8String}, inputnames::Vector{UTF8String},
21-
outputnames::Vector{UTF8String})
20+
statenames::Vector{String}, inputnames::Vector{String},
21+
outputnames::Vector{String})
2222
nx = size(A, 1)
2323
nu = size(B, 2)
2424
ny = size(C, 1)
@@ -52,8 +52,8 @@ type StateSpace <: LTISystem
5252
end
5353

5454
function StateSpace(A::Array, B::Array, C::Array, D::Array, Ts::Real,
55-
statenames::Vector{UTF8String}, inputnames::Vector{UTF8String},
56-
outputnames::Vector{UTF8String})
55+
statenames::Vector{String}, inputnames::Vector{String},
56+
outputnames::Vector{String})
5757
return StateSpace(float64mat(A), float64mat(B), float64mat(C),
5858
float64mat(D), map(Float64, Ts), statenames, inputnames, outputnames)
5959
end
@@ -182,14 +182,14 @@ function +(s1::StateSpace, s2::StateSpace)
182182
elseif all(s2.inputnames .== "") || (s1.inputnames == s2.inputnames)
183183
inputnames = s1.inputnames
184184
else
185-
inputnames = fill(UTF8String(""),s1.ny)
185+
inputnames = fill(String(""),s1.ny)
186186
end
187187
if all(s1.outputnames .== "")
188188
outputnames = s2.outputnames
189189
elseif all(s2.outputnames .== "") || (s1.outputnames == s2.outputnames)
190190
outputnames = s1.outputnames
191191
else
192-
outputnames = fill(UTF8String(""),s1.nu)
192+
outputnames = fill(String(""),s1.nu)
193193
end
194194
return StateSpace(A, B, C, D, s1.Ts, statenames, inputnames, outputnames)
195195
end
@@ -260,7 +260,7 @@ function Base.getindex(s::StateSpace, inds...)
260260
if size(inds, 1) != 2
261261
error("Must specify 2 indices to index statespace model")
262262
end
263-
rows, cols = inds
263+
rows, cols = ControlSystems.index2range(inds...)
264264
return StateSpace([s.A;], [s.B[:, cols];], [s.C[rows, :];], [s.D[rows, cols];],
265265
s.Ts, [s.statenames;], [s.inputnames[cols];], [s.outputnames[rows];])
266266
end
@@ -270,11 +270,11 @@ end
270270
#####################################################################
271271

272272
# TODO : this is a very hacky way of handling StateSpace printing.
273-
function _string_mat_with_headers(X::Matrix, cols::Vector{UTF8String},
274-
rows::Vector{UTF8String})
275-
mat = [[""] cols';
273+
function _string_mat_with_headers(X::Matrix, cols::Vector{String},
274+
rows::Vector{String})
275+
mat = [[""] reshape(cols,1,length(cols));
276276
rows X]
277-
p = (io, m) -> Base.showarray(io, m, header=false, repr=false)
277+
p = (io, m) -> Base.showarray(io, m, false, header=false)
278278
return replace(sprint(p, mat), "\"", " ")
279279
end
280280

src/types/tf2ss.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function ss2tf(A, B, C, D, Ts = 0; inputnames = "", outputnames = "")
145145
ubernum = Matrix{Vector}(ny,nu)
146146
uberden = Matrix{Vector}(ny,nu)
147147
for i = 1:nu, j=1:ny
148-
ubernum[j,i],uberden[j,i] = sisoss2tf(A, B[:,i], C[j,:], D[j,i])
148+
ubernum[j,i],uberden[j,i] = sisoss2tf(A, B[:,i], C[j,:]', D[j,i])
149149
end
150150
tf(ubernum,uberden, Ts, inputnames=inputnames, outputnames=outputnames)
151151
end

src/types/transferfunction.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ type TransferFunction{S<:SisoTf} <: LTISystem
1212
Ts::Float64
1313
nu::Int
1414
ny::Int
15-
inputnames::Vector{UTF8String}
16-
outputnames::Vector{UTF8String}
15+
inputnames::Vector{String}
16+
outputnames::Vector{String}
1717
function TransferFunction{T<:SisoTf}(matrix::Matrix{T}, Ts::Float64,
18-
inputnames::Vector{UTF8String}, outputnames::Vector{UTF8String})
18+
inputnames::Vector{String}, outputnames::Vector{String})
1919
# Validate size of input and output names
2020
ny, nu = size(matrix)
2121
if size(inputnames, 1) != nu
@@ -81,7 +81,6 @@ Base.convert(::Type{SisoGeneralized}, sys::SisoZpk) = convert(SisoGeneralized, c
8181

8282
Base.convert(::Type{SisoRational}, sys::SisoGeneralized) = SisoRational(sys.expr)
8383
Base.convert(::Type{SisoZpk}, sys::SisoGeneralized) = convert(SisoZpk, SisoRational(sys.expr))
84-
Base.convert(::Type{TransferFunction{SisoZpk}}, s::TransferFunction) = zpk(s)
8584

8685
#Just default SisoTf to SisoRational
8786
SisoTf(args...) = SisoRational(args...)
@@ -116,6 +115,10 @@ tzero(sys::SisoTf) = error("tzero is not implemented for type $(typeof(sys))")
116115
==(a::SisoTf, b::SisoTf) = ==(promote(a,b)...)
117116
!=(a::SisoTf, b::SisoTf) = !(a==b)
118117
isapprox(a::SisoTf, b::SisoTf; kwargs...) = isapprox(promote(a,b)...; kwargs...)
118+
119+
# Promote_op types
120+
Base.promote_op{T<:SisoTf}(::Any, ::Type{T}, ::Type{T}) = T
121+
119122
#####################################################################
120123
## Constructor Functions ##
121124
#####################################################################
@@ -319,11 +322,11 @@ function Base.getindex(t::TransferFunction, inds...)
319322
if size(inds, 1) != 2
320323
error("Must specify 2 indices to index TransferFunction model")
321324
end
322-
rows, cols = inds
325+
rows, cols = ControlSystems.index2range(inds...)
323326
mat = Array(eltype(t.matrix), length(rows), length(cols))
324327
mat[:, :] = t.matrix[rows, cols]
325-
innames = UTF8String[t.inputnames[i] for i in cols]
326-
outnames = UTF8String[t.outputnames[i] for i in rows]
328+
innames = String[t.inputnames[i] for i in cols]
329+
outnames = String[t.outputnames[i] for i in rows]
327330
return TransferFunction(mat, t.Ts, innames, outnames)
328331
end
329332

@@ -397,14 +400,14 @@ function +(t1::TransferFunction, t2::TransferFunction)
397400
elseif all(t2.inputnames .== "") || (t1.inputnames == t2.inputnames)
398401
inputnames = t1.inputnames
399402
else
400-
inputnames = fill(UTF8String(""),t1.ny)
403+
inputnames = fill(String(""),t1.ny)
401404
end
402405
if all(t1.outputnames .== "")
403406
outputnames = t2.outputnames
404407
elseif all(t2.outputnames .== "") || (t1.outputnames == t2.outputnames)
405408
outputnames = t1.outputnames
406409
else
407-
outputnames = fill(UTF8String(""),t1.nu)
410+
outputnames = fill(String(""),t1.nu)
408411
end
409412
t1, t2 = promote(t1, t2)
410413
matrix = t1.matrix + t2.matrix

0 commit comments

Comments
 (0)