From 331edd8d92604d7cd24bcce47e7bfe28c78809fe Mon Sep 17 00:00:00 2001
From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Mon, 20 Apr 2009 15:54:19 +0000
Subject: [PATCH] trunk preprocessor: cosmetic changes

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2614 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 DataTree.cc                |  6 ------
 DataTree.hh                |  3 ---
 DynamicModel.cc            | 34 +++++++++++++++---------------
 DynamicModel.hh            |  1 -
 ExprNode.hh                |  1 -
 NumericalInitialization.cc |  2 +-
 StaticModel.cc             | 42 +++++++++++---------------------------
 StaticModel.hh             |  8 +-------
 8 files changed, 30 insertions(+), 67 deletions(-)

diff --git a/DataTree.cc b/DataTree.cc
index 0b7eed7f..aa44d82b 100644
--- a/DataTree.cc
+++ b/DataTree.cc
@@ -487,12 +487,6 @@ DataTree::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException)
   throw UnknownDerivIDException();
 }
 
-int
-DataTree::getDerivIDNbr() const
-{
-  return 0;
-}
-
 int
 DataTree::getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException)
 {
diff --git a/DataTree.hh b/DataTree.hh
index 17be97c6..1fea9429 100644
--- a/DataTree.hh
+++ b/DataTree.hh
@@ -183,9 +183,6 @@ public:
 
   //! Returns the derivation ID, or throws an exception if the derivation ID does not exist
   virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
-  //! Returns the total number of derivation IDs
-  /*! Valid derivation IDs are between 0 and getDerivIDNbr()-1 */
-  virtual int getDerivIDNbr() const;
   //! Returns the column of the dynamic Jacobian associated to a derivation ID
   virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
 };
diff --git a/DynamicModel.cc b/DynamicModel.cc
index 3107b1b0..9a425b80 100644
--- a/DynamicModel.cc
+++ b/DynamicModel.cc
@@ -2164,11 +2164,12 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative
 
   // Compute derivatives w.r. to all endogenous, and possibly exogenous and exogenous deterministic
   set<int> vars;
-  for(int i = 0; i < getDerivIDNbr(); i++)
+  for(deriv_id_table_t::const_iterator it = deriv_id_table.begin();
+      it != deriv_id_table.end(); it++)
     {
-      SymbolType type = getTypeByDerivID(i);
+      SymbolType type = symbol_table.getType(it->first.first);
       if (type == eEndogenous || (jacobianExo && (type == eExogenous || type == eExogenousDet)))
-        vars.insert(i);
+        vars.insert(it->second);
     }
 
   // Launch computations
