Commit 33b280b3 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Remove some ExprNode::writeOutput variants

More precisely, remove those variants where temporary_terms can be specified
without temporary_terms_idxs, in order to make clear that the latter is
expected. For situations where the tt_idxs are not needed (C, block MATLAB), an
empty map has to be explicitly given.
parent 3f874cfc
......@@ -3474,11 +3474,9 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
output << "];" << endl;
// Write PacExpectationInfo
deriv_node_temp_terms_t tef_terms;
temporary_terms_t temp_terms_empty;
for (set<const PacExpectationNode *>::const_iterator it = pac_expectation_info.begin();
it != pac_expectation_info.end(); it++)
(*it)->ExprNode::writeOutput(output, oMatlabDynamicModel, temp_terms_empty, tef_terms);
(*it)->ExprNode::writeOutput(output, oMatlabDynamicModel);
}
map<pair<int, pair<int, int > >, expr_t>
......@@ -5967,7 +5965,7 @@ DynamicModel::writeFirstDerivativesC(const string &basename, bool cuda) const
mDynamicModelFile << "=";
// oCStaticModel makes reference to the static variables
// oCDynamicModel makes reference to the dynamic variables
d1->writeOutput(mDynamicModelFile, oCDynamicModel, temporary_terms, tef_terms);
d1->writeOutput(mDynamicModelFile, oCDynamicModel, temporary_terms, {}, tef_terms);
mDynamicModelFile << ";" << endl;
}
......@@ -6062,7 +6060,7 @@ DynamicModel::writeFirstDerivativesC_csr(const string &basename, bool cuda) cons
<< "=" << it->col_nbr << ";" << endl;
mDynamicModelFile << "value[" << k << "] = ";
// oCstaticModel makes reference to the static variables
it->value->writeOutput(mDynamicModelFile, oCDynamic2Model, temporary_terms, tef_terms);
it->value->writeOutput(mDynamicModelFile, oCDynamic2Model, temporary_terms, {}, tef_terms);
mDynamicModelFile << ";" << endl;
k++;
}
......@@ -6161,7 +6159,7 @@ DynamicModel::writeSecondDerivativesC_csr(const string &basename, bool cuda) con
<< "=" << it->col_nbr << ";" << endl;
mDynamicModelFile << "value[" << k << "] = ";
// oCstaticModel makes reference to the static variables
it->value->writeOutput(mDynamicModelFile, oCStaticModel, temporary_terms, tef_terms);
it->value->writeOutput(mDynamicModelFile, oCStaticModel, temporary_terms, {}, tef_terms);
mDynamicModelFile << ";" << endl;
k++;
}
......@@ -6293,7 +6291,7 @@ DynamicModel::writeThirdDerivativesC_csr(const string &basename, bool cuda) cons
<< "=" << it->col_nbr << ";" << endl;
mDynamicModelFile << "value[" << k << "] = ";
// oCstaticModel makes reference to the static variables
it->value->writeOutput(mDynamicModelFile, oCStaticModel, temporary_terms, tef_terms);
it->value->writeOutput(mDynamicModelFile, oCStaticModel, temporary_terms, {}, tef_terms);
mDynamicModelFile << ";" << endl;
k++;
}
......
......@@ -185,29 +185,13 @@ ExprNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t>
void
ExprNode::writeOutput(ostream &output) const
{
writeOutput(output, oMatlabOutsideModel, temporary_terms_t());
writeOutput(output, oMatlabOutsideModel, {}, {});
}
void
ExprNode::writeOutput(ostream &output, ExprNodeOutputType output_type) const
{
writeOutput(output, output_type, temporary_terms_t());
}
void
ExprNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const
{
temporary_terms_idxs_t temporary_terms_idxs;
deriv_node_temp_terms_t tef_terms;
writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
}
void
ExprNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_t &temporary_terms,
deriv_node_temp_terms_t &tef_terms) const
{
writeOutput(output, output_type, temporary_terms, {}, tef_terms);
writeOutput(output, output_type, {}, {});
}
void
......@@ -6425,6 +6409,7 @@ AbstractExternalFunctionNode::writeJsonExternalFunctionArguments(ostream &output
void
AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_t &temporary_terms,
const temporary_terms_idxs_t &temporary_terms_idxs,
deriv_node_temp_terms_t &tef_terms, const string &ending) const
{
output << "mxArray *prhs"<< ending << "[nrhs"<< ending << "];" << endl;
......@@ -6433,7 +6418,7 @@ AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType outp
it != arguments.end(); it++)
{
output << "prhs" << ending << "[" << i++ << "] = mxCreateDoubleScalar("; // All external_function arguments are scalars
(*it)->writeOutput(output, output_type, temporary_terms, tef_terms);
(*it)->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
output << ");" << endl;
}
}
......@@ -6669,7 +6654,7 @@ ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutpu
output << "mxArray *plhs" << ending.str()<< "[nlhs"<< ending.str() << "];" << endl;
output << "int nrhs" << ending.str()<< " = " << arguments.size() << ";" << endl;
writePrhs(output, output_type, temporary_terms, tef_terms, ending.str());
writePrhs(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms, ending.str());
output << "mexCallMATLAB("
<< "nlhs" << ending.str() << ", "
......@@ -7004,7 +6989,7 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
<< "double *TEFD_def_" << indx << ";" << endl
<< "mxArray *plhs" << ending.str() << "[nlhs"<< ending.str() << "];" << endl
<< "int nrhs" << ending.str() << " = " << arguments.size() << ";" << endl;
writePrhs(output, output_type, temporary_terms, tef_terms, ending.str());
writePrhs(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms, ending.str());
output << "mexCallMATLAB("
<< "nlhs" << ending.str() << ", "
......@@ -7358,7 +7343,7 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
<< "double *TEFDD_def_" << indx << ";" << endl
<< "mxArray *plhs" << ending.str() << "[nlhs"<< ending.str() << "];" << endl
<< "int nrhs" << ending.str() << " = " << arguments.size() << ";" << endl;
writePrhs(output, output_type, temporary_terms, tef_terms, ending.str());
writePrhs(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms, ending.str());
output << "mexCallMATLAB("
<< "nlhs" << ending.str() << ", "
......
......@@ -226,6 +226,9 @@ class ExprNode
\param[in] output the output stream
\param[in] output_type the type of output (MATLAB, C, LaTeX...)
\param[in] temporary_terms the nodes that are marked as temporary terms
\param[in] a map from temporary_terms to integers indexes (in the
MATLAB or Julia vector of temporary terms); can be empty
when writing C or MATLAB with block decomposition)
\param[in,out] tef_terms the set of already written external function nodes
*/
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, const temporary_terms_idxs_t &temporary_terms_idxs, deriv_node_temp_terms_t &tef_terms) const = 0;
......@@ -240,9 +243,7 @@ class ExprNode
void writeOutput(ostream &output, ExprNodeOutputType output_type) const;
//! Writes output of node, using a Txxx notation for nodes in temporary_terms
void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, const temporary_terms_idxs_t &temporary_terms_idxs) const;
void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
//! Writes output of node in JSON syntax
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const bool isdynamic = true) const = 0;
......@@ -1145,7 +1146,7 @@ public:
virtual bool containsExogenous() const;
virtual bool isDiffPresent(void) const;
virtual bool isVariableNodeEqualTo(SymbolType type_arg, int variable_id, int lag_arg) const;
virtual void writePrhs(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms, const string &ending) const;
virtual void writePrhs(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, const temporary_terms_idxs_t &temporary_terms_idxs, deriv_node_temp_terms_t &tef_terms, const string &ending) const;
virtual expr_t replaceTrendVar() const;
virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const;
virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0;
......
......@@ -1027,7 +1027,7 @@ ModelTree::writeDerivative(ostream &output, int eq, int symb_id, int lag,
{
first_derivatives_t::const_iterator it = first_derivatives.find(make_pair(eq, getDerivID(symb_id, lag)));
if (it != first_derivatives.end())
(it->second)->writeOutput(output, output_type, temporary_terms);
(it->second)->writeOutput(output, output_type, temporary_terms, {});
else
output << 0;
}
......
......@@ -2435,15 +2435,12 @@ void
StaticModel::writeAuxVarRecursiveDefinitions(ostream &output, ExprNodeOutputType output_type) const
{
deriv_node_temp_terms_t tef_terms;
temporary_terms_t temporary_terms;
temporary_terms_idxs_t temporary_terms_idxs;
for (int i = 0; i < (int) aux_equations.size(); i++)
if (dynamic_cast<ExprNode *>(aux_equations[i])->containsExternalFunction())
dynamic_cast<ExprNode *>(aux_equations[i])->writeExternalFunctionOutput(output, oMatlabStaticModel,
temporary_terms, temporary_terms_idxs, tef_terms);
dynamic_cast<ExprNode *>(aux_equations[i])->writeExternalFunctionOutput(output, oMatlabStaticModel, {}, {}, tef_terms);
for (int i = 0; i < (int) aux_equations.size(); i++)
{
dynamic_cast<ExprNode *>(aux_equations[i]->substituteStaticAuxiliaryDefinition())->writeOutput(output, output_type, temporary_terms, tef_terms);
dynamic_cast<ExprNode *>(aux_equations[i]->substituteStaticAuxiliaryDefinition())->writeOutput(output, output_type);
output << ";" << endl;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment