- the "steady_state" function is implemented with the "bytecode" option
git-svn-id: https://www.dynare.org/svn/dynare/trunk@2952 ac1d8469-bf42-47a9-8791-bf33cf982152issue#70
parent
e337789b54
commit
0c7fea9e5f
|
@ -41,13 +41,13 @@ const char FEND=17;
|
||||||
const char FOK=18;
|
const char FOK=18;
|
||||||
const char FENDEQU=19;
|
const char FENDEQU=19;
|
||||||
const char FLDSV=20;
|
const char FLDSV=20;
|
||||||
const char FSTPSV=21;
|
const char FLDVS=21;
|
||||||
const char FLDSU=22;
|
const char FSTPSV=22;
|
||||||
const char FSTPSU=23;
|
const char FLDSU=23;
|
||||||
const char FLDST=24;
|
const char FSTPSU=24;
|
||||||
const char FSTPST=25;
|
const char FLDST=25;
|
||||||
const char FDIMST=26;
|
const char FSTPST=26;
|
||||||
|
const char FDIMST=27;
|
||||||
|
|
||||||
|
|
||||||
enum BlockType
|
enum BlockType
|
||||||
|
|
|
@ -60,7 +60,7 @@ DynamicModel::compileDerivative(ofstream &code_file, int eq, int symb_id, int la
|
||||||
//first_derivatives_type::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symb_id, lag)));
|
//first_derivatives_type::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symb_id, lag)));
|
||||||
first_derivatives_type::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symbol_table.getID(eEndogenous, symb_id), lag)));
|
first_derivatives_type::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symbol_table.getID(eEndogenous, symb_id), lag)));
|
||||||
if (it != first_derivatives.end())
|
if (it != first_derivatives.end())
|
||||||
(it->second)->compile(code_file, false, temporary_terms, map_idx, true);
|
(it->second)->compile(code_file, false, temporary_terms, map_idx, true, false);
|
||||||
else
|
else
|
||||||
code_file.write(&FLDZ, sizeof(FLDZ));
|
code_file.write(&FLDZ, sizeof(FLDZ));
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ DynamicModel::compileChainRuleDerivative(ofstream &code_file, int eqr, int varr,
|
||||||
{
|
{
|
||||||
map<pair<int, pair<int, int> >, NodeID>::const_iterator it = first_chain_rule_derivatives.find(make_pair(eqr, make_pair(varr, lag)));
|
map<pair<int, pair<int, int> >, NodeID>::const_iterator it = first_chain_rule_derivatives.find(make_pair(eqr, make_pair(varr, lag)));
|
||||||
if (it != first_chain_rule_derivatives.end())
|
if (it != first_chain_rule_derivatives.end())
|
||||||
(it->second)->compile(code_file, false, temporary_terms, map_idx, true);
|
(it->second)->compile(code_file, false, temporary_terms, map_idx, true, false);
|
||||||
else
|
else
|
||||||
code_file.write(&FLDZ, sizeof(FLDZ));
|
code_file.write(&FLDZ, sizeof(FLDZ));
|
||||||
}
|
}
|
||||||
|
@ -934,7 +934,7 @@ DynamicModel::writeModelEquationsCodeOrdered(const string file_name, const Model
|
||||||
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->begin();
|
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->begin();
|
||||||
it != ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->end(); it++)
|
it != ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->end(); it++)
|
||||||
{
|
{
|
||||||
(*it)->compile(code_file, false, tt2, map_idx, true);
|
(*it)->compile(code_file, false, tt2, map_idx, true, false);
|
||||||
code_file.write(&FSTPT, sizeof(FSTPT));
|
code_file.write(&FSTPT, sizeof(FSTPT));
|
||||||
map_idx_type::const_iterator ii=map_idx.find((*it)->idx);
|
map_idx_type::const_iterator ii=map_idx.find((*it)->idx);
|
||||||
v=(int)ii->second;
|
v=(int)ii->second;
|
||||||
|
@ -967,16 +967,16 @@ evaluation:
|
||||||
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
|
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
rhs->compile(code_file, false, temporary_terms, map_idx, true);
|
rhs->compile(code_file, false, temporary_terms, map_idx, true, false);
|
||||||
lhs->compile(code_file, true, temporary_terms, map_idx, true);
|
lhs->compile(code_file, true, temporary_terms, map_idx, true, false);
|
||||||
}
|
}
|
||||||
else if (ModelBlock->Block_List[j].Equation_Type[i] == E_EVALUATE_S)
|
else if (ModelBlock->Block_List[j].Equation_Type[i] == E_EVALUATE_S)
|
||||||
{
|
{
|
||||||
eq_node = (BinaryOpNode*)ModelBlock->Block_List[j].Equation_Normalized[i];
|
eq_node = (BinaryOpNode*)ModelBlock->Block_List[j].Equation_Normalized[i];
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
rhs->compile(code_file, false, temporary_terms, map_idx, true);
|
rhs->compile(code_file, false, temporary_terms, map_idx, true, false);
|
||||||
lhs->compile(code_file, true, temporary_terms, map_idx, true);
|
lhs->compile(code_file, true, temporary_terms, map_idx, true, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SOLVE_BACKWARD_COMPLETE:
|
case SOLVE_BACKWARD_COMPLETE:
|
||||||
|
@ -994,8 +994,8 @@ end:
|
||||||
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
|
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
lhs->compile(code_file, false, temporary_terms, map_idx, true);
|
lhs->compile(code_file, false, temporary_terms, map_idx, true, false);
|
||||||
rhs->compile(code_file, false, temporary_terms, map_idx, true);
|
rhs->compile(code_file, false, temporary_terms, map_idx, true, false);
|
||||||
code_file.write(&FBINARY, sizeof(FBINARY));
|
code_file.write(&FBINARY, sizeof(FBINARY));
|
||||||
int v=oMinus;
|
int v=oMinus;
|
||||||
code_file.write(reinterpret_cast<char *>(&v),sizeof(v));
|
code_file.write(reinterpret_cast<char *>(&v),sizeof(v));
|
||||||
|
|
119
ExprNode.cc
119
ExprNode.cc
|
@ -191,7 +191,7 @@ NumConstNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NumConstNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
NumConstNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const
|
||||||
{
|
{
|
||||||
CompileCode.write(&FLDC, sizeof(FLDC));
|
CompileCode.write(&FLDC, sizeof(FLDC));
|
||||||
double vard = datatree.num_constants.getDouble(id);
|
double vard = datatree.num_constants.getDouble(id);
|
||||||
|
@ -379,9 +379,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
case oMatlabOutsideModel:
|
case oMatlabOutsideModel:
|
||||||
output << "oo_.steady_state(" << tsid + 1 << ")";
|
output << "oo_.steady_state(" << tsid + 1 << ")";
|
||||||
break;
|
break;
|
||||||
case oMatlabDynamicSteadyStateOperator:
|
case oMatlabDynamicSteadyStateOperator:
|
||||||
output << "oo_.steady_state(" << tsid + 1 << ")";
|
output << "oo_.steady_state(" << tsid + 1 << ")";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
@ -416,9 +416,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
assert(lag == 0);
|
assert(lag == 0);
|
||||||
output << "oo_.exo_steady_state(" << i << ")";
|
output << "oo_.exo_steady_state(" << i << ")";
|
||||||
break;
|
break;
|
||||||
case oMatlabDynamicSteadyStateOperator:
|
case oMatlabDynamicSteadyStateOperator:
|
||||||
output << "oo_.exo_steady_state(" << i << ")";
|
output << "oo_.exo_steady_state(" << i << ")";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
@ -478,20 +478,34 @@ VariableNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const
|
||||||
{
|
{
|
||||||
int i, lagl;
|
int i, lagl;
|
||||||
if (!lhs_rhs)
|
if (!lhs_rhs)
|
||||||
{
|
{
|
||||||
if(dynamic)
|
if(dynamic)
|
||||||
CompileCode.write(&FLDV, sizeof(FLDV));
|
{
|
||||||
|
if(steady_dynamic) // steady state values in a dynamic model
|
||||||
|
CompileCode.write(&FLDVS, sizeof(FLDVS));
|
||||||
|
else
|
||||||
|
CompileCode.write(&FLDV, sizeof(FLDV));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
CompileCode.write(&FLDSV, sizeof(FLDSV));
|
CompileCode.write(&FLDSV, sizeof(FLDSV));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(dynamic)
|
if(dynamic)
|
||||||
CompileCode.write(&FSTPV, sizeof(FSTPV));
|
{
|
||||||
|
if(steady_dynamic) // steady state values in a dynamic model
|
||||||
|
{
|
||||||
|
/*CompileCode.write(&FLDVS, sizeof(FLDVS));*/
|
||||||
|
cerr << "Impossible case: steady_state in rhs of equation" << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CompileCode.write(&FSTPV, sizeof(FSTPV));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
CompileCode.write(&FSTPSV, sizeof(FSTPSV));
|
CompileCode.write(&FSTPSV, sizeof(FSTPSV));
|
||||||
}
|
}
|
||||||
|
@ -509,7 +523,7 @@ VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_
|
||||||
//cout << "Endogenous=" << symb_id << "\n";
|
//cout << "Endogenous=" << symb_id << "\n";
|
||||||
i = tsid;//symb_id;
|
i = tsid;//symb_id;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||||
if(dynamic)
|
if(dynamic && !steady_dynamic)
|
||||||
{
|
{
|
||||||
lagl=lag;
|
lagl=lag;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||||
|
@ -519,7 +533,7 @@ VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_
|
||||||
//cout << "Exogenous=" << tsid << "\n";
|
//cout << "Exogenous=" << tsid << "\n";
|
||||||
i = tsid;
|
i = tsid;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||||
if(dynamic)
|
if(dynamic && !steady_dynamic)
|
||||||
{
|
{
|
||||||
lagl=lag;
|
lagl=lag;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||||
|
@ -529,7 +543,7 @@ VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_
|
||||||
i = tsid + datatree.symbol_table.exo_nbr();
|
i = tsid + datatree.symbol_table.exo_nbr();
|
||||||
//cout << "ExogenousDet=" << i << "\n";
|
//cout << "ExogenousDet=" << i << "\n";
|
||||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||||
if(dynamic)
|
if(dynamic && !steady_dynamic)
|
||||||
{
|
{
|
||||||
lagl=lag;
|
lagl=lag;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||||
|
@ -538,7 +552,7 @@ VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_
|
||||||
case eModelLocalVariable:
|
case eModelLocalVariable:
|
||||||
case eModFileLocalVariable:
|
case eModFileLocalVariable:
|
||||||
//cout << "eModelLocalVariable=" << symb_id << "\n";
|
//cout << "eModelLocalVariable=" << symb_id << "\n";
|
||||||
datatree.local_variables_table[symb_id]->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
datatree.local_variables_table[symb_id]->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic);
|
||||||
break;
|
break;
|
||||||
case eUnknownFunction:
|
case eUnknownFunction:
|
||||||
cerr << "Impossible case: eUnknownFuncion" << endl;
|
cerr << "Impossible case: eUnknownFuncion" << endl;
|
||||||
|
@ -886,7 +900,7 @@ UnaryOpNode::collectTemporary_terms(const temporary_terms_type &temporary_terms,
|
||||||
void
|
void
|
||||||
UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
const temporary_terms_type &temporary_terms) const
|
const temporary_terms_type &temporary_terms) const
|
||||||
{
|
{
|
||||||
// If node is a temporary term
|
// If node is a temporary term
|
||||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
|
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
|
||||||
if (it != temporary_terms.end())
|
if (it != temporary_terms.end())
|
||||||
|
@ -958,28 +972,28 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
case oSqrt:
|
case oSqrt:
|
||||||
output << "sqrt";
|
output << "sqrt";
|
||||||
break;
|
break;
|
||||||
case oSteadyState:
|
case oSteadyState:
|
||||||
ExprNodeOutputType new_output_type;
|
ExprNodeOutputType new_output_type;
|
||||||
switch(output_type)
|
switch(output_type)
|
||||||
{
|
{
|
||||||
case oMatlabDynamicModel:
|
case oMatlabDynamicModel:
|
||||||
new_output_type = oMatlabDynamicSteadyStateOperator;
|
new_output_type = oMatlabDynamicSteadyStateOperator;
|
||||||
break;
|
break;
|
||||||
case oLatexDynamicModel:
|
case oLatexDynamicModel:
|
||||||
new_output_type = oLatexDynamicSteadyStateOperator;
|
new_output_type = oLatexDynamicSteadyStateOperator;
|
||||||
break;
|
break;
|
||||||
case oCDynamicModel:
|
case oCDynamicModel:
|
||||||
cerr << "Steady State Operator not implemented for oCDynamicModel." << endl;
|
cerr << "Steady State Operator not implemented for oCDynamicModel." << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
case oMatlabDynamicModelSparse:
|
case oMatlabDynamicModelSparse:
|
||||||
cerr << "Steady State Operator not implemented for oMatlabDynamicModelSparse." << endl;
|
cerr << "Steady State Operator not implemented for oMatlabDynamicModelSparse." << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
default:
|
default:
|
||||||
new_output_type = output_type;
|
new_output_type = output_type;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
arg->writeOutput(output, new_output_type, temporary_terms);
|
arg->writeOutput(output, new_output_type, temporary_terms);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool close_parenthesis = false;
|
bool close_parenthesis = false;
|
||||||
|
@ -988,7 +1002,7 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
- current opcode is not uminus, or
|
- current opcode is not uminus, or
|
||||||
- current opcode is uminus and argument has lowest precedence
|
- current opcode is uminus and argument has lowest precedence
|
||||||
*/
|
*/
|
||||||
if (op_code != oUminus
|
if (op_code != oUminus
|
||||||
|| (op_code == oUminus
|
|| (op_code == oUminus
|
||||||
&& arg->precedence(output_type, temporary_terms) < precedence(output_type, temporary_terms)))
|
&& arg->precedence(output_type, temporary_terms) < precedence(output_type, temporary_terms)))
|
||||||
{
|
{
|
||||||
|
@ -1062,7 +1076,7 @@ UnaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcept
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const
|
||||||
{
|
{
|
||||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
|
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
|
||||||
if (it != temporary_terms.end())
|
if (it != temporary_terms.end())
|
||||||
|
@ -1075,10 +1089,15 @@ UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_t
|
||||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arg->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
if (op_code == oSteadyState)
|
||||||
CompileCode.write(&FUNARY, sizeof(FUNARY));
|
arg->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic, true);
|
||||||
UnaryOpcode op_codel=op_code;
|
else
|
||||||
CompileCode.write(reinterpret_cast<char *>(&op_codel), sizeof(op_codel));
|
{
|
||||||
|
arg->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic);
|
||||||
|
CompileCode.write(&FUNARY, sizeof(FUNARY));
|
||||||
|
UnaryOpcode op_codel=op_code;
|
||||||
|
CompileCode.write(reinterpret_cast<char *>(&op_codel), sizeof(op_codel));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1557,7 +1576,7 @@ BinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
BinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const
|
||||||
{
|
{
|
||||||
// If current node is a temporary term
|
// If current node is a temporary term
|
||||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this));
|
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this));
|
||||||
|
@ -1571,8 +1590,8 @@ BinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_
|
||||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic);
|
||||||
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic);
|
||||||
CompileCode.write(&FBINARY, sizeof(FBINARY));
|
CompileCode.write(&FBINARY, sizeof(FBINARY));
|
||||||
BinaryOpcode op_codel=op_code;
|
BinaryOpcode op_codel=op_code;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&op_codel),sizeof(op_codel));
|
CompileCode.write(reinterpret_cast<char *>(&op_codel),sizeof(op_codel));
|
||||||
|
@ -2291,7 +2310,7 @@ TrinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExce
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TrinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
TrinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const
|
||||||
{
|
{
|
||||||
// If current node is a temporary term
|
// If current node is a temporary term
|
||||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this));
|
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this));
|
||||||
|
@ -2305,9 +2324,9 @@ TrinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms
|
||||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic);
|
||||||
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic);
|
||||||
arg3->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
|
arg3->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic);
|
||||||
CompileCode.write(&FBINARY, sizeof(FBINARY));
|
CompileCode.write(&FBINARY, sizeof(FBINARY));
|
||||||
TrinaryOpcode op_codel=op_code;
|
TrinaryOpcode op_codel=op_code;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&op_codel),sizeof(op_codel));
|
CompileCode.write(reinterpret_cast<char *>(&op_codel),sizeof(op_codel));
|
||||||
|
@ -2497,7 +2516,7 @@ UnknownFunctionNode::eval(const eval_context_type &eval_context) const throw (Ev
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UnknownFunctionNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
|
UnknownFunctionNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const
|
||||||
{
|
{
|
||||||
cerr << "UnknownFunctionNode::compile: operation impossible!" << endl;
|
cerr << "UnknownFunctionNode::compile: operation impossible!" << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
16
ExprNode.hh
16
ExprNode.hh
|
@ -76,7 +76,7 @@ enum ExprNodeOutputType
|
||||||
|
|
||||||
#define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
|
#define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
|
||||||
|| (output_type) == oLatexDynamicModel \
|
|| (output_type) == oLatexDynamicModel \
|
||||||
|| (output_type) == oLatexDynamicSteadyStateOperator)
|
|| (output_type) == oLatexDynamicSteadyStateOperator)
|
||||||
|
|
||||||
/* Equal to 1 for Matlab langage, or to 0 for C language. Not defined for LaTeX.
|
/* Equal to 1 for Matlab langage, or to 0 for C language. Not defined for LaTeX.
|
||||||
In Matlab, array indexes begin at 1, while they begin at 0 in C */
|
In Matlab, array indexes begin at 1, while they begin at 0 in C */
|
||||||
|
@ -207,7 +207,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException) = 0;
|
virtual double eval(const eval_context_type &eval_context) const throw (EvalException) = 0;
|
||||||
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const = 0;
|
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const = 0;
|
||||||
//! Creates a static version of this node
|
//! Creates a static version of this node
|
||||||
/*!
|
/*!
|
||||||
This method duplicates the current node by creating a similar node from which all leads/lags have been stripped,
|
This method duplicates the current node by creating a similar node from which all leads/lags have been stripped,
|
||||||
|
@ -241,7 +241,7 @@ public:
|
||||||
virtual void collectVariables(SymbolType type_arg, 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 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 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, bool dynamic) const;
|
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const;
|
||||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||||
|
@ -271,7 +271,7 @@ public:
|
||||||
map_idx_type &map_idx) const;
|
map_idx_type &map_idx) const;
|
||||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) 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 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, bool dynamic) const;
|
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const;
|
||||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||||
int get_symb_id() const { return symb_id; };
|
int get_symb_id() const { return symb_id; };
|
||||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||||
|
@ -303,7 +303,7 @@ public:
|
||||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) 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);
|
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(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const;
|
||||||
//! Returns operand
|
//! Returns operand
|
||||||
NodeID get_arg() const { return(arg); };
|
NodeID get_arg() const { return(arg); };
|
||||||
//! Returns op code
|
//! Returns op code
|
||||||
|
@ -340,7 +340,7 @@ public:
|
||||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) 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);
|
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(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const;
|
||||||
virtual NodeID Compute_RHS(NodeID arg1, NodeID arg2, int op, int op_type) const;
|
virtual NodeID Compute_RHS(NodeID arg1, NodeID arg2, int op, int op_type) const;
|
||||||
//! Returns first operand
|
//! Returns first operand
|
||||||
NodeID get_arg1() const { return(arg1); };
|
NodeID get_arg1() const { return(arg1); };
|
||||||
|
@ -381,7 +381,7 @@ public:
|
||||||
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) 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);
|
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(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
|
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const;
|
||||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||||
|
@ -409,7 +409,7 @@ public:
|
||||||
virtual void collectVariables(SymbolType type_arg, 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 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 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, bool dynamic) const;
|
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic, bool steady_dynamic) const;
|
||||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||||
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
|
||||||
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
|
||||||
|
|
|
@ -60,7 +60,7 @@ StaticDllModel::compileDerivative(ofstream &code_file, int eq, int symb_id, int
|
||||||
//first_derivatives_type::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symb_id, lag)));
|
//first_derivatives_type::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symb_id, lag)));
|
||||||
first_derivatives_type::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symbol_table.getID(eEndogenous, symb_id), lag)));
|
first_derivatives_type::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symbol_table.getID(eEndogenous, symb_id), lag)));
|
||||||
if (it != first_derivatives.end())
|
if (it != first_derivatives.end())
|
||||||
(it->second)->compile(code_file, false, temporary_terms, map_idx, false);
|
(it->second)->compile(code_file, false, temporary_terms, map_idx, false, false);
|
||||||
else
|
else
|
||||||
code_file.write(&FLDZ, sizeof(FLDZ));
|
code_file.write(&FLDZ, sizeof(FLDZ));
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ StaticDllModel::compileChainRuleDerivative(ofstream &code_file, int eqr, int var
|
||||||
{
|
{
|
||||||
map<pair<int, pair<int, int> >, NodeID>::const_iterator it = first_chain_rule_derivatives.find(make_pair(eqr, make_pair(varr, lag)));
|
map<pair<int, pair<int, int> >, NodeID>::const_iterator it = first_chain_rule_derivatives.find(make_pair(eqr, make_pair(varr, lag)));
|
||||||
if (it != first_chain_rule_derivatives.end())
|
if (it != first_chain_rule_derivatives.end())
|
||||||
(it->second)->compile(code_file, false, temporary_terms, map_idx, false);
|
(it->second)->compile(code_file, false, temporary_terms, map_idx, false, false);
|
||||||
else
|
else
|
||||||
code_file.write(&FLDZ, sizeof(FLDZ));
|
code_file.write(&FLDZ, sizeof(FLDZ));
|
||||||
}
|
}
|
||||||
|
@ -435,7 +435,7 @@ StaticDllModel::writeModelEquationsCodeOrdered(const string file_name, const Mod
|
||||||
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->begin();
|
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->begin();
|
||||||
it != ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->end(); it++)
|
it != ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->end(); it++)
|
||||||
{
|
{
|
||||||
(*it)->compile(code_file, false, tt2, map_idx, false);
|
(*it)->compile(code_file, false, tt2, map_idx, false, false);
|
||||||
code_file.write(&FSTPST, sizeof(FSTPST));
|
code_file.write(&FSTPST, sizeof(FSTPST));
|
||||||
map_idx_type::const_iterator ii=map_idx.find((*it)->idx);
|
map_idx_type::const_iterator ii=map_idx.find((*it)->idx);
|
||||||
v=(int)ii->second;
|
v=(int)ii->second;
|
||||||
|
@ -453,16 +453,16 @@ evaluation:
|
||||||
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
|
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
rhs->compile(code_file, false, temporary_terms, map_idx, false);
|
rhs->compile(code_file, false, temporary_terms, map_idx, false, false);
|
||||||
lhs->compile(code_file, true, temporary_terms, map_idx, false);
|
lhs->compile(code_file, true, temporary_terms, map_idx, false, false);
|
||||||
}
|
}
|
||||||
else if (ModelBlock->Block_List[j].Equation_Type[i] == E_EVALUATE_S)
|
else if (ModelBlock->Block_List[j].Equation_Type[i] == E_EVALUATE_S)
|
||||||
{
|
{
|
||||||
eq_node = (BinaryOpNode*)ModelBlock->Block_List[j].Equation_Normalized[i];
|
eq_node = (BinaryOpNode*)ModelBlock->Block_List[j].Equation_Normalized[i];
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
rhs->compile(code_file, false, temporary_terms, map_idx, false);
|
rhs->compile(code_file, false, temporary_terms, map_idx, false, false);
|
||||||
lhs->compile(code_file, true, temporary_terms, map_idx, false);
|
lhs->compile(code_file, true, temporary_terms, map_idx, false, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SOLVE_BACKWARD_COMPLETE:
|
case SOLVE_BACKWARD_COMPLETE:
|
||||||
|
@ -478,8 +478,8 @@ end:
|
||||||
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
|
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
|
||||||
lhs = eq_node->get_arg1();
|
lhs = eq_node->get_arg1();
|
||||||
rhs = eq_node->get_arg2();
|
rhs = eq_node->get_arg2();
|
||||||
lhs->compile(code_file, false, temporary_terms, map_idx, false);
|
lhs->compile(code_file, false, temporary_terms, map_idx, false, false);
|
||||||
rhs->compile(code_file, false, temporary_terms, map_idx, false);
|
rhs->compile(code_file, false, temporary_terms, map_idx, false, false);
|
||||||
code_file.write(&FBINARY, sizeof(FBINARY));
|
code_file.write(&FBINARY, sizeof(FBINARY));
|
||||||
int v=oMinus;
|
int v=oMinus;
|
||||||
code_file.write(reinterpret_cast<char *>(&v),sizeof(v));
|
code_file.write(reinterpret_cast<char *>(&v),sizeof(v));
|
||||||
|
|
Loading…
Reference in New Issue