fix comments in generated files

time-shift
Houtan Bastani 2015-08-21 12:00:47 +02:00
parent 8715878971
commit 59122a1e73
4 changed files with 106 additions and 63 deletions

View File

@ -1575,7 +1575,11 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const
exit(EXIT_FAILURE);
}
output << "module " << basename << "Dynamic" << endl << endl
output << "module " << basename << "Dynamic" << endl
<< "#" << endl
<< "# NB: this file was automatically generated by Dynare" << endl
<< "# from " << basename << ".mod" << endl
<< "#" << endl
<< "using Utils" << endl << endl
<< "export dynamic!" << endl << endl;
writeDynamicModel(output, false, true);
@ -2365,16 +2369,29 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
}
else
{
ostringstream comments;
comments << "## Function Arguments" << endl
<< endl
<< "## Input" << endl
<< " 1 y: Array{Float64, num_dynamic_vars, 1} Vector of endogenous variables in the order stored" << endl
<< " in model.lead_lag_incidence; see the manual" << endl
<< " 2 x: Array{Float64, nperiods, length(model.exo)} Matrix of exogenous variables (in declaration order)" << endl
<< " for all simulation periods" << endl
<< " 3 params: Array{Float64, length(model.param), 1} Vector of parameter values in declaration order" << endl
<< " 4 steady_state:" << endl
<< " 5 it_: Int Time period for exogenous variables for which to evaluate the model" << endl
<< endl
<< "## Output" << endl
<< " 6 residual: Array(Float64, model.eq_nbr, 1) Vector of residuals of the dynamic model equations in" << endl
<< " order of declaration of the equations." << endl;
DynamicOutput << "function dynamic!(y::Vector{Float64}, x::Matrix{Float64}, "
<< "params::Vector{Float64}," << endl
<< " steady_state::Vector{Float64}, it_::Int, "
<< "residual::Vector{Float64})" << endl
<< "#" << endl
<< "# Function argument sizes:" << endl
<< "# residual: Array(Float64, model.eq_nbr, 1)" << endl
<< "#" << endl
<< "#=" << endl << comments.str() << "=#" << endl
<< "@assert size(residual) == " << nrows << endl
<< "fill!(residual, 0.0)" << endl << endl
<< "fill!(residual, 0.0)" << endl
<< "#" << endl
<< "# Model equations" << endl
<< "#" << endl
@ -2385,14 +2402,15 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
<< "params::Vector{Float64}," << endl
<< " steady_state::Vector{Float64}, it_::Int, "
<< "residual::Vector{Float64}," << endl
<< " g1::Matrix{Float64})" << endl
<< " #" << endl
<< " # Function argument sizes:" << endl
<< " # residual: Array(Float64, model.eq_nbr, 1)" << endl
<< " # g1: Array(Float64, model.eq_nbr, num_dynamic_endo_(+exo?)_vars)" << endl
<< " #" << endl
<< " g1::Matrix{Float64})" << endl;
comments << " 7 g1: Array(Float64, model.eq_nbr, num_dynamic_vars) Jacobian matrix of the dynamic model equations;" << endl
<< " rows: equations in order of declaration" << endl
<< " columns: variables in order stored in M_.lead_lag_incidence" << endl;
DynamicOutput << "#=" << endl << comments.str() << "=#" << endl
<< " @assert size(g1) == (" << nrows << ", " << dynJacobianColsNbr << ")" << endl
<< " fill!(g1, 0.0)" << endl << endl
<< " fill!(g1, 0.0)" << endl
<< " dynamic!(y, x, params, steady_state, it_, residual)" << endl
<< model_output.str()
<< " #" << endl
@ -2404,13 +2422,13 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
<< "params::Vector{Float64}," << endl
<< " steady_state::Vector{Float64}, it_::Int, "
<< "residual::Vector{Float64}," << endl
<< " g1::Matrix{Float64}, g2::Matrix{Float64})" << endl
<< " #" << endl
<< " # Function argument sizes:" << endl
<< " # residual: Array(Float64, model.eq_nbr, 1)" << endl
<< " # g1: Array(Float64, model.eq_nbr, num_dynamic_endo_(+exo?)_vars)" << endl
<< " # g2: spzeros(model.eq_nbr, (num_dynamic_endo_(+exo?)_vars)^2)" << endl
<< " #" << endl << endl
<< " g1::Matrix{Float64}, g2::Matrix{Float64})" << endl;
comments << " 8 g2: spzeros(model.eq_nbr, (num_dynamic_vars)^2) Hessian matrix of the dynamic model equations;" << endl
<< " rows: equations in order of declaration" << endl
<< " columns: variables in order stored in M_.lead_lag_incidence" << endl;
DynamicOutput << "#=" << endl << comments.str() << "=#" << endl
<< " @assert size(g2) == (" << nrows << ", " << hessianColsNbr << ")" << endl
<< " dynamic!(y, x, params, steady_state, it_, residual, g1)" << endl;
if (second_derivatives.size())
@ -2427,14 +2445,13 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
<< "params::Vector{Float64}," << endl
<< " steady_state::Vector{Float64}, it_::Int, "
<< "residual::Vector{Float64}," << endl
<< " g1::Matrix{Float64}, g2::Matrix{Float64}, g3::Matrix{Float64})" << endl
<< " #" << endl
<< " # Function argument sizes:" << endl
<< " # residual: Array(Float64, model.eq_nbr, 1)" << endl
<< " # g1: Array(Float64, model.eq_nbr, num_dynamic_endo_(+exo?)_vars)" << endl
<< " # g2: spzeros(model.eq_nbr, (num_dynamic_endo_(+exo?)_vars)^2)" << endl
<< " # g3: spzeros(model.eq_nbr, (num_dynamic_endo_(+exo?)_vars)^3)" << endl
<< " #" << endl << endl
<< " g1::Matrix{Float64}, g2::Matrix{Float64}, g3::Matrix{Float64})" << endl;
comments << " 9 g3: spzeros(model.eq_nbr, (num_dynamic_vars)^3) Third order derivative matrix of the dynamic model equations;" << endl
<< " rows: equations in order of declaration" << endl
<< " columns: variables in order stored in M_.lead_lag_incidence" << endl;
DynamicOutput << "#=" << endl << comments.str() << "=#" << endl
<< " @assert size(g3) == (" << nrows << ", " << ncols << ")" << endl
<< " dynamic!(y, x, params, steady_state, it_, residual, g1, g2)" << endl;
if (third_derivatives.size())
@ -3934,7 +3951,11 @@ DynamicModel::writeParamsDerivativesFile(const string &basename, bool julia) con
<< "% Warning : this file is generated automatically by Dynare" << endl
<< "% from model file (.mod)" << endl << endl;
else
paramsDerivsFile << "module " << basename << "DynamicParamsDerivs" << endl << endl
paramsDerivsFile << "module " << basename << "DynamicParamsDerivs" << endl
<< "#" << endl
<< "# NB: this file was automatically generated by Dynare" << endl
<< "# from " << basename << ".mod" << endl
<< "#" << endl
<< "export params_derivs" << endl << endl
<< "function params_derivs(y, x, paramssteady_state, it_, "
<< "ss_param_deriv, ss_param_2nd_deriv)" << endl;

View File

@ -1077,10 +1077,10 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
}
jlOutputFile << "module " << basename << endl
<< "##" << endl
<< " # Note : this file was automatically generated by Dynare" << endl
<< " # from " << basename << ".mod" << endl
<< "##" << endl
<< "#" << endl
<< "# NB: this file was automatically generated by Dynare" << endl
<< "# from " << basename << ".mod" << endl
<< "#" << endl
<< "using DynareModel" << endl
<< "using DynareOptions" << endl
<< "using DynareOutput" << endl

