Commit 892d6524 authored by ferhat's avatar ferhat
Browse files

- forgotten files in the previous upload: MatlabFile.cc and MatlabFile.hh

- temporary terms computed just before the equation where they appeared => important for "evaluated blocks" where temporary terms depend on endogenous computed in the block

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2351 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 644d8c8a
......@@ -108,19 +108,18 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
bool *tmp_variable_evaluated;
bool *Cur_IM;
bool *IM, OK;
ModelBlock->Periods = periods;
int Lag_Endo, Lead_Endo, Lag_Exo, Lead_Exo, Lag_Other_Endo, Lead_Other_Endo;
ModelBlock->Periods = periods;
ModelBlock->Block_List[count_Block].is_linear=true;
ModelBlock->Block_List[count_Block].Size = size;
ModelBlock->Block_List[count_Block].Type = type;
ModelBlock->Block_List[count_Block].Temporary_terms=new temporary_terms_type ();
ModelBlock->Block_List[count_Block].Temporary_terms->clear();
ModelBlock->Block_List[count_Block].Temporary_InUse=new temporary_terms_inuse_type ();
ModelBlock->Block_List[count_Block].Temporary_InUse->clear();
ModelBlock->Block_List[count_Block].Simulation_Type = SimType;
ModelBlock->Block_List[count_Block].Equation = (int*)malloc(ModelBlock->Block_List[count_Block].Size * sizeof(int));
ModelBlock->Block_List[count_Block].Variable = (int*)malloc(ModelBlock->Block_List[count_Block].Size * sizeof(int));
ModelBlock->Block_List[count_Block].Temporary_Terms_in_Equation = (temporary_terms_type**)malloc(ModelBlock->Block_List[count_Block].Size * sizeof(temporary_terms_type));
ModelBlock->Block_List[count_Block].Own_Derivative = (int*)malloc(ModelBlock->Block_List[count_Block].Size * sizeof(int));
Lead = Lag = 0;
first_count_equ = *count_Equ;
......@@ -144,6 +143,8 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
memset(tmp_variable_evaluated, 0, symbol_table.endo_nbr*sizeof(bool));
for (i = 0;i < size;i++)
{
ModelBlock->Block_List[count_Block].Temporary_Terms_in_Equation[i]=new temporary_terms_type ();
ModelBlock->Block_List[count_Block].Temporary_Terms_in_Equation[i]->clear();
ModelBlock->Block_List[count_Block].Equation[i] = Index_Equ_IM[*count_Equ].index;
ModelBlock->Block_List[count_Block].Variable[i] = Index_Var_IM[*count_Equ].index;
i_1 = Index_Var_IM[*count_Equ].index;
......@@ -453,7 +454,9 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock) const
}
}
free(ModelBlock->Block_List[blk].IM_lead_lag);
delete(ModelBlock->Block_List[blk].Temporary_terms);
for(i=0; i<ModelBlock->Block_List[blk].Size; i++)
delete ModelBlock->Block_List[blk].Temporary_Terms_in_Equation[i];
free(ModelBlock->Block_List[blk].Temporary_Terms_in_Equation);
delete(ModelBlock->Block_List[blk].Temporary_InUse);
}
free(ModelBlock->Block_List);
......
......@@ -84,9 +84,10 @@ ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
void
ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
Model_Block *ModelBlock,
int equation,
map_idx_type &map_idx) const
{
// Nothing to do for a terminal node
......@@ -148,23 +149,12 @@ NumConstNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
void
NumConstNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const
{
//CompileCode.write(reinterpret_cast<char *>(&FLDT), sizeof(FLDT));
/*temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<NumConstNode *>(this));
if (it != temporary_terms.end())
{
CompileCode.write(&FLDT, sizeof(FLDT));
idl=
CompileCode.write(reinterpret_cast<char *>(&idl),sizeof(idl));
}
else
{*/
CompileCode.write(&FLDC, sizeof(FLDC));
double vard=atof(datatree.num_constants.get(id).c_str());
CompileCode.write(&FLDC, sizeof(FLDC));
double vard=atof(datatree.num_constants.get(id).c_str());
#ifdef DEBUGC
cout << "FLDC " << vard << "\n";
cout << "FLDC " << vard << "\n";
#endif
CompileCode.write(reinterpret_cast<char *>(&vard),sizeof(vard));
/*}*/
CompileCode.write(reinterpret_cast<char *>(&vard),sizeof(vard));
}
......@@ -427,15 +417,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
double
VariableNode::eval(const eval_context_type &eval_context) const throw (EvalException)
{
// ModelTree::evaluateJacobian need to have the initval values applied to lead/lagged variables also
/*if (lag != 0)
throw EvalException();*/
/*if(type==eModelLocalVariable)
cout << "eModelLocalVariable = " << symb_id << "\n";*/
eval_context_type::const_iterator it = eval_context.find(make_pair(symb_id, type));
if (it == eval_context.end())
{
//cout << "unknonw variable type = " << type << " simb_id = " << symb_id << "\n";
throw EvalException();
}
......@@ -445,15 +429,6 @@ VariableNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
void
VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const
{
// If node is a temporary term
/*temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<VariableNode *>(this));
if (it != temporary_terms.end())
{
CompileCode.write(&FLDT, sizeof(FLDT));
int var=temporary_terms.count(const_cast<VariableNode *>(this))-1;
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
return;
}*/
int i, lagl;
#ifdef DEBUGC
cout << "output_type=" << output_type << "\n";
......@@ -501,6 +476,23 @@ VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType ou
}
}
void
VariableNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
Model_Block *ModelBlock,
int equation,
map_idx_type &map_idx) const
{
if(type== eModelLocalVariable)
datatree.local_variables_table[symb_id]->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, equation, map_idx);
}
void
VariableNode::collectEndogenous(set<pair<int, int> > &result) const
{
......@@ -711,9 +703,10 @@ UnaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
void
UnaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
Model_Block *ModelBlock,
int equation,
map_idx_type &map_idx) const
{
NodeID this2 = const_cast<UnaryOpNode *>(this);
......@@ -721,8 +714,8 @@ UnaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
if (it == reference_count.end())
{
reference_count[this2] = 1;
first_occurence[this2] = Curr_block;
arg->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, map_idx);
first_occurence[this2] = make_pair(Curr_block,equation);
arg->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, equation, map_idx);
}
else
{
......@@ -730,7 +723,7 @@ UnaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
if (reference_count[this2] * cost(temporary_terms, false) > MIN_COST_C)
{
temporary_terms.insert(this2);
ModelBlock->Block_List[first_occurence[this2]].Temporary_terms->insert(this2);
ModelBlock->Block_List[first_occurence[this2].first].Temporary_Terms_in_Equation[first_occurence[this2].second]->insert(this2);
}
}
}
......@@ -1151,9 +1144,10 @@ BinaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
void
BinaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
Model_Block *ModelBlock,
int equation,
map_idx_type &map_idx) const
{
NodeID this2 = const_cast<BinaryOpNode *>(this);
......@@ -1161,17 +1155,19 @@ BinaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
if (it == reference_count.end())
{
reference_count[this2] = 1;
first_occurence[this2] = Curr_block;
arg1->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, map_idx);
arg2->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, map_idx);
first_occurence[this2] = make_pair(Curr_block, equation);
arg1->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, equation, map_idx);
arg2->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, equation, map_idx);
}
else
{
reference_count[this2]++;
if (reference_count[this2] * cost(temporary_terms, false) > MIN_COST_C)
{
if(this2->idx==2280)
cout << "==>Curr_block= " << Curr_block << " equation= " << equation << " first_occurence[this2].first=" << first_occurence[this2].first << " first_occurence[this2].second=" << first_occurence[this2].second << "\n";
temporary_terms.insert(this2);
ModelBlock->Block_List[first_occurence[this2]].Temporary_terms->insert(this2);
ModelBlock->Block_List[first_occurence[this2].first].Temporary_Terms_in_Equation[first_occurence[this2].second]->insert(this2);
}
}
}
......@@ -1563,9 +1559,10 @@ TrinaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
void
TrinaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
Model_Block *ModelBlock,
int equation,
map_idx_type &map_idx) const
{
NodeID this2 = const_cast<TrinaryOpNode *>(this);
......@@ -1573,18 +1570,20 @@ TrinaryOpNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
if (it == reference_count.end())
{
reference_count[this2] = 1;
first_occurence[this2] = Curr_block;
arg1->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, map_idx);
arg2->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, map_idx);
arg3->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, map_idx);
first_occurence[this2] = make_pair(Curr_block,equation);
arg1->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, equation, map_idx);
arg2->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, equation, map_idx);
arg3->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, Curr_block, ModelBlock, equation, map_idx);
}
else
{
reference_count[this2]++;
if (reference_count[this2] * cost(temporary_terms, false) > MIN_COST_C)
{
if(this2->idx==2280)
cout << "==>Curr_block= " << Curr_block << " equation= " << equation << " first_occurence[this2].first=" << first_occurence[this2].first << " first_occurence[this2].second=" << first_occurence[this2].second << "\n";
temporary_terms.insert(this2);
ModelBlock->Block_List[first_occurence[this2]].Temporary_terms->insert(this2);
ModelBlock->Block_List[first_occurence[this2].first].Temporary_Terms_in_Equation[first_occurence[this2].second]->insert(this2);
}
}
}
......@@ -1743,9 +1742,10 @@ void UnknownFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output
void
UnknownFunctionNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
Model_Block *ModelBlock,
int equation,
map_idx_type &map_idx) const
{
cerr << "UnknownFunctionNode::computeTemporaryTerms: not implemented" << endl;
......
This diff is collapsed.
......@@ -131,7 +131,6 @@ ModFile::evalAllExpressions()
{
if(global_eval_context.find(make_pair(j, eEndogenous))==global_eval_context.end())
{
//it2=mat_file.variable.find(symbol_table.getNameByID(eEndogenous, j));
map<string,vector<double> >::iterator it2=collect_struct.variable_double_name.find(symbol_table.getNameByID(eEndogenous, j));
if(it2!=collect_struct.variable_double_name.end())
{
......
......@@ -277,7 +277,8 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type)
void
ModelTree::computeTemporaryTermsOrdered(int order, Model_Block *ModelBlock)
{
map<NodeID, int> reference_count, first_occurence;
map<NodeID, pair<int, int> > first_occurence;
map<NodeID, int> reference_count;
int i, j, m, eq, var, lag;
temporary_terms_type vect;
ostringstream tmp_output;
......@@ -293,7 +294,7 @@ ModelTree::computeTemporaryTermsOrdered(int order, Model_Block *ModelBlock)
for (i = 0;i < ModelBlock->Block_List[j].Size;i++)
{
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
eq_node->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, j, ModelBlock, map_idx);
eq_node->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, j, ModelBlock, i, map_idx);
}
for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++)
{
......@@ -303,7 +304,7 @@ ModelTree::computeTemporaryTermsOrdered(int order, Model_Block *ModelBlock)
eq=ModelBlock->Block_List[j].IM_lead_lag[m].Equ_Index[i];
var=ModelBlock->Block_List[j].IM_lead_lag[m].Var_Index[i];
it=first_derivatives.find(make_pair(eq,variable_table.getID(eEndogenous, var,lag)));
it->second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, j, ModelBlock, map_idx);
it->second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, j, ModelBlock, ModelBlock->Block_List[j].Size-1, map_idx);
}
}
for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++)
......@@ -314,7 +315,7 @@ ModelTree::computeTemporaryTermsOrdered(int order, Model_Block *ModelBlock)
eq=ModelBlock->Block_List[j].IM_lead_lag[m].Equ_X_Index[i];
var=ModelBlock->Block_List[j].IM_lead_lag[m].Exogenous_Index[i];
it=first_derivatives.find(make_pair(eq,variable_table.getID(eExogenous, var,lag)));
it->second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, j, ModelBlock, map_idx);
it->second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, j, ModelBlock, ModelBlock->Block_List[j].Size-1, map_idx);
}
}
//jacobian_max_exo_col=(variable_table.max_exo_lag+variable_table.max_exo_lead+1)*symbol_table.exo_nbr;
......@@ -328,7 +329,7 @@ ModelTree::computeTemporaryTermsOrdered(int order, Model_Block *ModelBlock)
eq=ModelBlock->Block_List[j].IM_lead_lag[m].Equ_Index_other_endo[i];
var=ModelBlock->Block_List[j].IM_lead_lag[m].Var_Index_other_endo[i];
it=first_derivatives.find(make_pair(eq,variable_table.getID(eEndogenous, var,lag)));
it->second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, j, ModelBlock, map_idx);
it->second->computeTemporaryTerms(reference_count, temporary_terms, first_occurence, j, ModelBlock, ModelBlock->Block_List[j].Size-1, map_idx);
}
}
}
......@@ -470,7 +471,6 @@ ModelTree::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const string &
}
output << " g2=0;g3=0;\n";
temporary_terms_type tt2;
if(ModelBlock->Block_List[j].Temporary_InUse->size())
{
tmp_output.str("");
......@@ -502,24 +502,24 @@ ModelTree::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const string &
sps = " ";
else
sps="";
if (ModelBlock->Block_List[j].Temporary_terms->size())
output << " " << sps << "% //Temporary variables" << endl;
i=0;
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin();
it != ModelBlock->Block_List[j].Temporary_terms->end(); it++)
{
output << " " << sps;
(*it)->writeOutput(output, oMatlabDynamicModelSparse, temporary_terms);
output << " = ";
(*it)->writeOutput(output, oMatlabDynamicModelSparse, tt2);
// Insert current node into tt2
tt2.insert(*it);
output << ";" << endl;
i++;
}
// The equations
for (i = 0;i < ModelBlock->Block_List[j].Size;i++)
{
temporary_terms_type tt2;
tt2.clear();
if (ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->size())
output << " " << sps << "% //Temporary variables" << endl;
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++)
{
output << " " << sps;
(*it)->writeOutput(output, oMatlabDynamicModelSparse, temporary_terms);
output << " = ";
(*it)->writeOutput(output, oMatlabDynamicModelSparse, tt2);
// Insert current node into tt2
tt2.insert(*it);
output << ";" << endl;
}
string sModel = symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[i]) ;
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
lhs = eq_node->arg1;
......@@ -904,7 +904,6 @@ ModelTree::writeModelStaticEquationsOrdered_M(Model_Block *ModelBlock, const str
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
//The Temporary terms
//output << global_output.str();
temporary_terms_type tt2;
if(ModelBlock->Block_List[j].Temporary_InUse->size())
{
tmp_output.str("");
......@@ -946,24 +945,24 @@ ModelTree::writeModelStaticEquationsOrdered_M(Model_Block *ModelBlock, const str
output << " residual=zeros(" << ModelBlock->Block_List[j].Size << ",1);\n";
}
sps="";
if (ModelBlock->Block_List[j].Temporary_terms->size())
output << " " << sps << "% //Temporary variables" << endl;
i=0;
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin();
it != ModelBlock->Block_List[j].Temporary_terms->end(); it++)
{
output << " " << sps;
(*it)->writeOutput(output, oMatlabStaticModelSparse, temporary_terms);
output << " = ";
(*it)->writeOutput(output, oMatlabStaticModelSparse, tt2);
// Insert current node into tt2
tt2.insert(*it);
output << ";" << endl;
i++;
}
// The equations
for (i = 0;i < ModelBlock->Block_List[j].Size;i++)
{
temporary_terms_type tt2;
tt2.clear();
if (ModelBlock->Block_List[j].Temporary_Terms_in_Equation[i]->size())
output << " " << sps << "% //Temporary variables" << endl;
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++)
{
output << " " << sps;
(*it)->writeOutput(output, oMatlabStaticModelSparse, temporary_terms);
output << " = ";
(*it)->writeOutput(output, oMatlabStaticModelSparse, tt2);
// Insert current node into tt2
tt2.insert(*it);
output << ";" << endl;
}
string sModel = symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[i]) ;
output << sps << " % equation " << ModelBlock->Block_List[j].Equation[i]+1 << " variable : "
<< sModel << " (" << ModelBlock->Block_List[j].Variable[i]+1 << ")" << endl;
......@@ -1202,38 +1201,41 @@ ModelTree::writeModelEquationsCodeOrdered(const string file_name, const Model_Bl
}
else
lhs_rhs_done=false;
//The Temporary terms
temporary_terms_type tt2;
i=0;
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin();
it != ModelBlock->Block_List[j].Temporary_terms->end(); it++)
// The equations
for (i = 0;i < ModelBlock->Block_List[j].Size;i++)
{
(*it)->compile(code_file,false, output_type, tt2, map_idx);
code_file.write(&FSTPT, sizeof(FSTPT));
map_idx_type::const_iterator ii=map_idx.find((*it)->idx);
v=(int)ii->second;
code_file.write(reinterpret_cast<char *>(&v), sizeof(v));
// Insert current node into tt2
tt2.insert(*it);
//ModelBlock->Block_List[j].Variable_Sorted[i] = variable_table.getID(eEndogenous, ModelBlock->Block_List[j].Variable[i], 0);
//The Temporary terms
temporary_terms_type tt2;
#ifdef DEBUGC
cout << "FSTPT " << v << "\n";
code_file.write(&FOK, sizeof(FOK));
code_file.write(reinterpret_cast<char *>(&i), sizeof(i));
k=0;
#endif
i++;
}
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin();
it != ModelBlock->Block_List[j].Temporary_terms->end(); it++)
{
map_idx_type::const_iterator ii=map_idx.find((*it)->idx);
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)->compile(code_file,false, output_type, tt2, map_idx);
code_file.write(&FSTPT, sizeof(FSTPT));
map_idx_type::const_iterator ii=map_idx.find((*it)->idx);
v=(int)ii->second;
code_file.write(reinterpret_cast<char *>(&v), sizeof(v));
// Insert current node into tt2
tt2.insert(*it);
#ifdef DEBUGC
cout << "map_idx[" << (*it)->idx <<"]=" << ii->second << "\n";
cout << "FSTPT " << v << "\n";
code_file.write(&FOK, sizeof(FOK));
code_file.write(reinterpret_cast<char *>(&k), sizeof(k));
ki++;
#endif
}
#ifdef DEBUGC
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin();
it != ModelBlock->Block_List[j].Temporary_terms->end(); it++)
{
map_idx_type::const_iterator ii=map_idx.find((*it)->idx);
cout << "map_idx[" << (*it)->idx <<"]=" << ii->second << "\n";
}
#endif
}
// The equations
for (i = 0;i < ModelBlock->Block_List[j].Size;i++)
{
//ModelBlock->Block_List[j].Variable_Sorted[i] = variable_table.getID(eEndogenous, ModelBlock->Block_List[j].Variable[i], 0);
if (!lhs_rhs_done)
{
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
......
......@@ -148,9 +148,10 @@ public:
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,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
Model_Block *ModelBlock,
int equation,
map_idx_type &map_idx) const;
class EvalException
......@@ -204,6 +205,13 @@ public:
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms = temporary_terms_type()) const;
virtual void collectEndogenous(set<pair<int, int> > &result) const;
virtual void collectExogenous(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,
int Curr_block,
Model_Block *ModelBlock,
int equation,
map_idx_type &map_idx) 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(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
......@@ -225,9 +233,10 @@ public:
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
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;
......@@ -254,9 +263,10 @@ public:
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
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;
......@@ -290,9 +300,10 @@ public:
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
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;
......@@ -317,9 +328,10 @@ public:
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
map<NodeID, pair<int, int> > &first_occurence,
int Curr_block,
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;
......@@ -349,7 +361,8 @@ struct Block
bool is_linear;
int *Equation, *Own_Derivative;
int *Variable, *Other_Endogenous, *Exogenous;
temporary_terms_type *Temporary_terms;
temporary_terms_type **Temporary_Terms_in_Equation;
//temporary_terms_type *Temporary_terms;
temporary_terms_inuse_type *Temporary_InUse;
IM_compact *IM_lead_lag;
int Code_Start, Code_Length;
......
/*
* Copyright (C) 2006-2008 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Usefull documentation: Matlab 7 Mat-File Format
-----------------------------------------------
revision: October 2008 PDF only Rereleased for Version 7.7 (Release 2008b)
available at: http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf
*/
#ifndef _MAT_FILE_HH
#define _MAT_FILE_HH
#include <cstdio>
#include <cstdlib>
#include <string>
#include <fstream>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include <math.h>
//! zlib needed to uncompress the mat-file. It is available with GCC 4.3.2 but it needs a dll !!
//! => to avoid compress MatFile, save is used with option '-v6' in save_params_and_strady_state.m
//#include "zlib.h"
using namespace std;