Preprocessor:
* new ExprNode method for computing set of ModelLocalVariables of an expression * factorized code with collectEndogenous() and collectExogenous() methods git-svn-id: https://www.dynare.org/svn/dynare/trunk@2839 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
171632be23
commit
d9aca4bc4e
|
@ -21,6 +21,8 @@
|
|||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
#include <ext/functional>
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
|
@ -75,6 +77,35 @@ ExprNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab) cons
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ExprNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
set<pair<int, int> > symb_ids;
|
||||
collectVariables(eEndogenous, symb_ids);
|
||||
for(set<pair<int, int> >::const_iterator it = symb_ids.begin();
|
||||
it != symb_ids.end(); it++)
|
||||
result.insert(make_pair(datatree.symbol_table.getTypeSpecificID(it->first), it->second));
|
||||
}
|
||||
|
||||
void
|
||||
ExprNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
set<pair<int, int> > symb_ids;
|
||||
collectVariables(eExogenous, symb_ids);
|
||||
for(set<pair<int, int> >::const_iterator it = symb_ids.begin();
|
||||
it != symb_ids.end(); it++)
|
||||
result.insert(make_pair(datatree.symbol_table.getTypeSpecificID(it->first), it->second));
|
||||
}
|
||||
|
||||
void
|
||||
ExprNode::collectModelLocalVariables(set<int> &result) const
|
||||
{
|
||||
set<pair<int, int> > symb_ids;
|
||||
collectVariables(eModelLocalVariable, symb_ids);
|
||||
transform(symb_ids.begin(), symb_ids.end(), inserter(result, result.begin()),
|
||||
__gnu_cxx::select1st<pair<int, int> >());
|
||||
}
|
||||
|
||||
void
|
||||
ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||
temporary_terms_type &temporary_terms,
|
||||
|
@ -160,14 +191,9 @@ NumConstNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_
|
|||
}
|
||||
|
||||
void
|
||||
NumConstNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
NumConstNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
}
|
||||
NumConstNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const
|
||||
{
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
NumConstNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
|
@ -507,22 +533,13 @@ VariableNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
|||
}
|
||||
|
||||
void
|
||||
VariableNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
if (type == eEndogenous)
|
||||
result.insert(make_pair(datatree.symbol_table.getTypeSpecificID(symb_id), lag));
|
||||
else if (type == eModelLocalVariable)
|
||||
datatree.local_variables_table[symb_id]->collectEndogenous(result);
|
||||
}
|
||||
|
||||
void
|
||||
VariableNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
if (type == eExogenous)
|
||||
result.insert(make_pair(datatree.symbol_table.getTypeSpecificID(symb_id), lag));
|
||||
else if (type == eModelLocalVariable)
|
||||
datatree.local_variables_table[symb_id]->collectExogenous(result);
|
||||
}
|
||||
VariableNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const
|
||||
{
|
||||
if (type == type_arg)
|
||||
result.insert(make_pair(symb_id, lag));
|
||||
if (type == eModelLocalVariable)
|
||||
datatree.local_variables_table[symb_id]->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
VariableNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
|
@ -993,16 +1010,10 @@ UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_t
|
|||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg->collectEndogenous(result);
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg->collectExogenous(result);
|
||||
}
|
||||
UnaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const
|
||||
{
|
||||
arg->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
UnaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
|
@ -1615,18 +1626,11 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg1->collectEndogenous(result);
|
||||
arg2->collectEndogenous(result);
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg1->collectExogenous(result);
|
||||
arg2->collectExogenous(result);
|
||||
}
|
||||
BinaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const
|
||||
{
|
||||
arg1->collectVariables(type_arg, result);
|
||||
arg2->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
BinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
|
@ -2079,20 +2083,12 @@ TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg1->collectEndogenous(result);
|
||||
arg2->collectEndogenous(result);
|
||||
arg3->collectEndogenous(result);
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg1->collectExogenous(result);
|
||||
arg2->collectExogenous(result);
|
||||
arg3->collectExogenous(result);
|
||||
}
|
||||
TrinaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const
|
||||
{
|
||||
arg1->collectVariables(type_arg, result);
|
||||
arg2->collectVariables(type_arg, result);
|
||||
arg3->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
pair<bool, NodeID>
|
||||
TrinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
|
||||
|
@ -2199,20 +2195,12 @@ UnknownFunctionNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
|||
}
|
||||
|
||||
void
|
||||
UnknownFunctionNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
UnknownFunctionNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const
|
||||
{
|
||||
for (vector<NodeID>::const_iterator it = arguments.begin();
|
||||
it != arguments.end(); it++)
|
||||
(*it)->collectEndogenous(result);
|
||||
}
|
||||
|
||||
void
|
||||
UnknownFunctionNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
for (vector<NodeID>::const_iterator it = arguments.begin();
|
||||
it != arguments.end(); it++)
|
||||
(*it)->collectExogenous(result);
|
||||
}
|
||||
(*it)->collectVariables(type_arg, result);
|
||||
}
|
||||
|
||||
void
|
||||
UnknownFunctionNode::collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const
|
||||
|
|
|
@ -153,19 +153,37 @@ public:
|
|||
//! Writes output of node (with no temporary terms and with "outside model" output type)
|
||||
void writeOutput(ostream &output);
|
||||
|
||||
//! Computes the set of all variables of a given symbol type in the expression
|
||||
/*!
|
||||
Variables are stored as integer pairs of the form (symb_id, lag).
|
||||
They are added to the set given in argument.
|
||||
Note that model local variables are substituted by their expression in the computation
|
||||
(and added if type_arg = ModelLocalVariable).
|
||||
*/
|
||||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const = 0;
|
||||
|
||||
//! Computes the set of endogenous variables in the expression
|
||||
/*!
|
||||
Endogenous are stored as integer pairs of the form (type_specific_id, lag).
|
||||
They are added to the set given in argument.
|
||||
Note that model local variables are substituted by their expression in the computation.
|
||||
*/
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const = 0;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
|
||||
//! Computes the set of exogenous variables in the expression
|
||||
/*!
|
||||
Exogenous are stored as integer pairs of the form (type_specific_id, lag).
|
||||
They are added to the set given in argument.
|
||||
Note that model local variables are substituted by their expression in the computation.
|
||||
*/
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const = 0;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
|
||||
//! Computes the set of model local variables in the expression
|
||||
/*!
|
||||
Symbol IDs of these model local variables are added to the set given in argument.
|
||||
Note that this method is called recursively on the expressions associated to the model local variables detected.
|
||||
*/
|
||||
virtual void collectModelLocalVariables(set<int> &result) const;
|
||||
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const = 0;
|
||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||
|
@ -213,8 +231,7 @@ private:
|
|||
public:
|
||||
NumConstNode(DataTree &datatree_arg, int id_arg);
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||
|
@ -237,8 +254,7 @@ private:
|
|||
public:
|
||||
VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg, int deriv_id_arg);
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||
temporary_terms_type &temporary_terms,
|
||||
map<NodeID, pair<int, int> > &first_occurence,
|
||||
|
@ -276,8 +292,7 @@ public:
|
|||
Model_Block *ModelBlock,
|
||||
int equation,
|
||||
map_idx_type &map_idx) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
static double eval_opcode(UnaryOpcode op_code, double v) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
|
@ -314,8 +329,7 @@ public:
|
|||
Model_Block *ModelBlock,
|
||||
int equation,
|
||||
map_idx_type &map_idx) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
static double eval_opcode(double v1, BinaryOpcode op_code, double v2) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
|
@ -355,8 +369,7 @@ public:
|
|||
Model_Block *ModelBlock,
|
||||
int equation,
|
||||
map_idx_type &map_idx) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
static double eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
|
@ -385,8 +398,7 @@ public:
|
|||
Model_Block *ModelBlock,
|
||||
int equation,
|
||||
map_idx_type &map_idx) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
#ifdef DEBUG
|
||||
# include <ext/functional>
|
||||
using namespace __gnu_cxx;
|
||||
#endif
|
||||
|
||||
#include <boost/graph/adjacency_list.hpp>
|
||||
|
@ -321,7 +320,7 @@ StaticModel::computeNormalization()
|
|||
n1++;
|
||||
|
||||
pair<multimap<int, int>::const_iterator, multimap<int, int>::const_iterator> x = natural_endo2eqs.equal_range(i);
|
||||
if (find_if(x.first, x.second, compose1(bind2nd(equal_to<int>(), endo2eq[i]), select2nd<multimap<int, int>::value_type>())) == x.second)
|
||||
if (find_if(x.first, x.second, compose1(bind2nd(equal_to<int>(), endo2eq[i]), __gnu_cxx::select2nd<multimap<int, int>::value_type>())) == x.second)
|
||||
cout << "Natural normalization of variable " << symbol_table.getName(symbol_table.getID(eEndogenous, i))
|
||||
<< " not used." << endl;
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue