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

Fix ordering of model local variables

parent dd679918
......@@ -43,7 +43,8 @@ typedef class ExprNode *expr_t;
struct ExprNodeLess;
//! Type for set of temporary terms
/*! They are ordered by index number thanks to ExprNodeLess */
/*! The ExprNodeLess ordering is important for the temporary terms algorithm,
see the definition of ExprNodeLess */
typedef set<expr_t, ExprNodeLess> temporary_terms_t;
/*! Keeps track of array indices of temporary_terms for writing */
typedef map<expr_t, int> temporary_terms_idxs_t;
......@@ -540,6 +541,9 @@ class ExprNode
};
//! Object used to compare two nodes (using their indexes)
/*! Note that in this ordering, a subexpression is always less than the
expression from which it is extracted. This property is used extensively in
the temporary terms computations. */
struct ExprNodeLess
{
bool
......
......@@ -1180,7 +1180,7 @@ ModelTree::computeTemporaryTerms(bool is_matlab)
temporary_terms_g3 = temp_terms_map[eThirdDeriv];
int idx = 0;
for (map<expr_t, expr_t>::const_iterator it = temporary_terms_mlv.begin();
for (map<expr_t, expr_t, ExprNodeLess>::const_iterator it = temporary_terms_mlv.begin();
it != temporary_terms_mlv.end(); it++)
temporary_terms_idxs[it->first] = idx++;
......@@ -1202,7 +1202,7 @@ ModelTree::computeTemporaryTerms(bool is_matlab)
}
void
ModelTree::writeModelLocalVariableTemporaryTerms(const temporary_terms_t &tto, const map<expr_t, expr_t> &tt,
ModelTree::writeModelLocalVariableTemporaryTerms(const temporary_terms_t &tto, const map<expr_t, expr_t, ExprNodeLess> &tt,
ostream &output, ExprNodeOutputType output_type,
deriv_node_temp_terms_t &tef_terms) const
{
......
......@@ -136,7 +136,7 @@ protected:
//! Temporary terms for the static/dynamic file (those which will be noted T[x])
temporary_terms_t temporary_terms;
map<expr_t, expr_t> temporary_terms_mlv;
map<expr_t, expr_t, ExprNodeLess> temporary_terms_mlv;
temporary_terms_t temporary_terms_res;
temporary_terms_t temporary_terms_g1;
temporary_terms_t temporary_terms_g2;
......@@ -200,7 +200,7 @@ protected:
//! Writes model local variables
/*! No temporary term is used in the output, so that local parameters declarations can be safely put before temporary terms declaration in the output files */
void writeModelLocalVariables(ostream &output, ExprNodeOutputType output_type, deriv_node_temp_terms_t &tef_terms) const;
void writeModelLocalVariableTemporaryTerms(const temporary_terms_t &tto, const map<expr_t, expr_t> &tt,
void writeModelLocalVariableTemporaryTerms(const temporary_terms_t &tto, const map<expr_t, expr_t, ExprNodeLess> &tt,
ostream &output, ExprNodeOutputType output_type,
deriv_node_temp_terms_t &tef_terms) const;
//! Writes model equations
......
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