Revert "preprocessor: julia: print only those temporary vars needed for the computation of (residuals, g1, g2, g3) in the respective dynamic! and static! functions"
This reverts commit eb2890d1f58f2285306821c85fa631b865fb80b6.issue#70
parent
7f014b94df
commit
7c28c672a4
|
@ -2112,27 +2112,26 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
|
||||||
void
|
void
|
||||||
DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia) const
|
DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia) const
|
||||||
{
|
{
|
||||||
ostringstream model_local_vars_output; // Used for storing model local vars
|
ostringstream model_output; // Used for storing model
|
||||||
ostringstream model_output; // Used for storing model temp vars and equations
|
ostringstream model_eq_output; // Used for storing model equations
|
||||||
ostringstream jacobian_output; // Used for storing jacobian equations
|
ostringstream jacobian_output; // Used for storing jacobian equations
|
||||||
ostringstream hessian_output; // Used for storing Hessian equations
|
ostringstream hessian_output; // Used for storing Hessian equations
|
||||||
ostringstream third_derivatives_output;
|
ostringstream third_derivatives_output;
|
||||||
|
|
||||||
ExprNodeOutputType output_type = (use_dll ? oCDynamicModel :
|
ExprNodeOutputType output_type = (use_dll ? oCDynamicModel :
|
||||||
julia ? oJuliaDynamicModel : oMatlabDynamicModel);
|
julia ? oJuliaDynamicModel : oMatlabDynamicModel);
|
||||||
|
|
||||||
deriv_node_temp_terms_t tef_terms;
|
deriv_node_temp_terms_t tef_terms;
|
||||||
writeModelLocalVariables(model_local_vars_output, output_type, tef_terms);
|
writeModelLocalVariables(model_output, output_type, tef_terms);
|
||||||
|
|
||||||
writeTemporaryTerms(temporary_terms_res, model_output, output_type, tef_terms);
|
writeTemporaryTerms(temporary_terms, model_output, output_type, tef_terms);
|
||||||
|
|
||||||
writeModelEquations(model_output, output_type);
|
writeModelEquations(model_eq_output, output_type);
|
||||||
|
|
||||||
int nrows = equations.size();
|
int nrows = equations.size();
|
||||||
int hessianColsNbr = dynJacobianColsNbr * dynJacobianColsNbr;
|
int hessianColsNbr = dynJacobianColsNbr * dynJacobianColsNbr;
|
||||||
|
|
||||||
// Writing Jacobian
|
// Writing Jacobian
|
||||||
writeTemporaryTerms(temporary_terms_g1, jacobian_output, output_type, tef_terms);
|
|
||||||
for (first_derivatives_t::const_iterator it = first_derivatives.begin();
|
for (first_derivatives_t::const_iterator it = first_derivatives.begin();
|
||||||
it != first_derivatives.end(); it++)
|
it != first_derivatives.end(); it++)
|
||||||
{
|
{
|
||||||
|
@ -2142,13 +2141,11 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
|
|
||||||
jacobianHelper(jacobian_output, eq, getDynJacobianCol(var), output_type);
|
jacobianHelper(jacobian_output, eq, getDynJacobianCol(var), output_type);
|
||||||
jacobian_output << "=";
|
jacobian_output << "=";
|
||||||
d1->writeOutput(jacobian_output, output_type, temporary_terms_g1, tef_terms);
|
d1->writeOutput(jacobian_output, output_type, temporary_terms, tef_terms);
|
||||||
jacobian_output << ";" << endl;
|
jacobian_output << ";" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writing Hessian
|
// Writing Hessian
|
||||||
if (second_derivatives.size() > 0)
|
|
||||||
writeTemporaryTerms(temporary_terms_g2, hessian_output, output_type, tef_terms);
|
|
||||||
int k = 0; // Keep the line of a 2nd derivative in v2
|
int k = 0; // Keep the line of a 2nd derivative in v2
|
||||||
for (second_derivatives_t::const_iterator it = second_derivatives.begin();
|
for (second_derivatives_t::const_iterator it = second_derivatives.begin();
|
||||||
it != second_derivatives.end(); it++)
|
it != second_derivatives.end(); it++)
|
||||||
|
@ -2169,7 +2166,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
{
|
{
|
||||||
for_sym << "g2[" << eq + 1 << "," << col_nb + 1 << "]";
|
for_sym << "g2[" << eq + 1 << "," << col_nb + 1 << "]";
|
||||||
hessian_output << " @inbounds " << for_sym.str() << " = ";
|
hessian_output << " @inbounds " << for_sym.str() << " = ";
|
||||||
d2->writeOutput(hessian_output, output_type, temporary_terms_g2, tef_terms);
|
d2->writeOutput(hessian_output, output_type, temporary_terms, tef_terms);
|
||||||
hessian_output << endl;
|
hessian_output << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2211,8 +2208,6 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writing third derivatives
|
// Writing third derivatives
|
||||||
if (third_derivatives.size() > 0)
|
|
||||||
writeTemporaryTerms(temporary_terms_g3, third_derivatives_output, output_type, tef_terms);
|
|
||||||
k = 0; // Keep the line of a 3rd derivative in v3
|
k = 0; // Keep the line of a 3rd derivative in v3
|
||||||
for (third_derivatives_t::const_iterator it = third_derivatives.begin();
|
for (third_derivatives_t::const_iterator it = third_derivatives.begin();
|
||||||
it != third_derivatives.end(); it++)
|
it != third_derivatives.end(); it++)
|
||||||
|
@ -2235,7 +2230,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
{
|
{
|
||||||
for_sym << "g3[" << eq + 1 << "," << ref_col + 1 << "]";
|
for_sym << "g3[" << eq + 1 << "," << ref_col + 1 << "]";
|
||||||
third_derivatives_output << " @inbounds " << for_sym.str() << " = ";
|
third_derivatives_output << " @inbounds " << for_sym.str() << " = ";
|
||||||
d3->writeOutput(third_derivatives_output, output_type, temporary_terms_g3, tef_terms);
|
d3->writeOutput(third_derivatives_output, output_type, temporary_terms, tef_terms);
|
||||||
third_derivatives_output << endl;
|
third_derivatives_output << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2292,8 +2287,8 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
<< "%" << endl
|
<< "%" << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< "residual = zeros(" << nrows << ", 1);" << endl
|
<< "residual = zeros(" << nrows << ", 1);" << endl
|
||||||
<< model_local_vars_output.str()
|
|
||||||
<< model_output.str()
|
<< model_output.str()
|
||||||
|
<< model_eq_output.str()
|
||||||
// Writing initialization instruction for matrix g1
|
// Writing initialization instruction for matrix g1
|
||||||
<< "if nargout >= 2," << endl
|
<< "if nargout >= 2," << endl
|
||||||
<< " g1 = zeros(" << nrows << ", " << dynJacobianColsNbr << ");" << endl
|
<< " g1 = zeros(" << nrows << ", " << dynJacobianColsNbr << ");" << endl
|
||||||
|
@ -2342,8 +2337,8 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
<< " double lhs, rhs;" << endl
|
<< " double lhs, rhs;" << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< " /* Residual equations */" << endl
|
<< " /* Residual equations */" << endl
|
||||||
<< model_local_vars_output.str()
|
|
||||||
<< model_output.str()
|
<< model_output.str()
|
||||||
|
<< model_eq_output.str()
|
||||||
<< " /* Jacobian */" << endl
|
<< " /* Jacobian */" << endl
|
||||||
<< " if (g1 == NULL)" << endl
|
<< " if (g1 == NULL)" << endl
|
||||||
<< " return;" << endl
|
<< " return;" << endl
|
||||||
|
@ -2401,8 +2396,8 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
<< " #" << endl
|
<< " #" << endl
|
||||||
<< " # Model equations" << endl
|
<< " # Model equations" << endl
|
||||||
<< " #" << endl
|
<< " #" << endl
|
||||||
<< model_local_vars_output.str()
|
|
||||||
<< model_output.str()
|
<< model_output.str()
|
||||||
|
<< model_eq_output.str()
|
||||||
<< "end" << endl << endl
|
<< "end" << endl << endl
|
||||||
<< "function dynamic!(y::Vector{Float64}, x::Matrix{Float64}, "
|
<< "function dynamic!(y::Vector{Float64}, x::Matrix{Float64}, "
|
||||||
<< "params::Vector{Float64}," << endl
|
<< "params::Vector{Float64}," << endl
|
||||||
|
@ -2418,7 +2413,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
<< " @assert size(g1) == (" << nrows << ", " << dynJacobianColsNbr << ")" << endl
|
<< " @assert size(g1) == (" << nrows << ", " << dynJacobianColsNbr << ")" << endl
|
||||||
<< " fill!(g1, 0.0)" << endl
|
<< " fill!(g1, 0.0)" << endl
|
||||||
<< " dynamic!(y, x, params, steady_state, it_, residual)" << endl
|
<< " dynamic!(y, x, params, steady_state, it_, residual)" << endl
|
||||||
<< model_local_vars_output.str()
|
<< model_output.str()
|
||||||
<< " #" << endl
|
<< " #" << endl
|
||||||
<< " # Jacobian matrix" << endl
|
<< " # Jacobian matrix" << endl
|
||||||
<< " #" << endl
|
<< " #" << endl
|
||||||
|
@ -2438,7 +2433,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
<< " @assert size(g2) == (" << nrows << ", " << hessianColsNbr << ")" << endl
|
<< " @assert size(g2) == (" << nrows << ", " << hessianColsNbr << ")" << endl
|
||||||
<< " dynamic!(y, x, params, steady_state, it_, residual, g1)" << endl;
|
<< " dynamic!(y, x, params, steady_state, it_, residual, g1)" << endl;
|
||||||
if (second_derivatives.size())
|
if (second_derivatives.size())
|
||||||
DynamicOutput << model_local_vars_output.str()
|
DynamicOutput << model_output.str()
|
||||||
<< " #" << endl
|
<< " #" << endl
|
||||||
<< " # Hessian matrix" << endl
|
<< " # Hessian matrix" << endl
|
||||||
<< " #" << endl
|
<< " #" << endl
|
||||||
|
@ -2461,7 +2456,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
|
||||||
<< " @assert size(g3) == (" << nrows << ", " << ncols << ")" << endl
|
<< " @assert size(g3) == (" << nrows << ", " << ncols << ")" << endl
|
||||||
<< " dynamic!(y, x, params, steady_state, it_, residual, g1, g2)" << endl;
|
<< " dynamic!(y, x, params, steady_state, it_, residual, g1, g2)" << endl;
|
||||||
if (third_derivatives.size())
|
if (third_derivatives.size())
|
||||||
DynamicOutput << model_local_vars_output.str()
|
DynamicOutput << model_output.str()
|
||||||
<< " #" << endl
|
<< " #" << endl
|
||||||
<< " # Third order derivatives" << endl
|
<< " # Third order derivatives" << endl
|
||||||
<< " #" << endl
|
<< " #" << endl
|
||||||
|
|
75
ExprNode.cc
75
ExprNode.cc
|
@ -128,14 +128,6 @@ ExprNode::computeTemporaryTerms(map<expr_t, int> &reference_count,
|
||||||
// Nothing to do for a terminal node
|
// Nothing to do for a terminal node
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ExprNode::computeSplitTemporaryTerms(map<expr_t, int> &reference_count,
|
|
||||||
temporary_terms_t &temporary_terms,
|
|
||||||
bool is_matlab) const
|
|
||||||
{
|
|
||||||
// Nothing to do for a terminal node
|
|
||||||
}
|
|
||||||
|
|
||||||
pair<int, expr_t >
|
pair<int, expr_t >
|
||||||
ExprNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const
|
ExprNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const
|
||||||
{
|
{
|
||||||
|
@ -1756,19 +1748,6 @@ UnaryOpNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, te
|
||||||
arg->collectTemporary_terms(temporary_terms, temporary_terms_inuse, Curr_Block);
|
arg->collectTemporary_terms(temporary_terms, temporary_terms_inuse, Curr_Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
UnaryOpNode::computeSplitTemporaryTerms(map<expr_t, int> &reference_count,
|
|
||||||
temporary_terms_t &temporary_terms,
|
|
||||||
bool is_matlab) const
|
|
||||||
{
|
|
||||||
expr_t this2 = const_cast<UnaryOpNode *>(this);
|
|
||||||
|
|
||||||
arg->computeSplitTemporaryTerms(reference_count, temporary_terms, is_matlab);
|
|
||||||
|
|
||||||
if (reference_count[this2] * cost(temporary_terms, is_matlab) > MIN_COST(is_matlab))
|
|
||||||
temporary_terms.insert(this2);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
UnaryOpNode::containsExternalFunction() const
|
UnaryOpNode::containsExternalFunction() const
|
||||||
{
|
{
|
||||||
|
@ -2836,21 +2815,6 @@ BinaryOpNode::computeTemporaryTerms(map<expr_t, int> &reference_count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
BinaryOpNode::computeSplitTemporaryTerms(map<expr_t, int> &reference_count,
|
|
||||||
temporary_terms_t &temporary_terms,
|
|
||||||
bool is_matlab) const
|
|
||||||
{
|
|
||||||
expr_t this2 = const_cast<BinaryOpNode *>(this);
|
|
||||||
|
|
||||||
arg1->computeSplitTemporaryTerms(reference_count, temporary_terms, is_matlab);
|
|
||||||
arg2->computeSplitTemporaryTerms(reference_count, temporary_terms, is_matlab);
|
|
||||||
|
|
||||||
if (reference_count[this2] * cost(temporary_terms, is_matlab) > MIN_COST(is_matlab)
|
|
||||||
&& op_code != oEqual)
|
|
||||||
temporary_terms.insert(this2);
|
|
||||||
}
|
|
||||||
|
|
||||||
double
|
double
|
||||||
BinaryOpNode::eval_opcode(double v1, BinaryOpcode op_code, double v2, int derivOrder) throw (EvalException, EvalExternalFunctionException)
|
BinaryOpNode::eval_opcode(double v1, BinaryOpcode op_code, double v2, int derivOrder) throw (EvalException, EvalExternalFunctionException)
|
||||||
{
|
{
|
||||||
|
@ -3983,21 +3947,6 @@ TrinaryOpNode::computeTemporaryTerms(map<expr_t, int> &reference_count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
TrinaryOpNode::computeSplitTemporaryTerms(map<expr_t, int> &reference_count,
|
|
||||||
temporary_terms_t &temporary_terms,
|
|
||||||
bool is_matlab) const
|
|
||||||
{
|
|
||||||
expr_t this2 = const_cast<TrinaryOpNode *>(this);
|
|
||||||
|
|
||||||
arg1->computeSplitTemporaryTerms(reference_count, temporary_terms, is_matlab);
|
|
||||||
arg2->computeSplitTemporaryTerms(reference_count, temporary_terms, is_matlab);
|
|
||||||
arg3->computeSplitTemporaryTerms(reference_count, temporary_terms, is_matlab);
|
|
||||||
|
|
||||||
if (reference_count[this2] * cost(temporary_terms, is_matlab) > MIN_COST(is_matlab))
|
|
||||||
temporary_terms.insert(this2);
|
|
||||||
}
|
|
||||||
|
|
||||||
double
|
double
|
||||||
TrinaryOpNode::eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException, EvalExternalFunctionException)
|
TrinaryOpNode::eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException, EvalExternalFunctionException)
|
||||||
{
|
{
|
||||||
|
@ -4789,14 +4738,6 @@ ExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &reference_count,
|
||||||
v_temporary_terms[Curr_block][equation].insert(this2);
|
v_temporary_terms[Curr_block][equation].insert(this2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ExternalFunctionNode::computeSplitTemporaryTerms(map<expr_t, int> &reference_count,
|
|
||||||
temporary_terms_t &temporary_terms,
|
|
||||||
bool is_matlab) const
|
|
||||||
{
|
|
||||||
temporary_terms.insert(const_cast<ExternalFunctionNode *>(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExternalFunctionNode::compile(ostream &CompileCode, unsigned int &instruction_number,
|
ExternalFunctionNode::compile(ostream &CompileCode, unsigned int &instruction_number,
|
||||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||||
|
@ -5052,14 +4993,6 @@ FirstDerivExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &referenc
|
||||||
v_temporary_terms[Curr_block][equation].insert(this2);
|
v_temporary_terms[Curr_block][equation].insert(this2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
FirstDerivExternalFunctionNode::computeSplitTemporaryTerms(map<expr_t, int> &reference_count,
|
|
||||||
temporary_terms_t &temporary_terms,
|
|
||||||
bool is_matlab) const
|
|
||||||
{
|
|
||||||
temporary_terms.insert(const_cast<FirstDerivExternalFunctionNode *>(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
FirstDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
|
FirstDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
|
||||||
{
|
{
|
||||||
|
@ -5368,14 +5301,6 @@ SecondDerivExternalFunctionNode::computeTemporaryTerms(map<expr_t, int> &referen
|
||||||
v_temporary_terms[Curr_block][equation].insert(this2);
|
v_temporary_terms[Curr_block][equation].insert(this2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SecondDerivExternalFunctionNode::computeSplitTemporaryTerms(map<expr_t, int> &reference_count,
|
|
||||||
temporary_terms_t &temporary_terms,
|
|
||||||
bool is_matlab) const
|
|
||||||
{
|
|
||||||
temporary_terms.insert(const_cast<SecondDerivExternalFunctionNode *>(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
SecondDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
|
SecondDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
|
||||||
|
|
||||||
|
|
11
ExprNode.hh
11
ExprNode.hh
|
@ -188,10 +188,6 @@ public:
|
||||||
/*! A node will be marked as a temporary term if it is referenced at least two times (i.e. has at least two parents), and has a computing cost (multiplied by reference count) greater to datatree.min_cost */
|
/*! A node will be marked as a temporary term if it is referenced at least two times (i.e. has at least two parents), and has a computing cost (multiplied by reference count) greater to datatree.min_cost */
|
||||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
||||||
|
|
||||||
//! Splits temporary terms into those used for each of residuals, jacobian, hessian, 3rd derivs
|
|
||||||
//! based on the reference counts computed by computeTemporaryTerms
|
|
||||||
virtual void computeSplitTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
|
||||||
|
|
||||||
//! Writes output of node, using a Txxx notation for nodes in temporary_terms, and specifiying the set of already written external functions
|
//! Writes output of node, using a Txxx notation for nodes in temporary_terms, and specifiying the set of already written external functions
|
||||||
/*!
|
/*!
|
||||||
\param[in] output the output stream
|
\param[in] output the output stream
|
||||||
|
@ -570,7 +566,6 @@ public:
|
||||||
UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const expr_t arg_arg, int expectation_information_set_arg, int param1_symb_id_arg, int param2_symb_id_arg);
|
UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const expr_t arg_arg, int expectation_information_set_arg, int param1_symb_id_arg, int param2_symb_id_arg);
|
||||||
virtual void prepareForDerivation();
|
virtual void prepareForDerivation();
|
||||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
||||||
virtual void computeSplitTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||||
virtual bool containsExternalFunction() const;
|
virtual bool containsExternalFunction() const;
|
||||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
|
@ -650,7 +645,6 @@ public:
|
||||||
virtual void prepareForDerivation();
|
virtual void prepareForDerivation();
|
||||||
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
||||||
virtual void computeSplitTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||||
virtual bool containsExternalFunction() const;
|
virtual bool containsExternalFunction() const;
|
||||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
|
@ -746,7 +740,6 @@ public:
|
||||||
virtual void prepareForDerivation();
|
virtual void prepareForDerivation();
|
||||||
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
||||||
virtual void computeSplitTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||||
virtual bool containsExternalFunction() const;
|
virtual bool containsExternalFunction() const;
|
||||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
|
@ -819,7 +812,6 @@ public:
|
||||||
const vector<expr_t> &arguments_arg);
|
const vector<expr_t> &arguments_arg);
|
||||||
virtual void prepareForDerivation();
|
virtual void prepareForDerivation();
|
||||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const = 0;
|
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const = 0;
|
||||||
virtual void computeSplitTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const = 0;
|
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||||
virtual bool containsExternalFunction() const;
|
virtual bool containsExternalFunction() const;
|
||||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
|
@ -880,7 +872,6 @@ public:
|
||||||
ExternalFunctionNode(DataTree &datatree_arg, int symb_id_arg,
|
ExternalFunctionNode(DataTree &datatree_arg, int symb_id_arg,
|
||||||
const vector<expr_t> &arguments_arg);
|
const vector<expr_t> &arguments_arg);
|
||||||
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
virtual void computeTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
||||||
virtual void computeSplitTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||||
const temporary_terms_t &temporary_terms,
|
const temporary_terms_t &temporary_terms,
|
||||||
|
@ -918,7 +909,6 @@ public:
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
vector< vector<temporary_terms_t> > &v_temporary_terms,
|
vector< vector<temporary_terms_t> > &v_temporary_terms,
|
||||||
int equation) const;
|
int equation) const;
|
||||||
virtual void computeSplitTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||||
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
||||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||||
|
@ -955,7 +945,6 @@ public:
|
||||||
int Curr_block,
|
int Curr_block,
|
||||||
vector< vector<temporary_terms_t> > &v_temporary_terms,
|
vector< vector<temporary_terms_t> > &v_temporary_terms,
|
||||||
int equation) const;
|
int equation) const;
|
||||||
virtual void computeSplitTemporaryTerms(map<expr_t, int> &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const;
|
|
||||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||||
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
||||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||||
|
|
34
ModelTree.cc
34
ModelTree.cc
|
@ -1110,27 +1110,6 @@ ModelTree::computeTemporaryTerms(bool is_matlab)
|
||||||
for (third_derivatives_t::iterator it = third_derivatives.begin();
|
for (third_derivatives_t::iterator it = third_derivatives.begin();
|
||||||
it != third_derivatives.end(); it++)
|
it != third_derivatives.end(); it++)
|
||||||
it->second->computeTemporaryTerms(reference_count, temporary_terms, is_matlab);
|
it->second->computeTemporaryTerms(reference_count, temporary_terms, is_matlab);
|
||||||
|
|
||||||
// Now split up temporary terms
|
|
||||||
temporary_terms_res.clear();
|
|
||||||
for (vector<BinaryOpNode *>::iterator it = equations.begin();
|
|
||||||
it != equations.end(); it++)
|
|
||||||
(*it)->computeSplitTemporaryTerms(reference_count, temporary_terms_res, is_matlab);
|
|
||||||
|
|
||||||
temporary_terms_g1 = temporary_terms_res;
|
|
||||||
for (first_derivatives_t::iterator it = first_derivatives.begin();
|
|
||||||
it != first_derivatives.end(); it++)
|
|
||||||
it->second->computeSplitTemporaryTerms(reference_count, temporary_terms_g1, is_matlab);
|
|
||||||
|
|
||||||
temporary_terms_g2 = temporary_terms_g1;
|
|
||||||
for (second_derivatives_t::iterator it = second_derivatives.begin();
|
|
||||||
it != second_derivatives.end(); it++)
|
|
||||||
it->second->computeSplitTemporaryTerms(reference_count, temporary_terms_g2, is_matlab);
|
|
||||||
|
|
||||||
temporary_terms_g3 = temporary_terms_g2;
|
|
||||||
for (third_derivatives_t::iterator it = third_derivatives.begin();
|
|
||||||
it != third_derivatives.end(); it++)
|
|
||||||
it->second->computeSplitTemporaryTerms(reference_count, temporary_terms_g3, is_matlab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1139,6 +1118,7 @@ ModelTree::writeTemporaryTerms(const temporary_terms_t &tt, ostream &output,
|
||||||
{
|
{
|
||||||
// Local var used to keep track of temp nodes already written
|
// Local var used to keep track of temp nodes already written
|
||||||
temporary_terms_t tt2;
|
temporary_terms_t tt2;
|
||||||
|
|
||||||
for (temporary_terms_t::const_iterator it = tt.begin();
|
for (temporary_terms_t::const_iterator it = tt.begin();
|
||||||
it != tt.end(); it++)
|
it != tt.end(); it++)
|
||||||
{
|
{
|
||||||
|
@ -1233,12 +1213,6 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t
|
||||||
void
|
void
|
||||||
ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type) const
|
ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type) const
|
||||||
{
|
{
|
||||||
temporary_terms_t temp_terms;
|
|
||||||
if (IS_JULIA(output_type))
|
|
||||||
temp_terms = temporary_terms_res;
|
|
||||||
else
|
|
||||||
temp_terms = temporary_terms;
|
|
||||||
|
|
||||||
for (int eq = 0; eq < (int) equations.size(); eq++)
|
for (int eq = 0; eq < (int) equations.size(); eq++)
|
||||||
{
|
{
|
||||||
BinaryOpNode *eq_node = equations[eq];
|
BinaryOpNode *eq_node = equations[eq];
|
||||||
|
@ -1260,13 +1234,13 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type)
|
||||||
if (IS_JULIA(output_type))
|
if (IS_JULIA(output_type))
|
||||||
output << " @inbounds ";
|
output << " @inbounds ";
|
||||||
output << "lhs =";
|
output << "lhs =";
|
||||||
lhs->writeOutput(output, output_type, temp_terms);
|
lhs->writeOutput(output, output_type, temporary_terms);
|
||||||
output << ";" << endl;
|
output << ";" << endl;
|
||||||
|
|
||||||
if (IS_JULIA(output_type))
|
if (IS_JULIA(output_type))
|
||||||
output << " @inbounds ";
|
output << " @inbounds ";
|
||||||
output << "rhs =";
|
output << "rhs =";
|
||||||
rhs->writeOutput(output, output_type, temp_terms);
|
rhs->writeOutput(output, output_type, temporary_terms);
|
||||||
output << ";" << endl;
|
output << ";" << endl;
|
||||||
|
|
||||||
if (IS_JULIA(output_type))
|
if (IS_JULIA(output_type))
|
||||||
|
@ -1284,7 +1258,7 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type)
|
||||||
<< eq + ARRAY_SUBSCRIPT_OFFSET(output_type)
|
<< eq + ARRAY_SUBSCRIPT_OFFSET(output_type)
|
||||||
<< RIGHT_ARRAY_SUBSCRIPT(output_type)
|
<< RIGHT_ARRAY_SUBSCRIPT(output_type)
|
||||||
<< " = ";
|
<< " = ";
|
||||||
lhs->writeOutput(output, output_type, temp_terms);
|
lhs->writeOutput(output, output_type, temporary_terms);
|
||||||
output << ";" << endl;
|
output << ";" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,10 +130,6 @@ protected:
|
||||||
|
|
||||||
//! Temporary terms for the static/dynamic file (those which will be noted Txxxx)
|
//! Temporary terms for the static/dynamic file (those which will be noted Txxxx)
|
||||||
temporary_terms_t temporary_terms;
|
temporary_terms_t temporary_terms;
|
||||||
temporary_terms_t temporary_terms_res;
|
|
||||||
temporary_terms_t temporary_terms_g1;
|
|
||||||
temporary_terms_t temporary_terms_g2;
|
|
||||||
temporary_terms_t temporary_terms_g3;
|
|
||||||
|
|
||||||
//! Temporary terms for the file containing parameters derivatives
|
//! Temporary terms for the file containing parameters derivatives
|
||||||
temporary_terms_t params_derivs_temporary_terms;
|
temporary_terms_t params_derivs_temporary_terms;
|
||||||
|
|
Loading…
Reference in New Issue