trunk preprocessor:
* removed obsolete output type CDynamicSparseDLL * probably fixed a bug in BlockTriangular::Reduce_Blocks_and_type_determination git-svn-id: https://www.dynare.org/svn/dynare/trunk@2652 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
e9f59ebd51
commit
bacbd603fd
|
@ -558,7 +558,7 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp_output.str("");
|
tmp_output.str("");
|
||||||
rhs->writeOutput(tmp_output, oCDynamicModelSparseDLL, temporary_terms);
|
rhs->writeOutput(tmp_output, oMatlabDynamicModelSparse, temporary_terms);
|
||||||
if (tmp_output.str()==tmp_s.str())
|
if (tmp_output.str()==tmp_s.str())
|
||||||
{
|
{
|
||||||
if (Simulation_Type==SOLVE_BACKWARD_SIMPLE)
|
if (Simulation_Type==SOLVE_BACKWARD_SIMPLE)
|
||||||
|
|
|
@ -53,11 +53,11 @@ DynamicModel::AddVariable(const string &name, int lag)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::compileDerivative(ofstream &code_file, int eq, int symb_id, int lag, ExprNodeOutputType output_type, map_idx_type &map_idx) const
|
DynamicModel::compileDerivative(ofstream &code_file, int eq, int symb_id, int lag, map_idx_type &map_idx) const
|
||||||
{
|
{
|
||||||
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)));
|
||||||
if (it != first_derivatives.end())
|
if (it != first_derivatives.end())
|
||||||
(it->second)->compile(code_file,false, output_type, temporary_terms, map_idx);
|
(it->second)->compile(code_file, false, temporary_terms, map_idx);
|
||||||
else
|
else
|
||||||
code_file.write(&FLDZ, sizeof(FLDZ));
|
code_file.write(&FLDZ, sizeof(FLDZ));
|
||||||
}
|
}
|
||||||
|
@ -684,7 +684,7 @@ DynamicModel::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const strin
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::writeModelEquationsCodeOrdered(const string file_name, const Model_Block *ModelBlock, const string bin_basename, ExprNodeOutputType output_type, map_idx_type map_idx) const
|
DynamicModel::writeModelEquationsCodeOrdered(const string file_name, const Model_Block *ModelBlock, const string bin_basename, map_idx_type map_idx) const
|
||||||
{
|
{
|
||||||
struct Uff_l
|
struct Uff_l
|
||||||
{
|
{
|
||||||
|
@ -817,7 +817,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, output_type, tt2, map_idx);
|
(*it)->compile(code_file, false, tt2, map_idx);
|
||||||
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;
|
||||||
|
@ -850,13 +850,13 @@ DynamicModel::writeModelEquationsCodeOrdered(const string file_name, const Model
|
||||||
{
|
{
|
||||||
case EVALUATE_BACKWARD:
|
case EVALUATE_BACKWARD:
|
||||||
case EVALUATE_FORWARD:
|
case EVALUATE_FORWARD:
|
||||||
rhs->compile(code_file,false, output_type, temporary_terms, map_idx);
|
rhs->compile(code_file, false, temporary_terms, map_idx);
|
||||||
lhs->compile(code_file,true, output_type, temporary_terms, map_idx);
|
lhs->compile(code_file, true, temporary_terms, map_idx);
|
||||||
break;
|
break;
|
||||||
case EVALUATE_BACKWARD_R:
|
case EVALUATE_BACKWARD_R:
|
||||||
case EVALUATE_FORWARD_R:
|
case EVALUATE_FORWARD_R:
|
||||||
lhs->compile(code_file,false, output_type, temporary_terms, map_idx);
|
lhs->compile(code_file, false, temporary_terms, map_idx);
|
||||||
rhs->compile(code_file,true, output_type, temporary_terms, map_idx);
|
rhs->compile(code_file, true, temporary_terms, map_idx);
|
||||||
break;
|
break;
|
||||||
case SOLVE_BACKWARD_COMPLETE:
|
case SOLVE_BACKWARD_COMPLETE:
|
||||||
case SOLVE_FORWARD_COMPLETE:
|
case SOLVE_FORWARD_COMPLETE:
|
||||||
|
@ -872,8 +872,8 @@ DynamicModel::writeModelEquationsCodeOrdered(const string file_name, const Model
|
||||||
goto end;
|
goto end;
|
||||||
default:
|
default:
|
||||||
end:
|
end:
|
||||||
lhs->compile(code_file,false, output_type, temporary_terms, map_idx);
|
lhs->compile(code_file, false, temporary_terms, map_idx);
|
||||||
rhs->compile(code_file,false, output_type, temporary_terms, map_idx);
|
rhs->compile(code_file, false, temporary_terms, map_idx);
|
||||||
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));
|
||||||
|
@ -896,7 +896,7 @@ DynamicModel::writeModelEquationsCodeOrdered(const string file_name, const Model
|
||||||
{
|
{
|
||||||
case SOLVE_BACKWARD_SIMPLE:
|
case SOLVE_BACKWARD_SIMPLE:
|
||||||
case SOLVE_FORWARD_SIMPLE:
|
case SOLVE_FORWARD_SIMPLE:
|
||||||
compileDerivative(code_file, ModelBlock->Block_List[j].Equation[0], ModelBlock->Block_List[j].Variable[0], 0, output_type, map_idx);
|
compileDerivative(code_file, ModelBlock->Block_List[j].Equation[0], ModelBlock->Block_List[j].Variable[0], 0, map_idx);
|
||||||
code_file.write(&FSTPG, sizeof(FSTPG));
|
code_file.write(&FSTPG, sizeof(FSTPG));
|
||||||
v=0;
|
v=0;
|
||||||
code_file.write(reinterpret_cast<char *>(&v), sizeof(v));
|
code_file.write(reinterpret_cast<char *>(&v), sizeof(v));
|
||||||
|
@ -924,7 +924,7 @@ DynamicModel::writeModelEquationsCodeOrdered(const string file_name, const Model
|
||||||
Uf[v].Ufl->pNext=NULL;
|
Uf[v].Ufl->pNext=NULL;
|
||||||
Uf[v].Ufl->u=u;
|
Uf[v].Ufl->u=u;
|
||||||
Uf[v].Ufl->var=var;
|
Uf[v].Ufl->var=var;
|
||||||
compileDerivative(code_file, eq, var, 0, output_type, map_idx);
|
compileDerivative(code_file, eq, var, 0, map_idx);
|
||||||
code_file.write(&FSTPU, sizeof(FSTPU));
|
code_file.write(&FSTPU, sizeof(FSTPU));
|
||||||
code_file.write(reinterpret_cast<char *>(&u), sizeof(u));
|
code_file.write(reinterpret_cast<char *>(&u), sizeof(u));
|
||||||
}
|
}
|
||||||
|
@ -989,7 +989,7 @@ DynamicModel::writeModelEquationsCodeOrdered(const string file_name, const Model
|
||||||
Uf[v].Ufl->u=u;
|
Uf[v].Ufl->u=u;
|
||||||
Uf[v].Ufl->var=var;
|
Uf[v].Ufl->var=var;
|
||||||
Uf[v].Ufl->lag=k;
|
Uf[v].Ufl->lag=k;
|
||||||
compileDerivative(code_file, eq, var, k, output_type, map_idx);
|
compileDerivative(code_file, eq, var, k, map_idx);
|
||||||
code_file.write(&FSTPU, sizeof(FSTPU));
|
code_file.write(&FSTPU, sizeof(FSTPU));
|
||||||
code_file.write(reinterpret_cast<char *>(&u), sizeof(u));
|
code_file.write(reinterpret_cast<char *>(&u), sizeof(u));
|
||||||
#ifdef CONDITION
|
#ifdef CONDITION
|
||||||
|
@ -2243,7 +2243,7 @@ DynamicModel::writeDynamicFile(const string &basename) const
|
||||||
#else
|
#else
|
||||||
mkdir(basename.c_str(), 0777);
|
mkdir(basename.c_str(), 0777);
|
||||||
#endif
|
#endif
|
||||||
writeModelEquationsCodeOrdered(basename + "_dynamic", block_triangular.ModelBlock, basename, oCDynamicModelSparseDLL, map_idx);
|
writeModelEquationsCodeOrdered(basename + "_dynamic", block_triangular.ModelBlock, basename, map_idx);
|
||||||
block_triangular.Free_Block(block_triangular.ModelBlock);
|
block_triangular.Free_Block(block_triangular.ModelBlock);
|
||||||
block_triangular.incidencematrix.Free_IM();
|
block_triangular.incidencematrix.Free_IM();
|
||||||
//block_triangular.Free_IM_X(block_triangular.First_IM_X);
|
//block_triangular.Free_IM_X(block_triangular.First_IM_X);
|
||||||
|
|
|
@ -79,7 +79,7 @@ private:
|
||||||
//! Writes the Block reordred structure of the model in M output
|
//! Writes the Block reordred structure of the model in M output
|
||||||
void writeModelEquationsOrdered_M(Model_Block *ModelBlock, const string &dynamic_basename) const;
|
void writeModelEquationsOrdered_M(Model_Block *ModelBlock, const string &dynamic_basename) const;
|
||||||
//! Writes the code of the Block reordred structure of the model in virtual machine bytecode
|
//! Writes the code of the Block reordred structure of the model in virtual machine bytecode
|
||||||
void writeModelEquationsCodeOrdered(const string file_name, const Model_Block *ModelBlock, const string bin_basename, ExprNodeOutputType output_type, map_idx_type map_idx) const;
|
void writeModelEquationsCodeOrdered(const string file_name, const Model_Block *ModelBlock, const string bin_basename, map_idx_type map_idx) const;
|
||||||
//! Computes jacobian and prepares for equation normalization
|
//! Computes jacobian and prepares for equation normalization
|
||||||
/*! Using values from initval/endval blocks and parameter initializations:
|
/*! Using values from initval/endval blocks and parameter initializations:
|
||||||
- computes the jacobian for the model w.r. to contemporaneous variables
|
- computes the jacobian for the model w.r. to contemporaneous variables
|
||||||
|
@ -94,7 +94,7 @@ private:
|
||||||
|
|
||||||
void computeTemporaryTermsOrdered(Model_Block *ModelBlock);
|
void computeTemporaryTermsOrdered(Model_Block *ModelBlock);
|
||||||
//! Write derivative code of an equation w.r. to a variable
|
//! Write derivative code of an equation w.r. to a variable
|
||||||
void compileDerivative(ofstream &code_file, int eq, int symb_id, int lag, ExprNodeOutputType output_type, map_idx_type &map_idx) const;
|
void compileDerivative(ofstream &code_file, int eq, int symb_id, int lag, map_idx_type &map_idx) const;
|
||||||
|
|
||||||
virtual int computeDerivID(int symb_id, int lag);
|
virtual int computeDerivID(int symb_id, int lag);
|
||||||
//! Get the type corresponding to a derivation ID
|
//! Get the type corresponding to a derivation ID
|
||||||
|
|
|
@ -131,9 +131,7 @@ NumConstNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
{
|
{
|
||||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<NumConstNode *>(this));
|
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<NumConstNode *>(this));
|
||||||
if (it != temporary_terms.end())
|
if (it != temporary_terms.end())
|
||||||
if (output_type == oCDynamicModelSparseDLL)
|
if (output_type == oMatlabDynamicModelSparse)
|
||||||
output << "T" << idx << "[it_]";
|
|
||||||
else if (output_type == oMatlabDynamicModelSparse)
|
|
||||||
output << "T" << idx << "(it_)";
|
output << "T" << idx << "(it_)";
|
||||||
else
|
else
|
||||||
output << "T" << idx;
|
output << "T" << idx;
|
||||||
|
@ -148,11 +146,10 @@ NumConstNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NumConstNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
NumConstNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||||
{
|
{
|
||||||
CompileCode.write(&FLDC, sizeof(FLDC));
|
CompileCode.write(&FLDC, sizeof(FLDC));
|
||||||
double vard=atof(datatree.num_constants.get(id).c_str());
|
double vard = datatree.num_constants.getDouble(id);
|
||||||
//double vard=id;
|
|
||||||
#ifdef DEBUGC
|
#ifdef DEBUGC
|
||||||
cout << "FLDC " << vard << "\n";
|
cout << "FLDC " << vard << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
@ -259,9 +256,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<VariableNode *>(this));
|
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<VariableNode *>(this));
|
||||||
if (it != temporary_terms.end())
|
if (it != temporary_terms.end())
|
||||||
{
|
{
|
||||||
if (output_type == oCDynamicModelSparseDLL)
|
if (output_type == oMatlabDynamicModelSparse)
|
||||||
output << "T" << idx << "[it_]";
|
|
||||||
else if (output_type == oMatlabDynamicModelSparse)
|
|
||||||
output << "T" << idx << "(it_)";
|
output << "T" << idx << "(it_)";
|
||||||
else
|
else
|
||||||
output << "T" << idx;
|
output << "T" << idx;
|
||||||
|
@ -305,14 +300,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
i = tsid + OFFSET(output_type);
|
i = tsid + OFFSET(output_type);
|
||||||
output << "y" << LPAR(output_type) << i << RPAR(output_type);
|
output << "y" << LPAR(output_type) << i << RPAR(output_type);
|
||||||
break;
|
break;
|
||||||
case oCDynamicModelSparseDLL:
|
|
||||||
if (lag > 0)
|
|
||||||
output << "y" << LPAR(output_type) << "(it_+" << lag << ")*y_size+" << tsid << RPAR(output_type);
|
|
||||||
else if (lag < 0)
|
|
||||||
output << "y" << LPAR(output_type) << "(it_" << lag << ")*y_size+" << tsid << RPAR(output_type);
|
|
||||||
else
|
|
||||||
output << "y" << LPAR(output_type) << "Per_y_+" << tsid << RPAR(output_type);
|
|
||||||
break;
|
|
||||||
case oMatlabDynamicModelSparse:
|
case oMatlabDynamicModelSparse:
|
||||||
i = tsid + OFFSET(output_type);
|
i = tsid + OFFSET(output_type);
|
||||||
if (lag > 0)
|
if (lag > 0)
|
||||||
|
@ -342,7 +329,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
output << "x(it_, " << i << ")";
|
output << "x(it_, " << i << ")";
|
||||||
break;
|
break;
|
||||||
case oCDynamicModel:
|
case oCDynamicModel:
|
||||||
case oCDynamicModelSparseDLL:
|
|
||||||
if (lag == 0)
|
if (lag == 0)
|
||||||
output << "x[it_+" << i << "*nb_row_x]";
|
output << "x[it_+" << i << "*nb_row_x]";
|
||||||
else if (lag > 0)
|
else if (lag > 0)
|
||||||
|
@ -376,7 +362,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
output << "x(it_, " << i << ")";
|
output << "x(it_, " << i << ")";
|
||||||
break;
|
break;
|
||||||
case oCDynamicModel:
|
case oCDynamicModel:
|
||||||
case oCDynamicModelSparseDLL:
|
|
||||||
if (lag == 0)
|
if (lag == 0)
|
||||||
output << "x[it_+" << i << "*nb_row_xd]";
|
output << "x[it_+" << i << "*nb_row_xd]";
|
||||||
else if (lag > 0)
|
else if (lag > 0)
|
||||||
|
@ -413,7 +398,7 @@ VariableNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||||
{
|
{
|
||||||
int i, lagl;
|
int i, lagl;
|
||||||
#ifdef DEBUGC
|
#ifdef DEBUGC
|
||||||
|
@ -429,33 +414,33 @@ VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType ou
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case eParameter:
|
case eParameter:
|
||||||
i = tsid + OFFSET(output_type);
|
i = tsid;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||||
#ifdef DEBUGC
|
#ifdef DEBUGC
|
||||||
cout << "FLD Param[ " << i << ", symb_id=" << symb_id << "]\n";
|
cout << "FLD Param[ " << i << ", symb_id=" << symb_id << "]\n";
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case eEndogenous :
|
case eEndogenous :
|
||||||
i = symb_id + OFFSET(output_type);
|
i = symb_id;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||||
lagl=lag;
|
lagl=lag;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||||
break;
|
break;
|
||||||
case eExogenous :
|
case eExogenous :
|
||||||
i = tsid + OFFSET(output_type);
|
i = tsid;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||||
lagl=lag;
|
lagl=lag;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||||
break;
|
break;
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
i = tsid + datatree.symbol_table.exo_nbr() + OFFSET(output_type);
|
i = tsid + datatree.symbol_table.exo_nbr();
|
||||||
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
|
||||||
lagl=lag;
|
lagl=lag;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
|
||||||
break;
|
break;
|
||||||
case eModelLocalVariable:
|
case eModelLocalVariable:
|
||||||
case eModFileLocalVariable:
|
case eModFileLocalVariable:
|
||||||
datatree.local_variables_table[symb_id]->compile(CompileCode, lhs_rhs, output_type, temporary_terms, map_idx);
|
datatree.local_variables_table[symb_id]->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||||
break;
|
break;
|
||||||
case eUnknownFunction:
|
case eUnknownFunction:
|
||||||
cerr << "Impossible case: eUnknownFuncion" << endl;
|
cerr << "Impossible case: eUnknownFuncion" << endl;
|
||||||
|
@ -735,9 +720,7 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
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())
|
||||||
{
|
{
|
||||||
if (output_type == oCDynamicModelSparseDLL)
|
if (output_type == oMatlabDynamicModelSparse)
|
||||||
output << "T" << idx << "[it_]";
|
|
||||||
else if (output_type == oMatlabDynamicModelSparse)
|
|
||||||
output << "T" << idx << "(it_)";
|
output << "T" << idx << "(it_)";
|
||||||
else
|
else
|
||||||
output << "T" << idx;
|
output << "T" << idx;
|
||||||
|
@ -881,7 +864,7 @@ UnaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcept
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UnaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
UnaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) 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())
|
||||||
|
@ -891,7 +874,7 @@ UnaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType out
|
||||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arg->compile(CompileCode, lhs_rhs, output_type, temporary_terms, map_idx);
|
arg->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||||
CompileCode.write(&FUNARY, sizeof(FUNARY));
|
CompileCode.write(&FUNARY, sizeof(FUNARY));
|
||||||
UnaryOpcode op_codel=op_code;
|
UnaryOpcode op_codel=op_code;
|
||||||
CompileCode.write(reinterpret_cast<char *>(&op_codel), sizeof(op_codel));
|
CompileCode.write(reinterpret_cast<char *>(&op_codel), sizeof(op_codel));
|
||||||
|
@ -1258,7 +1241,7 @@ BinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BinaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
BinaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) 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));
|
||||||
|
@ -1269,8 +1252,8 @@ BinaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType ou
|
||||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arg1->compile(CompileCode, lhs_rhs, output_type, temporary_terms, map_idx);
|
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||||
arg2->compile(CompileCode, lhs_rhs, output_type, temporary_terms, map_idx);
|
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||||
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));
|
||||||
|
@ -1298,9 +1281,7 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
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));
|
||||||
if (it != temporary_terms.end())
|
if (it != temporary_terms.end())
|
||||||
{
|
{
|
||||||
if (output_type == oCDynamicModelSparseDLL)
|
if (output_type == oMatlabDynamicModelSparse)
|
||||||
output << "T" << idx << "[it_]";
|
|
||||||
else if (output_type == oMatlabDynamicModelSparse)
|
|
||||||
output << "T" << idx << "(it_)";
|
output << "T" << idx << "(it_)";
|
||||||
else
|
else
|
||||||
output << "T" << idx;
|
output << "T" << idx;
|
||||||
|
@ -1678,8 +1659,7 @@ TrinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExce
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TrinaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type,
|
TrinaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||||
const temporary_terms_type &temporary_terms, map_idx_type &map_idx) 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));
|
||||||
|
@ -1690,9 +1670,9 @@ TrinaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType o
|
||||||
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arg1->compile(CompileCode, lhs_rhs, output_type, temporary_terms, map_idx);
|
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||||
arg2->compile(CompileCode, lhs_rhs, output_type, temporary_terms, map_idx);
|
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||||
arg3->compile(CompileCode, lhs_rhs, output_type, temporary_terms, map_idx);
|
arg3->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
|
||||||
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));
|
||||||
|
@ -1724,10 +1704,7 @@ TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
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));
|
||||||
if (it != temporary_terms.end())
|
if (it != temporary_terms.end())
|
||||||
{
|
{
|
||||||
if (output_type != oCDynamicModelSparseDLL)
|
output << "T" << idx;
|
||||||
output << "T" << idx;
|
|
||||||
else
|
|
||||||
output << "T" << idx << "[it_]";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1866,7 +1843,7 @@ UnknownFunctionNode::eval(const eval_context_type &eval_context) const throw (Ev
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UnknownFunctionNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
UnknownFunctionNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
|
||||||
{
|
{
|
||||||
cerr << "UnknownFunctionNode::compile: operation impossible!" << endl;
|
cerr << "UnknownFunctionNode::compile: operation impossible!" << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
|
@ -52,10 +52,9 @@ enum ExprNodeOutputType
|
||||||
oMatlabStaticModel, //!< Matlab code, static model declarations
|
oMatlabStaticModel, //!< Matlab code, static model declarations
|
||||||
oMatlabDynamicModel, //!< Matlab code, dynamic model declarations
|
oMatlabDynamicModel, //!< Matlab code, dynamic model declarations
|
||||||
oMatlabStaticModelSparse, //!< Matlab code, static block decomposed mode declaration
|
oMatlabStaticModelSparse, //!< Matlab code, static block decomposed mode declaration
|
||||||
oMatlabDynamicModelSparse, //!< Matlab code, dynamic block decomposed mode declaration
|
oMatlabDynamicModelSparse,//!< Matlab code, dynamic block decomposed mode declaration
|
||||||
oCStaticModel, //!< C code, static model declarations
|
oCStaticModel, //!< C code, static model declarations
|
||||||
oCDynamicModel, //!< C code, dynamic model declarations
|
oCDynamicModel, //!< C code, dynamic model declarations
|
||||||
oCDynamicModelSparseDLL, //!< C code, dynamic model declarations in SparseDLL module
|
|
||||||
oMatlabOutsideModel //!< Matlab code, outside model block (for example in initval)
|
oMatlabOutsideModel //!< Matlab code, outside model block (for example in initval)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ typedef map<int, double> eval_context_type;
|
||||||
// Computing cost above which a node can be declared a temporary term
|
// Computing cost above which a node can be declared a temporary term
|
||||||
#define MIN_COST_MATLAB (40*90)
|
#define MIN_COST_MATLAB (40*90)
|
||||||
#define MIN_COST_C (40*4)
|
#define MIN_COST_C (40*4)
|
||||||
#define MIN_COST(is_matlab) (is_matlab ? MIN_COST_MATLAB : MIN_COST_C)
|
#define MIN_COST(is_matlab) ((is_matlab) ? MIN_COST_MATLAB : MIN_COST_C)
|
||||||
|
|
||||||
//! Base class for expression nodes
|
//! Base class for expression nodes
|
||||||
class ExprNode
|
class ExprNode
|
||||||
|
@ -167,7 +166,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(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const = 0;
|
virtual void compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) 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,
|
||||||
|
@ -200,7 +199,7 @@ public:
|
||||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
virtual void collectExogenous(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(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, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -229,7 +228,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(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, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) 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; };
|
||||||
};
|
};
|
||||||
|
@ -259,7 +258,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(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, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||||
//! Returns operand
|
//! Returns operand
|
||||||
NodeID get_arg() const { return(arg); };
|
NodeID get_arg() const { return(arg); };
|
||||||
//! Returns op code
|
//! Returns op code
|
||||||
|
@ -293,7 +292,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(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, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||||
//! Returns first operand
|
//! Returns first operand
|
||||||
NodeID get_arg1() const { return(arg1); };
|
NodeID get_arg1() const { return(arg1); };
|
||||||
//! Returns second operand
|
//! Returns second operand
|
||||||
|
@ -330,7 +329,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(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, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -357,7 +356,7 @@ public:
|
||||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
virtual void collectExogenous(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(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, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
|
||||||
virtual NodeID toStatic(DataTree &static_datatree) const;
|
virtual NodeID toStatic(DataTree &static_datatree) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue