Commit e7c9ec55 authored by sebastien's avatar sebastien
Browse files

trunk preprocessor: fixed bug with sparse Hessian and USE_DLL


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2793 ac1d8469-bf42-47a9-8791-bf33cf982152
parent bbd75622
......@@ -1940,7 +1940,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const
ostringstream g1;
g1 << " g1";
matrixHelper(g1, eq, getDynJacobianCol(var), output_type);
jacobianHelper(g1, eq, getDynJacobianCol(var), output_type);
jacobian_output << g1.str() << "=" << g1.str() << "+";
d1->writeOutput(jacobian_output, output_type, temporary_terms);
......@@ -1964,15 +1964,15 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const
int col_nb_sym = id2 * dynJacobianColsNbr + id1;
hessian_output << "v2";
matrixHelper(hessian_output, k, 0, output_type);
hessianHelper(hessian_output, k, 0, output_type);
hessian_output << "=" << eq + 1 << ";" << endl;
hessian_output << "v2";
matrixHelper(hessian_output, k, 1, output_type);
hessianHelper(hessian_output, k, 1, output_type);
hessian_output << "=" << col_nb + 1 << ";" << endl;
hessian_output << "v2";
matrixHelper(hessian_output, k, 2, output_type);
hessianHelper(hessian_output, k, 2, output_type);
hessian_output << "=";
d2->writeOutput(hessian_output, output_type, temporary_terms);
hessian_output << ";" << endl;
......@@ -1983,17 +1983,17 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput) const
if (id1 != id2)
{
hessian_output << "v2";
matrixHelper(hessian_output, k, 0, output_type);
hessianHelper(hessian_output, k, 0, output_type);
hessian_output << "=" << eq + 1 << ";" << endl;
hessian_output << "v2";
matrixHelper(hessian_output, k, 1, output_type);
hessianHelper(hessian_output, k, 1, output_type);
hessian_output << "=" << col_nb_sym + 1 << ";" << endl;
hessian_output << "v2";
matrixHelper(hessian_output, k, 2, output_type);
hessianHelper(hessian_output, k, 2, output_type);
hessian_output << "=v2";
matrixHelper(hessian_output, k-1, 2, output_type);
hessianHelper(hessian_output, k-1, 2, output_type);
hessian_output << ";" << endl;
k++;
......
......@@ -281,7 +281,7 @@ ModelTree::addEquation(NodeID eq)
}
void
ModelTree::matrixHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const
ModelTree::jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const
{
output << LEFT_ARRAY_SUBSCRIPT(output_type);
if (IS_MATLAB(output_type))
......@@ -290,3 +290,14 @@ ModelTree::matrixHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputTy
output << eq_nb + col_nb * equations.size();
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
}
void
ModelTree::hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const
{
output << LEFT_ARRAY_SUBSCRIPT(output_type);
if (IS_MATLAB(output_type))
output << row_nb + 1 << ", " << col_nb + 1;
else
output << row_nb + col_nb * NNZDerivatives[1];
output << RIGHT_ARRAY_SUBSCRIPT(output_type);
}
......@@ -99,8 +99,13 @@ protected:
//! Writes model equations
void writeModelEquations(ostream &output, ExprNodeOutputType output_type) const;
//! Writes either (i+1,j+1) or [i+j*n_i] whether we are in Matlab or C mode
void matrixHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const;
//! Helper for writing the Jacobian elements in MATLAB and C
/*! Writes either (i+1,j+1) or [i+j*no_eq] */
void jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const;
//! Helper for writing the sparse Hessian elements in MATLAB and C
/*! Writes either (i+1,j+1) or [i+j*NNZDerivatives[1]] */
void hessianHelper(ostream &output, int row_nb, int col_nb, ExprNodeOutputType output_type) const;
//! Writes LaTeX model file
void writeLatexModelFile(const string &filename, ExprNodeOutputType output_type) const;
......
......@@ -156,7 +156,7 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const
ostringstream g1;
g1 << " g1";
matrixHelper(g1, eq, symbol_table.getTypeSpecificID(symb_id), output_type);
jacobianHelper(g1, eq, symbol_table.getTypeSpecificID(symb_id), output_type);
jacobian_output << g1.str() << "=" << g1.str() << "+";
d1->writeOutput(jacobian_output, output_type, temporary_terms);
......@@ -180,15 +180,15 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const
int col_nb_sym = tsid2*symbol_table.endo_nbr()+tsid1;
hessian_output << "v2";
matrixHelper(hessian_output, k, 0, output_type);
hessianHelper(hessian_output, k, 0, output_type);
hessian_output << "=" << eq + 1 << ";" << endl;
hessian_output << "v2";
matrixHelper(hessian_output, k, 1, output_type);
hessianHelper(hessian_output, k, 1, output_type);
hessian_output << "=" << col_nb + 1 << ";" << endl;
hessian_output << "v2";
matrixHelper(hessian_output, k, 2, output_type);
hessianHelper(hessian_output, k, 2, output_type);
hessian_output << "=";
d2->writeOutput(hessian_output, output_type, temporary_terms);
hessian_output << ";" << endl;
......@@ -199,17 +199,17 @@ StaticModel::writeStaticModel(ostream &StaticOutput) const
if (symb_id1 != symb_id2)
{
hessian_output << "v2";
matrixHelper(hessian_output, k, 0, output_type);
hessianHelper(hessian_output, k, 0, output_type);
hessian_output << "=" << eq + 1 << ";" << endl;
hessian_output << "v2";
matrixHelper(hessian_output, k, 1, output_type);
hessianHelper(hessian_output, k, 1, output_type);
hessian_output << "=" << col_nb_sym + 1 << ";" << endl;
hessian_output << "v2";
matrixHelper(hessian_output, k, 2, output_type);
hessianHelper(hessian_output, k, 2, output_type);
hessian_output << "=v2";
matrixHelper(hessian_output, k-1, 2, output_type);
hessianHelper(hessian_output, k-1, 2, output_type);
hessian_output << ";" << endl;
k++;
......
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