From cf4e2194b7fa0a676891f457a9430602e084882c Mon Sep 17 00:00:00 2001
From: MichelJuillard <michel.juillard@mjui.fr>
Date: Tue, 22 Nov 2022 10:18:11 +0000
Subject: [PATCH] Julia: remove module for derivatives w.r.t. parameters

---
 src/DynamicModel.hh       | 22 +++-------------------
 src/ModelEquationBlock.cc |  7 ++-----
 src/StaticModel.hh        | 20 +++-----------------
 3 files changed, 8 insertions(+), 41 deletions(-)

diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh
index c5db1000..d857a9eb 100644
--- a/src/DynamicModel.hh
+++ b/src/DynamicModel.hh
@@ -959,44 +959,28 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const
                        << "end" << endl;
     }
   else
-    paramsDerivsFile << "module " << basename << "DynamicParamsDerivs" << endl
-                     << "#" << endl
-                     << "# NB: this file was automatically generated by Dynare" << endl
+    paramsDerivsFile << "# 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_, "
+                     << "function dynamic_params_derivs(y, x, paramssteady_state, it_,"
                      << "ss_param_deriv, ss_param_2nd_deriv)" << endl
 		     << "@inbounds begin" << endl
                      << tt_output.str()
-		     << "end" << endl
                      << "rp = zeros(" << equations.size() << ", "
                      << symbol_table.param_nbr() << ");" << endl
-		     << "@inbounds begin" << endl
                      << rp_output.str()
-		     << "end" << endl
                      << "gp = zeros(" << equations.size() << ", " << getJacobianColsNbr(false) << ", " << symbol_table.param_nbr() << ");" << endl
-		     << "@inbounds begin" << endl
                      << gp_output.str()
-		     << "end" << endl
                      << "rpp = zeros(" << params_derivatives.at({ 0, 2 }).size() << ",4);" << endl
-		     << "@inbounds begin" << endl
                      << rpp_output.str()
-		     << "end" << endl
                      << "gpp = zeros(" << params_derivatives.at({ 1, 2 }).size() << ",5);" << endl
-		     << "@inbounds begin" << endl
                      << gpp_output.str()
-		     << "end" << endl
                      << "hp = zeros(" << params_derivatives.at({ 2, 1 }).size() << ",5);" << endl
-		     << "@inbounds begin" << endl
                      << hp_output.str()
-		     << "end" << endl
                      << "g3p = zeros(" << params_derivatives.at({ 3, 1 }).size() << ",6);" << endl
-		     << "@inbounds begin" << endl
                      << g3p_output.str()
 		     << "end" << endl
-                     << "(rp, gp, rpp, gpp, hp, g3p)" << endl
-                     << "end" << endl
+                     << "return (rp, gp, rpp, gpp, hp, g3p)" << endl
                      << "end" << endl;
 
   paramsDerivsFile.close();
diff --git a/src/ModelEquationBlock.cc b/src/ModelEquationBlock.cc
index 745fb6da..ef78b7d9 100644
--- a/src/ModelEquationBlock.cc
+++ b/src/ModelEquationBlock.cc
@@ -221,12 +221,9 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool julia) const
            << "% Steady state generated by Dynare preprocessor" << endl
            << "    info = 0;" << endl;
   else
-    output << "module " << basename << "SteadyState2" << endl
-           << "#" << endl
-           << "# NB: this file was automatically generated by Dynare" << endl
+    output << "# NB: this file was automatically generated by Dynare" << endl
            << "#     from " << basename << ".mod" << endl
            << "#" << endl
-           << "export steady_state!" << endl << endl
            << "function steady_state!(ys_::Vector{<: Real}, exo_::Vector{<: Real}, "
            << "params::Vector{<: Real})" << endl
 	   << "@inbounds begin" << endl;
@@ -257,7 +254,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool julia) const
 
   output << "end" << endl;
   if (julia)
-    output << "end" << endl << "end" << endl;
+    output << "end" << endl;
 
   if (julia)
     writeToFileIfModified(output, filesystem::path{basename} / "model" / "julia" / "SteadyState2.jl");
diff --git a/src/StaticModel.hh b/src/StaticModel.hh
index 6ec94ac4..002ffff2 100644
--- a/src/StaticModel.hh
+++ b/src/StaticModel.hh
@@ -294,40 +294,26 @@ StaticModel::writeParamsDerivativesFile(const string &basename) const
                        << "end" << endl;
     }
   else
-    paramsDerivsFile << "module " << basename << "StaticParamsDerivs" << endl
-                     << "#" << endl
-                     << "# NB: this file was automatically generated by Dynare" << endl
+    paramsDerivsFile << "# 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
+                     << "function static_params_derivs(y, x, params)" << endl
 		     << "@inbounds begin" << endl
                      << tt_output.str()
-		     << "end" << endl
                      << "rp = zeros(" << equations.size() << ", "
                      << symbol_table.param_nbr() << ");" << endl
-		     << "@inbounds begin" << endl
                      << rp_output.str()
-		     << "end" << endl
                      << "gp = zeros(" << equations.size() << ", " << symbol_table.endo_nbr() << ", "
                      << symbol_table.param_nbr() << ");" << endl
-		     << "@inbounds begin" << endl
                      << gp_output.str()
-		     << "end" << endl
                      << "rpp = zeros(" << params_derivatives.at({ 0, 2 }).size() << ",4);" << endl
-		     << "@inbounds begin" << endl
                      << rpp_output.str()
-		     << "end" << endl
                      << "gpp = zeros(" << params_derivatives.at({ 1, 2 }).size() << ",5);" << endl
-		     << "@inbounds begin" << endl
                      << gpp_output.str()
-		     << "end" << endl
                      << "hp = zeros(" << params_derivatives.at({ 2, 1 }).size() << ",5);" << endl
-		     << "@inbounds begin" << endl
                      << hp_output.str()
 		     << "end" << endl
-                     << "(rp, gp, rpp, gpp, hp)" << endl
-                     << "end" << endl
+                     << "return (rp, gp, rpp, gpp, hp)" << endl
                      << "end" << endl;
 
   paramsDerivsFile.close();
-- 
GitLab