Skip to content

Commit

Permalink
Avoid deprecation warnings concerning inner constructors on Julia 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Jan 31, 2017
1 parent 505ccfe commit 6596b21
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/ACME.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ type DiscreteModel{Solver}
solver::Solver
x::Vector{Float64}

function DiscreteModel(circ::Circuit, t::Float64)
@compat function (::Type{DiscreteModel{Solver}}){Solver}(circ::Circuit, t::Float64)
Base.depwarn("DiscreteModel{Solver}(circ, t) is deprecated, use DiscreteModel(circ, t, Solver) instead.",
:DiscreteModel)
DiscreteModel(circ, t, Solver)
end

function DiscreteModel(mats::Dict{Symbol}, nonlinear_eq::Expr, solver::Solver)
model = new()
@compat function (::Type{DiscreteModel{Solver}}){Solver}(mats::Dict{Symbol}, nonlinear_eq::Expr, solver::Solver)
model = new{Solver}()

for mat in (:a, :b, :c, :pexp, :dq, :eq, :fq, :dy, :ey, :fy, :x0, :q0, :y0)
setfield!(model, mat, convert(fieldtype(typeof(model), mat), mats[mat]))
Expand Down Expand Up @@ -584,12 +584,12 @@ immutable ModelRunner{Model<:DiscreteModel,ShowProgress}
p::Vector{Float64}
ycur::Vector{Float64}
xnew::Vector{Float64}
function ModelRunner(model::Model)
@compat function (::Type{ModelRunner{Model,ShowProgress}}){Model<:DiscreteModel,ShowProgress}(model::Model)
ucur = Array{Float64,1}(nu(model))
p = Array{Float64,1}(np(model))
ycur = Array{Float64,1}(ny(model))
xnew = Array{Float64,1}(nx(model))
return new(model, ucur, p, ycur, xnew)
return new{Model,ShowProgress}(model, ucur, p, ycur, xnew)
end
end

Expand Down
41 changes: 23 additions & 18 deletions src/solvers.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Martin Holters
# Copyright 2016, 2017 Martin Holters
# See accompanying license file.

export SimpleSolver, HomotopySolver, CachingSolver
Expand All @@ -12,12 +12,16 @@ type ParametricNonLinEq{F_eval<:Function,F_setp<:Function,F_calcjp<:Function,Scr
Jp::Matrix{Float64}
J::Matrix{Float64}
scratch::Scratch
function ParametricNonLinEq(func::F_eval, set_p::F_setp, calc_Jp::F_calcjp,
scratch::Scratch, nn::Integer, np::Integer)
@compat function (::Type{ParametricNonLinEq{F_eval,F_setp,F_calcjp,Scratch}}){
F_eval<:Function,F_setp<:Function,F_calcjp<:Function,Scratch
}(
func::F_eval, set_p::F_setp, calc_Jp::F_calcjp, scratch::Scratch,
nn::Integer, np::Integer
)
res = zeros(nn)
Jp = zeros(nn, np)
J = zeros(nn, nn)
return new(func, set_p, calc_Jp, res, Jp, J, scratch)
return new{F_eval,F_setp,F_calcjp,Scratch}(func, set_p, calc_Jp, res, Jp, J, scratch)
end
end
ParametricNonLinEq{F_eval<:Function,F_setp<:Function,F_calcjp<:Function,
Expand Down Expand Up @@ -113,8 +117,8 @@ type SimpleSolver{NLEQ<:ParametricNonLinEq}
tol::Float64
tmp_nn::Vector{Float64}
tmp_np::Vector{Float64}
function SimpleSolver(nleq::NLEQ, initial_p::Vector{Float64},
initial_z::Vector{Float64})
@compat function (::Type{SimpleSolver{NLEQ}}){NLEQ<:ParametricNonLinEq}(
nleq::NLEQ, initial_p::Vector{Float64}, initial_z::Vector{Float64})
z = zeros(nn(nleq))
linsolver = LinearSolver(nn(nleq))
last_z = zeros(nn(nleq))
Expand All @@ -123,8 +127,8 @@ type SimpleSolver{NLEQ<:ParametricNonLinEq}
last_linsolver = LinearSolver(nn(nleq))
tmp_nn = zeros(nn(nleq))
tmp_np = zeros(np(nleq))
solver = new(nleq, z, linsolver, last_z, last_p, last_Jp, last_linsolver,
0, 0.0, 1e-20, tmp_nn, tmp_np)
solver = new{NLEQ}(nleq, z, linsolver, last_z, last_p, last_Jp,
last_linsolver, 0, 0.0, 1e-20, tmp_nn, tmp_np)
set_extrapolation_origin(solver, initial_p, initial_z)
return solver
end
Expand Down Expand Up @@ -201,12 +205,13 @@ type HomotopySolver{BaseSolver}
start_p::Vector{Float64}
pa::Vector{Float64}
iters::Int
function HomotopySolver(basesolver::BaseSolver, np::Integer)
return new(basesolver, zeros(np), zeros(np), 0)
@compat function (::Type{HomotopySolver{BaseSolver}}){BaseSolver}(
basesolver::BaseSolver, np::Integer)
return new{BaseSolver}(basesolver, zeros(np), zeros(np), 0)
end
function HomotopySolver(nleq::ParametricNonLinEq,
initial_p::Vector{Float64},
initial_z::Vector{Float64})
@compat function (::Type{HomotopySolver{BaseSolver}}){BaseSolver}(
nleq::ParametricNonLinEq, initial_p::Vector{Float64},
initial_z::Vector{Float64})
basesolver = BaseSolver(nleq, initial_p, initial_z)
return HomotopySolver{typeof(basesolver)}(basesolver, np(nleq))
end
Expand Down Expand Up @@ -274,15 +279,15 @@ type CachingSolver{BaseSolver}
new_count::Int
new_count_limit::Int
alts::Alts{Float64}
function CachingSolver(basesolver::BaseSolver, initial_p::Vector{Float64},
initial_z::Vector{Float64}, nn::Integer)
@compat function (::Type{CachingSolver{BaseSolver}}){BaseSolver}(basesolver::BaseSolver,
initial_p::Vector{Float64}, initial_z::Vector{Float64}, nn::Integer)
ps_tree = KDTree(hcat(initial_p))
zs = reshape(copy(initial_z), nn, 1)
alts = Alts(initial_p)
return new(basesolver, ps_tree, zs, 1, 0, 2, alts)
return new{BaseSolver}(basesolver, ps_tree, zs, 1, 0, 2, alts)
end
function CachingSolver(nleq::ParametricNonLinEq, initial_p::Vector{Float64},
initial_z::Vector{Float64})
@compat function (::Type{CachingSolver{BaseSolver}}){BaseSolver}(nleq::ParametricNonLinEq,
initial_p::Vector{Float64}, initial_z::Vector{Float64})
basesolver = BaseSolver(nleq, initial_p, initial_z)
return CachingSolver{typeof(basesolver)}(basesolver, initial_p, initial_z, nn(nleq))
end
Expand Down

0 comments on commit 6596b21

Please sign in to comment.