v4 preprocessor: rewrote ExprNode::collectEndogenous()
git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1778 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
6ca15f8a95
commit
1e6b15f042
|
@ -73,18 +73,6 @@ ExprNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab) cons
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
ExprNode::present_endogenous_size() const
|
|
||||||
{
|
|
||||||
return(present_endogenous.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ExprNode::present_endogenous_find(int var, int lag) const
|
|
||||||
{
|
|
||||||
return(present_endogenous.find(make_pair(var,lag))!=present_endogenous.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
temporary_terms_type &temporary_terms,
|
temporary_terms_type &temporary_terms,
|
||||||
|
@ -172,7 +160,7 @@ NumConstNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType ou
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NumConstNode::collectEndogenous(NodeID &Id)
|
NumConstNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,10 +467,10 @@ VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType ou
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VariableNode::collectEndogenous(NodeID &Id)
|
VariableNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||||
{
|
{
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
Id->present_endogenous.insert(make_pair(symb_id, lag));
|
result.insert(make_pair(symb_id, lag));
|
||||||
}
|
}
|
||||||
|
|
||||||
UnaryOpNode::UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const NodeID arg_arg) :
|
UnaryOpNode::UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const NodeID arg_arg) :
|
||||||
|
@ -871,9 +859,9 @@ UnaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType out
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UnaryOpNode::collectEndogenous(NodeID &Id)
|
UnaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||||
{
|
{
|
||||||
arg->collectEndogenous(Id);
|
arg->collectEndogenous(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryOpNode::BinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
BinaryOpNode::BinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
||||||
|
@ -1328,10 +1316,10 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BinaryOpNode::collectEndogenous(NodeID &Id)
|
BinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||||
{
|
{
|
||||||
arg1->collectEndogenous(Id);
|
arg1->collectEndogenous(result);
|
||||||
arg2->collectEndogenous(Id);
|
arg2->collectEndogenous(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
TrinaryOpNode::TrinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
TrinaryOpNode::TrinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
||||||
|
@ -1595,11 +1583,11 @@ TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TrinaryOpNode::collectEndogenous(NodeID &Id)
|
TrinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||||
{
|
{
|
||||||
arg1->collectEndogenous(Id);
|
arg1->collectEndogenous(result);
|
||||||
arg2->collectEndogenous(Id);
|
arg2->collectEndogenous(result);
|
||||||
arg3->collectEndogenous(Id);
|
arg3->collectEndogenous(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnknownFunctionNode::UnknownFunctionNode(DataTree &datatree_arg,
|
UnknownFunctionNode::UnknownFunctionNode(DataTree &datatree_arg,
|
||||||
|
@ -1655,10 +1643,11 @@ UnknownFunctionNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UnknownFunctionNode::collectEndogenous(NodeID &Id)
|
UnknownFunctionNode::collectEndogenous(set<pair<int, int> > &result) const
|
||||||
{
|
{
|
||||||
cerr << "UnknownFunctionNode::collectEndogenous: not implemented" << endl;
|
for(vector<NodeID>::const_iterator it = arguments.begin();
|
||||||
exit(-1);
|
it != arguments.end(); it++)
|
||||||
|
(*it)->collectEndogenous(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
|
|
|
@ -3647,12 +3647,13 @@ ModelTree::BlockLinear(Model_Block *ModelBlock)
|
||||||
if (it!= first_derivatives.end())
|
if (it!= first_derivatives.end())
|
||||||
{
|
{
|
||||||
NodeID Id = it->second;
|
NodeID Id = it->second;
|
||||||
Id->collectEndogenous(Id);
|
set<pair<int, int> > endogenous;
|
||||||
if (Id->present_endogenous_size()>0)
|
Id->collectEndogenous(endogenous);
|
||||||
|
if (endogenous.size() > 0)
|
||||||
{
|
{
|
||||||
for(l=0;l<ModelBlock->Block_List[j].Size;l++)
|
for(l=0;l<ModelBlock->Block_List[j].Size;l++)
|
||||||
{
|
{
|
||||||
if (Id->present_endogenous_find(ModelBlock->Block_List[j].Variable[l],0))
|
if (endogenous.find(make_pair(ModelBlock->Block_List[j].Variable[l], 0)) != endogenous.end())
|
||||||
{
|
{
|
||||||
ModelBlock->Block_List[j].is_linear=false;
|
ModelBlock->Block_List[j].is_linear=false;
|
||||||
goto follow;
|
goto follow;
|
||||||
|
@ -3675,12 +3676,13 @@ ModelTree::BlockLinear(Model_Block *ModelBlock)
|
||||||
NodeID Id = it->second;
|
NodeID Id = it->second;
|
||||||
if (it!= first_derivatives.end())
|
if (it!= first_derivatives.end())
|
||||||
{
|
{
|
||||||
Id->collectEndogenous(Id);
|
set<pair<int, int> > endogenous;
|
||||||
if (Id->present_endogenous_size()>0)
|
Id->collectEndogenous(endogenous);
|
||||||
|
if (endogenous.size() > 0)
|
||||||
{
|
{
|
||||||
for(l=0;l<ModelBlock->Block_List[j].Size;l++)
|
for(l=0;l<ModelBlock->Block_List[j].Size;l++)
|
||||||
{
|
{
|
||||||
if (Id->present_endogenous_find(ModelBlock->Block_List[j].Variable[l],k1))
|
if (endogenous.find(make_pair(ModelBlock->Block_List[j].Variable[l], k1)) != endogenous.end())
|
||||||
{
|
{
|
||||||
ModelBlock->Block_List[j].is_linear=false;
|
ModelBlock->Block_List[j].is_linear=false;
|
||||||
goto follow;
|
goto follow;
|
||||||
|
|
|
@ -116,10 +116,6 @@ protected:
|
||||||
/*! Nodes included in temporary_terms are considered having a null cost */
|
/*! Nodes included in temporary_terms are considered having a null cost */
|
||||||
virtual int cost(const temporary_terms_type &temporary_terms, bool is_matlab) const;
|
virtual int cost(const temporary_terms_type &temporary_terms, bool is_matlab) const;
|
||||||
|
|
||||||
//! set of endogenous variables in the current expression
|
|
||||||
//! <symbolID, lag>
|
|
||||||
set< pair<int,int> > present_endogenous;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExprNode(DataTree &datatree_arg);
|
ExprNode(DataTree &datatree_arg);
|
||||||
virtual ~ExprNode();
|
virtual ~ExprNode();
|
||||||
|
@ -143,16 +139,16 @@ public:
|
||||||
//! Writes output of node (with no temporary terms and with "outside model" output type)
|
//! Writes output of node (with no temporary terms and with "outside model" output type)
|
||||||
void writeOutput(ostream &output);
|
void writeOutput(ostream &output);
|
||||||
|
|
||||||
//! Collects the Endogenous in a expression
|
//! Computes the set of endogenous variables in the expression
|
||||||
virtual void collectEndogenous(NodeID &Id) = 0;
|
/*! Endogenous are stored as integer pairs of the form (symb_id, lag)
|
||||||
|
They are added to the set given in argument */
|
||||||
|
virtual void collectEndogenous(set<pair<int, int> > &result) const = 0;
|
||||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
temporary_terms_type &temporary_terms,
|
temporary_terms_type &temporary_terms,
|
||||||
map<NodeID, int> &first_occurence,
|
map<NodeID, int> &first_occurence,
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
Model_Block *ModelBlock,
|
Model_Block *ModelBlock,
|
||||||
map_idx_type &map_idx) const;
|
map_idx_type &map_idx) const;
|
||||||
int present_endogenous_size() const;
|
|
||||||
int present_endogenous_find(int var, int lag) const;
|
|
||||||
|
|
||||||
class EvalException
|
class EvalException
|
||||||
{
|
{
|
||||||
|
@ -182,7 +178,7 @@ private:
|
||||||
public:
|
public:
|
||||||
NumConstNode(DataTree &datatree_arg, int id_arg);
|
NumConstNode(DataTree &datatree_arg, int id_arg);
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||||
};
|
};
|
||||||
|
@ -201,7 +197,7 @@ private:
|
||||||
public:
|
public:
|
||||||
VariableNode(DataTree &datatree_arg, int symb_id_arg, Type type_arg, int lag_arg);
|
VariableNode(DataTree &datatree_arg, int symb_id_arg, Type type_arg, int lag_arg);
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms = temporary_terms_type()) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms = temporary_terms_type()) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||||
};
|
};
|
||||||
|
@ -226,7 +222,7 @@ public:
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
Model_Block *ModelBlock,
|
Model_Block *ModelBlock,
|
||||||
map_idx_type &map_idx) const;
|
map_idx_type &map_idx) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||||
static double eval_opcode(UnaryOpcode op_code, double v) throw (EvalException);
|
static double eval_opcode(UnaryOpcode op_code, double v) throw (EvalException);
|
||||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||||
|
@ -253,7 +249,7 @@ public:
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
Model_Block *ModelBlock,
|
Model_Block *ModelBlock,
|
||||||
map_idx_type &map_idx) const;
|
map_idx_type &map_idx) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||||
static double eval_opcode(double v1, BinaryOpcode op_code, double v2) throw (EvalException);
|
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);
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||||
|
@ -285,7 +281,7 @@ public:
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
Model_Block *ModelBlock,
|
Model_Block *ModelBlock,
|
||||||
map_idx_type &map_idx) const;
|
map_idx_type &map_idx) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||||
static double eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException);
|
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);
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||||
|
@ -310,7 +306,7 @@ public:
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
Model_Block *ModelBlock,
|
Model_Block *ModelBlock,
|
||||||
map_idx_type &map_idx) const;
|
map_idx_type &map_idx) const;
|
||||||
virtual void collectEndogenous(NodeID &Id);
|
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue