From a8fc8e7afc42e02eaaa0f87d5cbcebe87f8f8ae9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 27 Mar 2023 17:20:34 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Incorrect=20cost=20table=20used?=
 =?UTF-8?q?=20when=20computing=20temporary=20terms=20in=20static=20model?=
 =?UTF-8?q?=20with=20=E2=80=9Cuse=5Fdll=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It was erroneously using MATLAB costs, leading to possible
inefficiencies (though those cost tables are probably not very accurate and
should be revised).
---
 src/ComputingTasks.cc | 2 +-
 src/ModFile.cc        | 2 +-
 src/StaticModel.cc    | 4 ++--
 src/StaticModel.hh    | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc
index f9fb98ab..ba134fa8 100644
--- a/src/ComputingTasks.cc
+++ b/src/ComputingTasks.cc
@@ -2442,7 +2442,7 @@ PlannerObjectiveStatement::getPlannerObjective() const
 void
 PlannerObjectiveStatement::computingPass(const ModFileStructure &mod_file_struct)
 {
-  model_tree.computingPass(max(3, mod_file_struct.order_option), 0, {}, false, false);
+  model_tree.computingPass(max(3, mod_file_struct.order_option), 0, {}, false, false, false);
   computing_pass_called = true;
 }
 
diff --git a/src/ModFile.cc b/src/ModFile.cc
index 17ef006c..1e3c38b9 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -672,7 +672,7 @@ ModFile::computingPass(bool no_tmp_terms, OutputType output, int params_derivs_o
               || (mod_file_struct.GMM_present && (mod_file_struct.analytic_standard_errors_present || mod_file_struct.analytic_jacobian_present)))
             paramsDerivsOrder = params_derivs_order;
 
-          static_model.computingPass(derivsOrder, paramsDerivsOrder, global_eval_context, no_tmp_terms, block);
+          static_model.computingPass(derivsOrder, paramsDerivsOrder, global_eval_context, no_tmp_terms, block, use_dll);
         }
       // Set things to compute for dynamic model
       if (mod_file_struct.perfect_foresight_solver_present
diff --git a/src/StaticModel.cc b/src/StaticModel.cc
index 44b32806..c1fc3530 100644
--- a/src/StaticModel.cc
+++ b/src/StaticModel.cc
@@ -170,7 +170,7 @@ StaticModel::writeStaticBlockBytecode(const string &basename) const
 }
 
 void
-StaticModel::computingPass(int derivsOrder, int paramsDerivsOrder, const eval_context_t &eval_context, bool no_tmp_terms, bool block)
+StaticModel::computingPass(int derivsOrder, int paramsDerivsOrder, const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll)
 {
   initializeVariablesAndEquations();
 
@@ -222,7 +222,7 @@ StaticModel::computingPass(int derivsOrder, int paramsDerivsOrder, const eval_co
       computeParamsDerivatives(paramsDerivsOrder);
     }
 
-  computeTemporaryTerms(true, no_tmp_terms);
+  computeTemporaryTerms(!use_dll, no_tmp_terms);
 
   if (paramsDerivsOrder > 0 && !no_tmp_terms)
     computeParamsDerivativesTemporaryTerms();
diff --git a/src/StaticModel.hh b/src/StaticModel.hh
index 6971f12a..77101304 100644
--- a/src/StaticModel.hh
+++ b/src/StaticModel.hh
@@ -122,7 +122,7 @@ public:
     \param derivsOrder order of derivation with respect to endogenous
     \param paramsDerivsOrder order of derivatives w.r. to a pair (endogenous, parameter) to be computed
   */
-  void computingPass(int derivsOrder, int paramsDerivsOrder, const eval_context_t &eval_context, bool no_tmp_terms, bool block);
+  void computingPass(int derivsOrder, int paramsDerivsOrder, const eval_context_t &eval_context, bool no_tmp_terms, bool block, bool use_dll);
 
   //! Writes static model file (+ bytecode)
   void writeStaticFile(const string &basename, bool use_dll, const string &mexext, const filesystem::path &matlabroot, bool julia) const;
-- 
GitLab