fix preprocessor tests for Julia 1.0

parent bd37417e
......@@ -30,7 +30,7 @@ end
export @compile, @dynare
type PreprocessorOptions
mutable struct PreprocessorOptions
debug::Bool
noclearall::Bool
onlyclearglobals::Bool
......@@ -108,7 +108,7 @@ end
Changes the value of option `name` in PreprocessorOptions object `opt`.
"""
function PreprocessorOptions!(opt::PreprocessorOptions, name::Symbol, value::Any)
if in(name, fieldnames(opt))
if in(name, fieldnames(typeof(opt)))
if isa(value, fieldtype(typeof(opt), name))
setfield!(opt, name, value)
else
......@@ -187,7 +187,7 @@ julia> Dynare.print(options)
function print(opt::PreprocessorOptions)
defaults = PreprocessorOptions()
optionstring = ""
for field in fieldnames(defaults)
for field in fieldnames(typeof(defaults))
if getfield(opt,field)==getfield(defaults,field)
# User did not change the default value of the preprocessor's option.
if field==:output
......@@ -262,9 +262,10 @@ Compiles `modfile` with `options`, calling the Dynare's preprocessor.
"""
function compile(modfile::AbstractString, options::PreprocessorOptions)
# Add current path to LOAD_PATH if necessary.
if isempty(findin([pwd()], LOAD_PATH))
unshift!(LOAD_PATH, pwd())
if isempty(findall((in)(LOAD_PATH), [pwd()]))
pushfirst!(LOAD_PATH, pwd())
end
# Append extension if necessary and check extension.
basename, ext = splitext(modfile)
if isempty(ext)
......@@ -301,16 +302,16 @@ Compiles `test1.mod` and `test2.mod` with options `:nograph` and `:json`, the ob
are respectively stored in a structures named `test1` and `test2`.
"""
macro dynare(modfiles::Expr, opts...)
if modfiles.head != :vect
error("Bad calling structure to @dynare")
end
options = SetPreprocessorOptions(opts...)
ex = Expr(:toplevel)
if modfiles.head==:vect
for i=1:length(modfiles.args)
compile(modfiles.args[i], options)
basename = split(modfiles.args[i], ".mod"; keep=false)
push!(ex.args, Expr(:import, Symbol(basename[1])))
end
return ex
args = Array{Expr}(undef, length(modfiles.args))
for i=1:length(modfiles.args)
compile(modfiles.args[i], options)
args[i] = Expr(:., Symbol(split(modfiles.args[i], ".mod"; keepempty=false)[1]))
end
return Expr(:import, args...)
end
"""
......@@ -325,16 +326,16 @@ Compiles `test1.mod` and `test2.mod` with default options, the objects model_, o
are respectively stored in a structures named `test1` and `test2`.
"""
macro dynare(modfiles::Expr)
if modfiles.head != :vect
error("Bad calling structure to @dynare")
end
options = PreprocessorOptions()
ex = Expr(:toplevel)
if modfiles.head==:vect
for i=1:length(modfiles.args)
compile(modfiles.args[i], options)
basename = split(modfiles.args[i], ".mod"; keep=false)
push!(ex.args, Expr(:import, Symbol(basename[1])))
end
return ex
args = Array{Expr}(undef, length(modfiles.args))
for i=1:length(modfiles.args)
compile(modfiles.args[i], options)
args[i] = Expr(:., Symbol(split(modfiles.args[i], ".mod"; keepempty=false)[1]))
end
return Expr(:import, args...)
end
"""
......@@ -350,11 +351,9 @@ Compiles `test1.mod` with options `:nograph` and `:json`, the objects model_, op
are stored in a structure named `test1`.
"""
macro dynare(modfile::AbstractString, opts...)
ex = Expr(:toplevel)
compile(modfile, SetPreprocessorOptions(opts...))
basename = split(modfile, ".mod"; keep=false)
push!(ex.args, Expr(:import, Symbol(basename[1])))
return ex
basename = split(modfile, ".mod"; keepempty=false)[1]
return Expr(:import, Expr(:., Symbol(basename)))
end
"""
......@@ -370,11 +369,9 @@ Compiles `test1.mod` with default options, the objects model_, options_ and oo_
are stored in a structure named `test1`.
"""
macro dynare(modfile::AbstractString)
ex = Expr(:toplevel)
compile(modfile, PreprocessorOptions())
basename = split(modfile, ".mod"; keep=false)
push!(ex.args, Expr(:import, Symbol(basename[1])))
return ex
basename = split(modfile, ".mod"; keepempty=false)[1]
return Expr(:import, Expr(:., Symbol(basename)))
end
"""
......
......@@ -22,31 +22,31 @@ export Model, Endo, Exo, ExoDet, Param, dynare_model
abstract type Atom end
immutable Endo <: Atom
struct Endo <: Atom
name::String
tex_name::String
long_name::String
end
immutable Exo <: Atom
struct Exo <: Atom
name::String
tex_name::String
long_name::String
end
immutable ExoDet <: Atom
struct ExoDet <: Atom
name::String
tex_name::String
long_name::String
end
immutable Param <: Atom
struct Param <: Atom
name::String
tex_name::String
long_name::String
end
immutable AuxVars
struct AuxVars
endo_index::Int
var_type::Int
orig_index::Int
......@@ -55,15 +55,15 @@ immutable AuxVars
orig_expr::String
end
immutable PredVars
struct PredVars
index::Int
end
immutable ObsVars
struct ObsVars
index::Int
end
immutable DetShocks
struct DetShocks
exo_det::Int
exo_id::Int
multiplicative::Bool
......@@ -71,18 +71,18 @@ immutable DetShocks
value::Float64
end
immutable EquationTag
struct EquationTag
eq_nbr::Int
name::String
value::String
end
type TemporariesInfo
mutable struct TemporariesInfo
static::Vector{Int}
dynamic::Vector{Int}
end
type Model
mutable struct Model
fname::String
dname::String
dynare_version::String
......@@ -146,65 +146,65 @@ type Model
end
function dynare_model()
return Model("", # fname
"", # dname
"", # dynare_version
Vector{Endo}(), # endo
0, # endo_nbr
Vector{Exo}(), # exo
0, # exo_nbr
Vector{ExoDet}(), # exo_det
0, # exo_det_nbr
Vector{Param}(), # param
0, # param_nbr
Vector{AuxVars}(), # aux_vars
Vector{Int}(), # pred_vars
Vector{Int}(), # obs_vars
Vector{Int}(), # state_var
0, # orig_endo_nbr
0, # orig_eq_nbr
0, # eq_nbr
0, # ramsey_eq_nbr
Vector{DetShocks}(), # det_shocks
0, # nstatic
0, # nfwrd
0, # npred
0, # nboth
0, # nsfwrd
0, # nspred
0, # ndynamic
0, # maximum_lag
0, # maximum_lead
0, # maximum_endo_lag
0, # maximum_endo_lead
0, # maximum_exo_lag
0, # maximum_exo_lead
0, # orig_maximum_lag
0, # orig_maximum_lead
0, # orig_maximum_endo_lag
0, # orig_maximum_endo_lead
0, # orig_maximum_exo_lag
0, # orig_maximum_exo_lead
0, # orig_maximum_exo_det_lag
0, # orig_maximum_exo_det_lead
Matrix{Int}(0,0), # lead_lag_incidence
zeros(Int64,3), # nnzderivatives
false, # analytical_steady_state
false, # user_written_analytical_steady_state
false, # static_and_dynamic_models_differ
Vector{String}(), # equation_tags
Vector{Int}(), # exo_names_orig_ord
Matrix{Float64}(0,0), # sigma_e (Cov matrix of the structural innovations)
Matrix{Float64}(0,0), # correlation_matrix (Corr matrix of the structural innovations)
Matrix{Float64}(0,0), # h (Cov matrix of the measurement errors)
Matrix{Float64}(0,0), # correlation_matrix_me (Cov matrix of the measurement errors)
true, # sigma_e_is_diagonal
Vector{Float64}(), # params
function()end, # static
function()end, # static_params_derivs
function()end, # dynamic
function()end, # dynamic_params_derivs
function()end, # steady_state
return Model("", # fname
"", # dname
"", # dynare_version
Vector{Endo}(), # endo
0, # endo_nbr
Vector{Exo}(), # exo
0, # exo_nbr
Vector{ExoDet}(), # exo_det
0, # exo_det_nbr
Vector{Param}(), # param
0, # param_nbr
Vector{AuxVars}(), # aux_vars
Vector{Int}(), # pred_vars
Vector{Int}(), # obs_vars
Vector{Int}(), # state_var
0, # orig_endo_nbr
0, # orig_eq_nbr
0, # eq_nbr
0, # ramsey_eq_nbr
Vector{DetShocks}(), # det_shocks
0, # nstatic
0, # nfwrd
0, # npred
0, # nboth
0, # nsfwrd
0, # nspred
0, # ndynamic
0, # maximum_lag
0, # maximum_lead
0, # maximum_endo_lag
0, # maximum_endo_lead
0, # maximum_exo_lag
0, # maximum_exo_lead
0, # orig_maximum_lag
0, # orig_maximum_lead
0, # orig_maximum_endo_lag
0, # orig_maximum_endo_lead
0, # orig_maximum_exo_lag
0, # orig_maximum_exo_lead
0, # orig_maximum_exo_det_lag
0, # orig_maximum_exo_det_lead
Matrix{Int}(undef,0,0), # lead_lag_incidence
zeros(Int64,3), # nnzderivatives
false, # analytical_steady_state
false, # user_written_analytical_steady_state
false, # static_and_dynamic_models_differ
Vector{String}(), # equation_tags
Vector{Int}(), # exo_names_orig_ord
Matrix{Float64}(undef,0,0), # sigma_e (Cov matrix of the structural innovations)
Matrix{Float64}(undef,0,0), # correlation_matrix (Corr matrix of the structural innovations)
Matrix{Float64}(undef,0,0), # h (Cov matrix of the measurement errors)
Matrix{Float64}(undef,0,0), # correlation_matrix_me (Cov matrix of the measurement errors)
true, # sigma_e_is_diagonal
Vector{Float64}(), # params
function()end, # static
function()end, # static_params_derivs
function()end, # dynamic
function()end, # dynamic_params_derivs
function()end, # steady_state
TemporariesInfo(zeros(Int,4),zeros(Int,4)) # temporaries
)
end
......
......@@ -20,7 +20,7 @@ module DynareOptions
export Options, dynare_options
type PFMSolver
mutable struct PFMSolver
maxit::Int
periods::Int
tolx::Float64
......@@ -35,7 +35,7 @@ function pfmsolver_set_defaults()
)
end
type Options
mutable struct Options
dynare_version::String
linear::Bool
pfmsolver::PFMSolver
......
......@@ -20,7 +20,7 @@ module DynareOutput
export Ouput, dynare_output
type Output
mutable struct Output
dynare_version::String
steady_state::Vector{Float64}
exo_steady_state::Vector{Float64}
......
......@@ -23,13 +23,15 @@ module DynareSolvers
export trustregion, TrustRegionWA
using LinearAlgebra
const p1 = .1
const p5 = .5
const p001 = .001
const p0001 = .0001
const macheps = eps(Float64)
type TrustRegionWA
mutable struct TrustRegionWA
x::Vector{Float64} # Vector of unknowns
xx::Vector{Float64} # Vector of unknowns
fval::Vector{Float64} # residuals of the non linear equations
......@@ -44,8 +46,9 @@ type TrustRegionWA
end
function TrustRegionWA(n::Int)
TrustRegionWA(Vector{Float64}(n), Vector{Float64}(n), Vector{Float64}(n), Vector{Float64}(n), Vector{Float64}(n), Matrix{Float64}(n,n),
Vector{Float64}(n), Vector{Float64}(n), Vector{Float64}(n), Vector{Float64}(n), Vector{Float64}(n))
TrustRegionWA(Vector{Float64}(undef,n), Vector{Float64}(undef,n), Vector{Float64}(undef,n), Vector{Float64}(undef,n),
Vector{Float64}(undef,n), Matrix{Float64}(undef,n,n), Vector{Float64}(undef,n), Vector{Float64}(undef,n),
Vector{Float64}(undef,n), Vector{Float64}(undef,n), Vector{Float64}(undef,n))
end
......
......@@ -20,7 +20,7 @@ module SteadyState
##
using DynareSolvers
using AutoAligns
using Printf
import DynareModel.Model
import DynareOutput.Output
......
......@@ -8,7 +8,7 @@ export brown, brown!, discreteboundaryvalue, discreteboundaryvalue!
export discreteintegralequation, discreteintegralequation!
export trigonometric, trigonometric!, variablydimensioned, variablydimensioned!
export broydentridiagonal, broydentridiagonal!
export broydenbanded, broydenbanded!
export broydenbanded, broydenbanded!
const ZERO = 0.0
const ONE = 1.0
......@@ -46,7 +46,7 @@ end
"""
rosenbrock!(fval::Vector{Float64}, x::Vector{Float64})
Evaluates the Rosenbrock function.
Evaluates the Rosenbrock function.
"""
function rosenbrock!(fval::Vector{Float64}, x::Vector{Float64})
fval[1] = ONE-x[1]
......@@ -56,7 +56,7 @@ end
"""
rosenbrock!(fval::Matrix{Float64}, x::Vector{Float64})
Evaluates the jacobian matrix of the Rosenbrock function.
Evaluates the jacobian matrix of the Rosenbrock function.
"""
function rosenbrock!(fjac::Matrix{Float64}, x::Vector{Float64})
fjac[1,1] = -ONE
......@@ -68,7 +68,7 @@ end
"""
rosenbrock()
Provides initial guess for solving the nonlinear system of equation based on the Rosenbrock function.
Provides initial guess for solving the nonlinear system of equation based on the Rosenbrock function.
"""
function rosenbrock()
return [-C1, ONE]
......@@ -216,7 +216,7 @@ function watson!(fjac::Matrix{Float64}, x::Vector{Float64})
tmp = ONE
for j=2:n
sum1 += Float64(j-1)*tmp*x[j]
tmp *= ti
tmp *= ti
end
sum2 = ZERO
tmp = ONE
......@@ -299,7 +299,7 @@ end
function chebyquad(n::Int)
h = ONE/Float64(n+1)
x = Vector{Float64}(n)
x = Vector{Float64}(undef,n)
for j=1:n
x[j] = Float64(j)*h
end
......@@ -346,7 +346,7 @@ function brown!(fjac::Matrix{Float64}, x::Vector{Float64})
end
function brown(n::Int)
x = Vector{Float64}(n)
x = Vector{Float64}(undef,n)
fill!(x, HALF)
return x
end
......@@ -365,7 +365,7 @@ function discreteboundaryvalue!(fval::Vector{Float64}, x::Vector{Float64})
if k!=n
tmp2 = x[k+1]
end
fval[k] = TWO*x[k]-tmp1-tmp2+tmp*hh/TWO
fval[k] = TWO*x[k]-tmp1-tmp2+tmp*hh/TWO
end
end
......@@ -388,7 +388,7 @@ end
function discreteboundaryvalue(n::Int)
h = ONE/Float64(n+1)
x = Vector{Float64}(n)
x = Vector{Float64}(undef,n)
for j=1:n
tj = Float64(j)*h
x[j] = tj*(tj-ONE)
......@@ -441,7 +441,7 @@ function trigonometric!(fval::Vector{Float64}, x::Vector{Float64})
sum = ZERO
for j=1:n
fval[j] = cos(x[j])
sum += fval[j]
sum += fval[j]
end
for k=1:n
fval[k] = Float64(n+k)-sin(x[k])-sum-Float64(k)*fval[k]
......@@ -460,7 +460,7 @@ function trigonometric!(fjac::Matrix{Float64}, x::Vector{Float64})
end
function trigonometric(n::Int)
x = Vector{Float64}(n)
x = Vector{Float64}(undef,n)
fill!(x, ONE/Float64(n))
return x
end
......@@ -495,7 +495,7 @@ end
function variablydimensioned(n::Int)
h = ONE/Float64(n)
x = Vector{Float64}(n)
x = Vector{Float64}(undef,n)
for j=1:n
x[j] = ONE-Float64(j)*h
end
......@@ -533,7 +533,7 @@ function broydentridiagonal!(fjac::Matrix{Float64}, x::Vector{Float64})
end
function broydentridiagonal(n::Int)
x = Vector{Float64}(n)
x = Vector{Float64}(undef,n)
fill!(x, -ONE)
return x
end
......
......@@ -13,7 +13,7 @@ import Base.LinAlg.BLAS.libblas
export QuasiUpperTriangular, I_plus_rA_ldiv_B!, I_plus_rA_plus_sB_ldiv_C!, A_rdiv_B!, A_rdiv_Bt!
immutable QuasiUpperTriangular{T<:Real,S<:AbstractMatrix} <: AbstractMatrix{T}
struct QuasiUpperTriangular{T<:Real,S<:AbstractMatrix} <: AbstractMatrix{T}
data::S
end
QuasiUpperTriangular(A::QuasiUpperTriangular) = A
......
......@@ -7,7 +7,7 @@ import Base.LinAlg.LAPACK: liblapack, chklapackerror
export QrWS, dgeqrf_core!, dormrqf_core!
type QrWS
mutable struct QrWS
tau::Vector{Float64}
work::Vector{Float64}
lwork::Ref{BlasInt}
......
......@@ -5,7 +5,7 @@ module SchurAlgo
include("exceptions.jl")
import Base: USE_BLAS64, LAPACKException
import Base.LinAlg: BlasInt, BlasFloat, checksquare, chkstride1
import Base.LinAlg: BlasInt, BlasFloat, checksquare, chkstride1
import Base.LinAlg.BLAS: @blasfunc, libblas
import Base.LinAlg.LAPACK: liblapack, chklapackerror
......@@ -29,7 +29,7 @@ end
const mycompare_c = cfunction(mycompare, Cint, (Ptr{Cdouble}, Ptr{Cdouble}))
const mycompare_g_c = cfunction(mycompare, Cint, (Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}))
type DgeesWS
mutable struct DgeesWS
jobvs::Ref{UInt8}
sdim::Ref{BlasInt}
wr::Vector{Float64}
......@@ -57,7 +57,7 @@ type DgeesWS
Ptr{Float64}, Ref{BlasInt}, Ptr{Int64},
Ref{BlasInt}),
jobvs, Rsort, mycompare_c,
n, A, RldA,
n, A, RldA,
sdim, wr, wi,
vs, ldvs,
work, lwork, bwork,
......@@ -115,7 +115,7 @@ function dgees!(ws::DgeesWS,A::StridedMatrix{Float64})
chklapackerror(ws.info[])
end
type DggesWS
mutable struct DggesWS
alphar::Vector{Float64}
alphai::Vector{Float64}
beta::Vector{Float64}
......
type SingularException <: Exception end
mutable struct SingularException <: Exception end
type DggesException <: Exception end
mutable struct DggesException <: Exception end
......@@ -6,7 +6,7 @@ import Base.LinAlg.BLAS: scal!, gemm!
export CyclicReductionWS, cyclic_reduction!, cyclic_reduction_check
type CyclicReductionWS
mutable struct CyclicReductionWS
linsolve_ws::LinSolveWS
ahat1::Matrix{Float64}
a1copy::Matrix{Float64}
......
......@@ -9,7 +9,7 @@ import Base.LinAlg.BLAS: scal!, gemm!
export GsSolverWS, gs_solver!
type GsSolverWS
mutable struct GsSolverWS
dgges_ws::DggesWS
linsolve_ws::LinSolveWS
D11::SubArray{Float64}
......@@ -24,7 +24,7 @@ type GsSolverWS
g1::Matrix{Float64}
g2::Matrix{Float64}
eigval::Vector{Complex64}
function GsSolverWS(d,e,n1)
dgges_ws = DggesWS(Ref{UInt8}('N'), Ref{UInt8}('N'), Ref{UInt8}('N'), e, d)
n = size(d,1)
......@@ -60,7 +60,7 @@ function gs_solver!(ws::GsSolverWS,d::Matrix{Float64},e::Matrix{Float64},n1::Int
dgges!('N', 'V', e, d, [0.0], ws.vsr, ws.eigval, ws.dgges_ws)
nstable = ws.dgges_ws.sdim[]
if nstable < n1
throw(UnstableSystemException)
elseif nstable > n1
......
......@@ -12,7 +12,7 @@ using Base.Test
import Base.LinAlg.BLAS: gemm!
export EyePlusAtKronBWS, generalized_sylvester_solver!, real_eliminate!, solvi, transformation1
immutable EyePlusAtKronBWS
struct EyePlusAtKronBWS
ma::Int64
mb::Int64
b1::Matrix{Float64}
......
type UnstableSystemException <: Exception end
mutable struct UnstableSystemException <: Exception end
type UndeterminateSystemException <: Exception end
mutable struct UndeterminateSystemException <: Exception end
# Put Dynare's sources in the path.
if isempty(findall((in)(LOAD_PATH), [abspath("$(@__DIR__)/../src")]))
pushfirst!(LOAD_PATH, abspath("$(@__DIR__)/../src"))
end
#=
** This script performs tests for nonlinear solvers.
** This script performs tests for nonlinear solvers.
**
** Copyright (C) 2018 Dynare Team
**
......@@ -22,11 +22,9 @@
rootdir = @__DIR__
origdir = pwd()
if isempty(findin([abspath("$(rootdir)/../../src")], LOAD_PATH))
unshift!(LOAD_PATH, abspath("$(rootdir)/../../src"))
end
include("../checkpath.jl")
using Base.Test
using Test
using TestFunctions
cd("$(rootdir)")
......@@ -35,8 +33,8 @@ cd("$(rootdir)")
@test begin
try
x = rosenbrock()
f = Vector{Float64}(2)
j = Matrix{Float64}(2,2)
f = Vector{Float64}(undef,2)
j = Matrix{Float64}(undef,2,2)