@@ -2334,7 +2335,7 @@ DynamicModel::getTypeByDerivID(int deriv_id) const throw (UnknownDerivIDExceptio
 int
 DynamicModel::getLagByDerivID(int deriv_id) const throw (UnknownDerivIDException)
 {
-  if (deriv_id < 0 || deriv_id >= getDerivIDNbr())
+  if (deriv_id < 0 || deriv_id >= (int) inv_deriv_id_table.size())
     throw UnknownDerivIDException();
 
   return inv_deriv_id_table[deriv_id].second;
@@ -2343,7 +2344,7 @@ DynamicModel::getLagByDerivID(int deriv_id) const throw (UnknownDerivIDException
 int
 DynamicModel::getSymbIDByDerivID(int deriv_id) const throw (UnknownDerivIDException)
 {
-  if (deriv_id < 0 || deriv_id >= getDerivIDNbr())
+  if (deriv_id < 0 || deriv_id >= (int) inv_deriv_id_table.size())
     throw UnknownDerivIDException();
 
   return inv_deriv_id_table[deriv_id].first;
@@ -2359,12 +2360,6 @@ DynamicModel::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDExcept
     return it->second;
 }
 
-int
-DynamicModel::getDerivIDNbr() const
-{
-  return deriv_id_table.size();
-}
-
 void
 DynamicModel::computeDynJacobianCols(bool jacobianExo)
 {
@@ -2430,17 +2425,20 @@ DynamicModel::getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDExcepti
 void
 DynamicModel::computeParamsDerivatives()
 {
-  for (int param = 0; param < getDerivIDNbr(); param++)
+  for(deriv_id_table_t::const_iterator it = deriv_id_table.begin();
+      it != deriv_id_table.end(); it++)
     {
-      if (getTypeByDerivID(param) != eParameter)
+      if (symbol_table.getType(it->first.first) != eParameter)
         continue;
 
-      for (first_derivatives_type::const_iterator it = first_derivatives.begin();
-           it != first_derivatives.end(); it++)
+      int param = it->second;
+
+      for (first_derivatives_type::const_iterator it2 = first_derivatives.begin();
+           it2 != first_derivatives.end(); it2++)
         {
-          int eq = it->first.first;
-          int var = it->first.second;
-          NodeID d1 = it->second;
+          int eq = it2->first.first;
+          int var = it2->first.second;
+          NodeID d1 = it2->second;
 
           NodeID d2 = d1->getDerivative(param);
           if (d2 == Zero)
diff --git a/DynamicModel.hh b/DynamicModel.hh
index 0e92c8dd..a3def3a1 100644
--- a/DynamicModel.hh
+++ b/DynamicModel.hh
@@ -147,7 +147,6 @@ public:
   /*! It assumes that the static model given in argument has just been allocated */
   void toStatic(StaticModel &static_model) const;
   virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
-  virtual int getDerivIDNbr() const;
   virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
 };
 
diff --git a/ExprNode.hh b/ExprNode.hh
index 9017b706..1a427400 100644
--- a/ExprNode.hh
+++ b/ExprNode.hh
@@ -204,7 +204,6 @@ private:
   const SymbolType type;
   const int lag;
   //! Derivation ID
-  /*! It is comprised between 0 and datatree.getDerivIDNbr()-1, or can be -1 if we don't derive w.r. to this variable */
   const int deriv_id;
   virtual NodeID computeDerivative(int deriv_id_arg);
 public:
diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc
index 7b98b0c8..aa3a18c6 100644
--- a/NumericalInitialization.cc
+++ b/NumericalInitialization.cc
@@ -251,7 +251,7 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin
                                                                      const SymbolTable &symbol_table_arg) :
   symbol_table(symbol_table_arg)
 {
-  cout << "Reading " << filename << " ...";
+  cout << "Reading " << filename << "." << endl;
 
   ifstream f;
   f.open(filename.c_str(), ios::in);
diff --git a/StaticModel.cc b/StaticModel.cc
index e4cec43b..838d7a0a 100644
--- a/StaticModel.cc
+++ b/StaticModel.cc
@@ -138,7 +138,7 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const
        it != first_derivatives.end(); it++)
     {
       int eq = it->first.first;
-      int symb_id = inv_deriv_id_table[it->first.second];
+      int symb_id = it->first.second;
       NodeID d1 = it->second;
 
       ostringstream g1;
@@ -155,8 +155,8 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const
        it != second_derivatives.end(); it++)
     {
       int eq = it->first.first;
-      int symb_id1 = inv_deriv_id_table[it->first.second.first];
-      int symb_id2 = inv_deriv_id_table[it->first.second.second];
+      int symb_id1 = it->first.second.first;
+      int symb_id2 = it->first.second.second;
       NodeID d2 = it->second;
 
       int tsid1 = symbol_table.getTypeSpecificID(symb_id1);
@@ -268,10 +268,10 @@ StaticModel::writeStaticFile(const string &basename) const
 void
 StaticModel::computingPass(bool hessian, bool no_tmp_terms)
 {
-  // Compute derivatives w.r. to all derivation IDs (i.e. all endogenous)
+  // Compute derivatives w.r. to all endogenous
   set<int> vars;
-  for(int i = 0; i < getDerivIDNbr(); i++)
-    vars.insert(i);
+  for(int i = 0; i < symbol_table.endo_nbr(); i++)
+    vars.insert(symbol_table.getID(eEndogenous, i));
 
   // Launch computations
   cout << "Computing static model derivatives:" << endl
@@ -291,35 +291,17 @@ StaticModel::computingPass(bool hessian, bool no_tmp_terms)
 int
 StaticModel::computeDerivID(int symb_id, int lag)
 {
-  // Only create derivation ID for endogenous
-  if (symbol_table.getType(symb_id) != eEndogenous)
+  if (symbol_table.getType(symb_id) == eEndogenous)
+    return symb_id;
+  else
     return -1;
-
-  deriv_id_table_t::const_iterator it = deriv_id_table.find(symb_id);
-  if (it != deriv_id_table.end())
-    return it->second;
-
-  // Create a new deriv_id
-  int deriv_id = deriv_id_table.size();
-
-  deriv_id_table[symb_id] = deriv_id;
-  inv_deriv_id_table.push_back(symb_id);
-
-  return deriv_id;
 }
 
 int
 StaticModel::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException)
 {
-  deriv_id_table_t::const_iterator it = deriv_id_table.find(symb_id);
-  if (it == deriv_id_table.end())
-    throw UnknownDerivIDException();
+  if (symbol_table.getType(symb_id) == eEndogenous)
+    return symb_id;
   else
-    return it->second;
-}
-
-int
-StaticModel::getDerivIDNbr() const
-{
-  return deriv_id_table.size();
+    throw UnknownDerivIDException();
 }
diff --git a/StaticModel.hh b/StaticModel.hh
index 50882b94..8c6dd119 100644
--- a/StaticModel.hh
+++ b/StaticModel.hh
@@ -25,15 +25,10 @@ using namespace std;
 #include "ModelTree.hh"
 
 //! Stores a static model
+/*! Derivation IDs are allocated only for endogenous, and are equal to symbol ID in that case */
 class StaticModel : public ModelTree
 {
 private:
-  typedef map<int, int> deriv_id_table_t;
-  //! Maps a symbol ID to a derivation ID
-  deriv_id_table_t deriv_id_table;
-  //! Maps a derivation ID to a symbol ID
-  vector<int> inv_deriv_id_table;
-
   //! Writes the static model equations and its derivatives
   /*! \todo handle hessian in C output */
   void writeStaticModel(ostream &StaticOutput) const;
@@ -55,7 +50,6 @@ public:
   void writeStaticFile(const string &basename) const;
 
   virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
-  virtual int getDerivIDNbr() const;
 };
 
 #endif
-- 
GitLab