View File

@ -1436,15 +1436,25 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
}
else
{
ostringstream comments;
comments << "## Function Arguments" << endl
<< endl
<< "## Input" << endl
<< " 1 y: Array{Float64, length(model.endo), 1} Vector of endogenous variables in declaration order" << endl
<< " 2 x: Array{Float64, length(model.exo), 1} Vector of exogenous variables in declaration order" << endl
<< " 3 params: Array{Float64, length(model.param), 1} Vector of parameter values in declaration order" << endl
<< endl
<< "## Output" << endl
<< " 4 residual: Array(Float64, model.eq_nbr, 1) Vector of residuals of the static model equations" << endl
<< " in order of declaration of the equations." << endl
<< " Dynare may prepend auxiliary equations, see model.aux_vars" << endl;
StaticOutput << "function static!(y::Vector{Float64}, x::Vector{Float64}, "
<< "params::Vector{Float64}," << endl
<< " residual::Vector{Float64})" << endl
<< "#" << endl
<< "# Function argument sizes:" << endl
<< "# residual: Array(Float64, model.eq_nbr, 1)" << endl
<< "#" << endl
<< "#=" << endl << comments.str() << "=#" << endl
<< "@assert size(residual) == " << equations.size() << endl
<< "fill!(residual, 0.0)" << endl << endl
<< "fill!(residual, 0.0)" << endl
<< "#" << endl
<< "# Model equations" << endl
<< "#" << endl
@ -1456,15 +1466,16 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
<< "end" << endl << endl
<< "function static!(y::Vector{Float64}, x::Vector{Float64}, "
<< "params::Vector{Float64}," << endl
<< " residual::Vector{Float64}, g1::Matrix{Float64})" << endl
<< " #" << endl
<< " # Function argument sizes:" << endl
<< " # residual: Array(Float64, model.eq_nbr, 1)" << endl
<< " # g1: Array(Float64, model.eq_nbr, length(model.endo))" << endl
<< " #" << endl
<< " residual::Vector{Float64}, g1::Matrix{Float64})" << endl;
comments << " 5 g1: Array(Float64, model.eq_nbr, length(model.endo)) Jacobian matrix of the static model equations;" << endl
<< " columns: variables in declaration order" << endl
<< " rows: equations in order of declaration" << endl;
StaticOutput << "#=" << endl << comments.str() << "=#" << endl
<< " @assert size(g1) == (" << equations.size() << ", " << symbol_table.endo_nbr()
<< ")" << endl
<< " fill!(g1, 0.0)" << endl << endl
<< " fill!(g1, 0.0)" << endl
<< " static!(y, x, params, residual)" << endl
<< model_output.str()
<< " #" << endl
@ -1478,13 +1489,13 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
<< "function static!(y::Vector{Float64}, x::Vector{Float64}, "
<< "params::Vector{Float64}," << endl
<< " residual::Vector{Float64}, g1::Matrix{Float64}, "
<< "g2::Matrix{Float64})" << endl
<< " #" << endl
<< " # Function argument sizes:" << endl
<< " # residual: Array(Float64, model.eq_nbr, 1)" << endl
<< " # g1: Array(Float64, model.eq_nbr, length(model.endo))" << endl
<< " # g2: spzeros(model.eq_nbr, length(model.endo)^2)" << endl
<< " #" << endl << endl
<< "g2::Matrix{Float64})" << endl;
comments << " 6 g2: spzeros(model.eq_nbr, length(model.endo)^2) Hessian matrix of the static model equations;" << endl
<< " columns: variables in declaration order" << endl
<< " rows: equations in order of declaration" << endl;
StaticOutput << "#=" << endl << comments.str() << "=#" << endl
<< " @assert size(g2) == (" << equations.size() << ", " << g2ncols << ")" << endl
<< " static!(y, x, params, residual, g1)" << endl;
if (second_derivatives.size())
@ -1501,14 +1512,13 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
<< "params::Vector{Float64}," << endl
<< " residual::Vector{Float64}, g1::Matrix{Float64}, "
<< "g2::Matrix{Float64}," << endl
<< " g3::Matrix{Float64})" << endl
<< " #" << endl
<< " # Function argument sizes:" << endl
<< " # residual: Array(Float64, model.eq_nbr, 1)" << endl
<< " # g1: Array(Float64, model.eq_nbr, length(model.endo))" << endl
<< " # g2: spzeros(model.eq_nbr, length(model.endo)^2)" << endl
<< " # g3: spzeros(model.eq_nbr, length(model.endo)^3)" << endl
<< " #" << endl << endl
<< " g3::Matrix{Float64})" << endl;
comments << " 7 g3: spzeros(model.eq_nbr, length(model.endo)^3) Third derivatives matrix of the static model equations;" << endl
<< " columns: variables in declaration order" << endl
<< " rows: equations in order of declaration" << endl;
StaticOutput << "#=" << endl << comments.str() << "=#" << endl
<< " @assert size(g3) == (" << nrows << ", " << ncols << ")" << endl
<< " static!(y, x, params, residual, g1, g2)" << endl;
if (third_derivatives.size())
@ -1644,7 +1654,11 @@ StaticModel::writeStaticJuliaFile(const string &basename) const
exit(EXIT_FAILURE);
}
output << "module " << basename << "Static" << endl << endl
output << "module " << basename << "Static" << endl
<< "#" << endl
<< "# NB: this file was automatically generated by Dynare" << endl
<< "# from " << basename << ".mod" << endl
<< "#" << endl
<< "using Utils" << endl << endl
<< "export static!" << endl << endl;
writeStaticModel(output, false, true);
@ -2108,7 +2122,11 @@ StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) cons
<< "% Warning : this file is generated automatically by Dynare" << endl
<< "% from model file (.mod)" << endl << endl;
else
paramsDerivsFile << "module " << basename << "StaticParamsDerivs" << endl << endl
paramsDerivsFile << "module " << basename << "StaticParamsDerivs" << endl
<< "#" << endl
<< "# NB: this file was automatically generated by Dynare" << endl
<< "# from " << basename << ".mod" << endl
<< "#" << endl
<< "export params_derivs" << endl << endl
<< "function params_derivs(y, x, params)" << endl;

View File

@ -127,7 +127,11 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
<< "% Steady state generated by Dynare preprocessor" << endl
<< " info = 0;" << endl;
else
output << "module " << basename << "SteadyState2" << endl << endl
output << "module " << basename << "SteadyState2" << endl
<< "#" << endl
<< "# NB: this file was automatically generated by Dynare" << endl
<< "# from " << basename << ".mod" << endl
<< "#" << endl
<< "export steady_state!" << endl << endl
<< "function steady_state!(ys_::Vector{Float64}, exo_::Vector{Float64}, "
<< "params::Vector{Float64})" << endl;