Commit 331edd8d authored by sebastien's avatar sebastien
Browse files

trunk preprocessor: cosmetic changes


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2614 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 34ee60fb
...@@ -487,12 +487,6 @@ DataTree::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException) ...@@ -487,12 +487,6 @@ DataTree::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException)
throw UnknownDerivIDException(); throw UnknownDerivIDException();
} }
int
DataTree::getDerivIDNbr() const
{
return 0;
}
int int
DataTree::getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException) DataTree::getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException)
{ {
......
...@@ -183,9 +183,6 @@ public: ...@@ -183,9 +183,6 @@ public:
//! Returns the derivation ID, or throws an exception if the derivation ID does not exist //! 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); 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 //! Returns the column of the dynamic Jacobian associated to a derivation ID
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException); virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
}; };
......
...@@ -2164,11 +2164,12 @@ DynamicModel::computingPass(bool jacobianExo, bool hessian, bool thirdDerivative ...@@ -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 // Compute derivatives w.r. to all endogenous, and possibly exogenous and exogenous deterministic
set<int> vars; 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))) if (type == eEndogenous || (jacobianExo && (type == eExogenous || type == eExogenousDet)))
vars.insert(i); vars.insert(it->second);
} }
// Launch computations // Launch computations
...@@ -2334,7 +2335,7 @@ DynamicModel::getTypeByDerivID(int deriv_id) const throw (UnknownDerivIDExceptio ...@@ -2334,7 +2335,7 @@ DynamicModel::getTypeByDerivID(int deriv_id) const throw (UnknownDerivIDExceptio
int int
DynamicModel::getLagByDerivID(int deriv_id) const throw (UnknownDerivIDException) 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(); throw UnknownDerivIDException();
return inv_deriv_id_table[deriv_id].second; return inv_deriv_id_table[deriv_id].second;
...@@ -2343,7 +2344,7 @@ DynamicModel::getLagByDerivID(int deriv_id) const throw (UnknownDerivIDException ...@@ -2343,7 +2344,7 @@ DynamicModel::getLagByDerivID(int deriv_id) const throw (UnknownDerivIDException
int int
DynamicModel::getSymbIDByDerivID(int deriv_id) const throw (UnknownDerivIDException) 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(); throw UnknownDerivIDException();
return inv_deriv_id_table[deriv_id].first; return inv_deriv_id_table[deriv_id].first;
...@@ -2359,12 +2360,6 @@ DynamicModel::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDExcept ...@@ -2359,12 +2360,6 @@ DynamicModel::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDExcept
return it->second; return it->second;
} }
int
DynamicModel::getDerivIDNbr() const
{
return deriv_id_table.size();
}
void void
DynamicModel::computeDynJacobianCols(bool jacobianExo) DynamicModel::computeDynJacobianCols(bool jacobianExo)
{ {
...@@ -2430,17 +2425,20 @@ DynamicModel::getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDExcepti ...@@ -2430,17 +2425,20 @@ DynamicModel::getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDExcepti
void void
DynamicModel::computeParamsDerivatives() 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; continue;
for (first_derivatives_type::const_iterator it = first_derivatives.begin(); int param = it->second;
it != first_derivatives.end(); it++)
for (first_derivatives_type::const_iterator it2 = first_derivatives.begin();
it2 != first_derivatives.end(); it2++)
{ {
int eq = it->first.first; int eq = it2->first.first;
int var = it->first.second; int var = it2->first.second;
NodeID d1 = it->second; NodeID d1 = it2->second;
NodeID d2 = d1->getDerivative(param); NodeID d2 = d1->getDerivative(param);
if (d2 == Zero) if (d2 == Zero)
......
...@@ -147,7 +147,6 @@ public: ...@@ -147,7 +147,6 @@ public:
/*! It assumes that the static model given in argument has just been allocated */ /*! It assumes that the static model given in argument has just been allocated */
void toStatic(StaticModel &static_model) const; void toStatic(StaticModel &static_model) const;
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException); virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
virtual int getDerivIDNbr() const;
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException); virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);
}; };
......
...@@ -204,7 +204,6 @@ private: ...@@ -204,7 +204,6 @@ private:
const SymbolType type; const SymbolType type;
const int lag; const int lag;
//! Derivation ID //! 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; const int deriv_id;
virtual NodeID computeDerivative(int deriv_id_arg); virtual NodeID computeDerivative(int deriv_id_arg);
public: public:
......
...@@ -251,7 +251,7 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin ...@@ -251,7 +251,7 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin
const SymbolTable &symbol_table_arg) : const SymbolTable &symbol_table_arg) :
symbol_table(symbol_table_arg) symbol_table(symbol_table_arg)
{ {
cout << "Reading " << filename << " ..."; cout << "Reading " << filename << "." << endl;
ifstream f; ifstream f;
f.open(filename.c_str(), ios::in); f.open(filename.c_str(), ios::in);
......
...@@ -138,7 +138,7 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const ...@@ -138,7 +138,7 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const
it != first_derivatives.end(); it++) it != first_derivatives.end(); it++)
{ {
int eq = it->first.first; 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; NodeID d1 = it->second;
ostringstream g1; ostringstream g1;
...@@ -155,8 +155,8 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const ...@@ -155,8 +155,8 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const
it != second_derivatives.end(); it++) it != second_derivatives.end(); it++)
{ {
int eq = it->first.first; int eq = it->first.first;
int symb_id1 = inv_deriv_id_table[it->first.second.first]; int symb_id1 = it->first.second.first;
int symb_id2 = inv_deriv_id_table[it->first.second.second]; int symb_id2 = it->first.second.second;
NodeID d2 = it->second; NodeID d2 = it->second;
int tsid1 = symbol_table.getTypeSpecificID(symb_id1); int tsid1 = symbol_table.getTypeSpecificID(symb_id1);
...@@ -268,10 +268,10 @@ StaticModel::writeStaticFile(const string &basename) const ...@@ -268,10 +268,10 @@ StaticModel::writeStaticFile(const string &basename) const
void void
StaticModel::computingPass(bool hessian, bool no_tmp_terms) 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; set<int> vars;
for(int i = 0; i < getDerivIDNbr(); i++) for(int i = 0; i < symbol_table.endo_nbr(); i++)
vars.insert(i); vars.insert(symbol_table.getID(eEndogenous, i));
// Launch computations // Launch computations
cout << "Computing static model derivatives:" << endl cout << "Computing static model derivatives:" << endl
...@@ -291,35 +291,17 @@ StaticModel::computingPass(bool hessian, bool no_tmp_terms) ...@@ -291,35 +291,17 @@ StaticModel::computingPass(bool hessian, bool no_tmp_terms)
int int
StaticModel::computeDerivID(int symb_id, int lag) 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; 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 int
StaticModel::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException) StaticModel::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException)
{ {
deriv_id_table_t::const_iterator it = deriv_id_table.find(symb_id); if (symbol_table.getType(symb_id) == eEndogenous)
if (it == deriv_id_table.end()) return symb_id;
throw UnknownDerivIDException();
else else
return it->second; throw UnknownDerivIDException();
}
int
StaticModel::getDerivIDNbr() const
{
return deriv_id_table.size();
} }
...@@ -25,15 +25,10 @@ using namespace std; ...@@ -25,15 +25,10 @@ using namespace std;
#include "ModelTree.hh" #include "ModelTree.hh"
//! Stores a static model //! Stores a static model
/*! Derivation IDs are allocated only for endogenous, and are equal to symbol ID in that case */
class StaticModel : public ModelTree class StaticModel : public ModelTree
{ {
private: 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 //! Writes the static model equations and its derivatives
/*! \todo handle hessian in C output */ /*! \todo handle hessian in C output */
void writeStaticModel(ostream &StaticOutput) const; void writeStaticModel(ostream &StaticOutput) const;
...@@ -55,7 +50,6 @@ public: ...@@ -55,7 +50,6 @@ public:
void writeStaticFile(const string &basename) const; void writeStaticFile(const string &basename) const;
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException); virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
virtual int getDerivIDNbr() const;
}; };
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment