From 31a9a5e9abe3929ffa422d6df42fddc9627337a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 12 May 2020 23:08:04 +0200
Subject: [PATCH] Bytecode MEX: various fixes to debug mode

---
 mex/sources/bytecode/ErrorHandling.hh |  4 +-
 mex/sources/bytecode/Evaluate.cc      | 16 ++++----
 mex/sources/bytecode/SparseMatrix.cc  | 54 +++++++++++++--------------
 3 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh
index fbded6d6fb..f9e2489d52 100644
--- a/mex/sources/bytecode/ErrorHandling.hh
+++ b/mex/sources/bytecode/ErrorHandling.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2007-2017 Dynare Team
+ * Copyright © 2007-2020 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -1789,7 +1789,7 @@ public:
               unsigned int nb_add_input_arguments = fc->get_nb_add_input_arguments();
               function_type = fc->get_function_type();
 #ifdef DEBUG
-              mexPrintf("function_type=%d ExternalFunctionWithoutDerivative=%d\n", function_type, ExternalFunctionWithoutDerivative);
+              mexPrintf("function_type=%d ExternalFunctionWithoutDerivative=%d\n", function_type, ExternalFunctionType::withoutDerivative);
               mexEvalString("drawnow;");
 #endif
               mxArray **input_arguments;
diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc
index a488a03509..576edff9e2 100644
--- a/mex/sources/bytecode/Evaluate.cc
+++ b/mex/sources/bytecode/Evaluate.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2013-2017 Dynare Team
+ * Copyright © 2013-2020 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -455,7 +455,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
           //load a temporary variable in the processor
           var = static_cast<FLDT_ *>(it_code->second)->get_pos();
 #ifdef DEBUG
-          mexPrintf("T[it_=%d var=%d, y_kmin=%d, y_kmax=%d == %d]=>%f\n", it_, var, y_kmin, y_kmax, var*(periods+y_kmin+y_kmax)+it_, var);
+          mexPrintf("FLDT T[it_=%d var=%d, y_kmin=%d, y_kmax=%d == %d]=>%f\n", it_, var, y_kmin, y_kmax, var*(periods+y_kmin+y_kmax)+it_, T[var*(periods+y_kmin+y_kmax)+it_]);
           tmp_out << " T[" << it_ << ", " << var << "](" << T[var*(periods+y_kmin+y_kmax)+it_] << ")";
 #endif
           Stack.push(T[var*(periods+y_kmin+y_kmax)+it_]);
@@ -783,11 +783,11 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
               tmp << " in compute_block_time, variable " << EQN_type << " not used yet\n";
               throw FatalExceptionHandling(tmp.str());
             }
-#ifdef DEBUG
-          tmp_out << "=>";
-          mexPrintf(" g1[%d](%f)=%s\n", var, g1[var], tmp_out.str().c_str());
-          tmp_out.str("");
-#endif
+// #ifdef DEBUG
+//           tmp_out << "=>";
+//           mexPrintf(" g1[%d](%f)=%s\n", var, g1[var], tmp_out.str().c_str());
+//           tmp_out.str("");
+// #endif
           Stack.pop();
           break;
 
@@ -1160,7 +1160,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
             unsigned int nb_add_input_arguments = fc->get_nb_add_input_arguments();
             function_type = fc->get_function_type();
 #ifdef DEBUG
-            mexPrintf("function_type=%d ExternalFunctionWithoutDerivative=%d\n", function_type, ExternalFunctionWithoutDerivative);
+            mexPrintf("function_type=%d ExternalFunctionWithoutDerivative=%d\n", function_type, ExternalFunctionType::withoutDerivative);
             mexEvalString("drawnow;");
 #endif
             mxArray **input_arguments;
diff --git a/mex/sources/bytecode/SparseMatrix.cc b/mex/sources/bytecode/SparseMatrix.cc
index 4af1ffa209..0473d91c1f 100644
--- a/mex/sources/bytecode/SparseMatrix.cc
+++ b/mex/sources/bytecode/SparseMatrix.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2007-2017 Dynare Team
+ * Copyright © 2007-2020 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -1083,23 +1083,23 @@ dynSparseMatrix::Init_UMFPACK_Sparse(int periods, int y_kmin, int y_kmax, int Si
       while (it4 != IM.end())
         {
           var = it4->first.first.first;
-#ifdef DEBUG
-          if (var < 0 || var >= Size)
-            {
-              ostringstream tmp;
-              tmp << " in Init_UMFPACK_Sparse, var (" << var << ") out of range\n";
-              throw FatalExceptionHandling(tmp.str());
-            }
-#endif
+// #ifdef DEBUG
+//           if (var < 0 || var >= Size)
+//             {
+//               ostringstream tmp;
+//               tmp << " in Init_UMFPACK_Sparse, var (" << var << ") out of range\n";
+//               throw FatalExceptionHandling(tmp.str());
+//             }
+// #endif
           eq = it4->first.second+Size*t;
-#ifdef DEBUG
-          if (eq < 0 || eq >= Size)
-            {
-              ostringstream tmp;
-              tmp << " in Init_UMFPACK_Sparse, eq (" << eq << ") out of range\n";
-              throw FatalExceptionHandling(tmp.str());
-            }
-#endif
+// #ifdef DEBUG
+//           if (eq < 0 || eq >= Size)
+//             {
+//               ostringstream tmp;
+//               tmp << " in Init_UMFPACK_Sparse, eq (" << eq << ") out of range\n";
+//               throw FatalExceptionHandling(tmp.str());
+//             }
+// #endif
           lag = -it4->first.first.second;
           int index = it4->second+ (t-lag) * u_count_init;
           if (var != last_var)
@@ -1181,12 +1181,12 @@ dynSparseMatrix::Init_UMFPACK_Sparse(int periods, int y_kmin, int y_kmax, int Si
               if (lag <= ti_new_y_kmax && lag >= ti_new_y_kmin) /*Build the index for sparse matrix containing the jacobian : u*/
                 {
 #ifdef DEBUG
-                  if (index < 0 || index >= u_count_alloc || index > Size + Size*Size)
-                    {
-                      ostringstream tmp;
-                      tmp << " in Init_UMFPACK_Sparse, index (" << index << ") out of range for u vector max = " << Size+Size*Size << " allocated = " << u_count_alloc << "\n";
-                      throw FatalExceptionHandling(tmp.str());
-                    }
+                  // if (index < 0 || index >= u_count_alloc || index > Size + Size*Size)
+                  //   {
+                  //     ostringstream tmp;
+                  //     tmp << " in Init_UMFPACK_Sparse, index (" << index << ") out of range for u vector max = " << Size+Size*Size << " allocated = " << u_count_alloc << "\n";
+                  //     throw FatalExceptionHandling(tmp.str());
+                  //   }
                   if (NZE >= max_nze)
                     {
                       ostringstream tmp;
@@ -1275,7 +1275,7 @@ dynSparseMatrix::Init_UMFPACK_Sparse(int periods, int y_kmin, int y_kmax, int Si
   (*Ap)[Size*periods] = NZE;
 #ifdef DEBUG
   mexPrintf("*Ax = [");
-  for (int i = 0; i < NZE; i++)
+  for (int i = 0; i < static_cast<int>(NZE); i++)
     mexPrintf("%f ", (*Ax)[i]);
   mexPrintf("]\n");
 
@@ -1285,7 +1285,7 @@ dynSparseMatrix::Init_UMFPACK_Sparse(int periods, int y_kmin, int y_kmax, int Si
   mexPrintf("]\n");
 
   mexPrintf("*Ai = [");
-  for (int i = 0; i < NZE; i++)
+  for (int i = 0; i < static_cast<int>(NZE); i++)
     mexPrintf("%d ", (*Ai)[i]);
   mexPrintf("]\n");
 #endif
@@ -6294,9 +6294,9 @@ dynSparseMatrix::Simulate_One_Boundary(int block_num, int y_size, int y_kmin, in
                 break;
               }
           if (select)
-            mexPrintf("-> variable %s (%d) at time %d = %f direction = %f\n", get_variable(eEndogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]);
+            mexPrintf("-> variable %s (%d) at time %d = %f direction = %f\n", get_variable(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]);
           else
-            mexPrintf("   variable %s (%d) at time %d = %f direction = %f\n", get_variable(eEndogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]);
+            mexPrintf("   variable %s (%d) at time %d = %f direction = %f\n", get_variable(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]);
         }
 #endif
       if (steady_state)
-- 
GitLab