Commit ae8d5774 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

preprocessor: fix scoping problem with temporary variables

parent 5bd51d65
......@@ -2318,10 +2318,10 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
<< " %" << endl
<< endl
<< jacobian_output.str()
<< "end" << endl;
<< endl
// Initialize g2 matrix
DynamicOutput << "if nargout >= 3," << endl
<< "if nargout >= 3," << endl
<< " %" << endl
<< " % Hessian matrix" << endl
<< " %" << endl
......@@ -2332,7 +2332,6 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
<< " g2 = sparse(v2(:,1),v2(:,2),v2(:,3)," << nrows << "," << hessianColsNbr << ");" << endl;
else // Either hessian is all zero, or we didn't compute it
DynamicOutput << " g2 = sparse([],[],[]," << nrows << "," << hessianColsNbr << ");" << endl;
DynamicOutput << "end" << endl;
// Initialize g3 matrix
DynamicOutput << "if nargout >= 4," << endl
......@@ -2348,7 +2347,9 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
else // Either 3rd derivatives is all zero, or we didn't compute it
DynamicOutput << " g3 = sparse([],[],[]," << nrows << "," << ncols << ");" << endl;
DynamicOutput << "end" << endl;
DynamicOutput << "end" << endl
<< "end" << endl
<< "end" << endl;
}
else if (output_type == oCDynamicModel)
{
......@@ -2362,28 +2363,25 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
<< " /* Jacobian */" << endl
<< " if (g1 == NULL)" << endl
<< " return;" << endl
<< " else" << endl
<< " {" << endl
<< endl
<< jacobian_output.str()
<< " }" << endl;
<< endl;
if (second_derivatives.size())
DynamicOutput << " /* Hessian for endogenous and exogenous variables */" << endl
<< " if (v2 == NULL)" << endl
<< " return;" << endl
<< " else" << endl
<< " {" << endl
<< endl
<< hessian_output.str()
<< " }" << endl;
<< endl;
if (third_derivatives.size())
DynamicOutput << " /* Third derivatives for endogenous and exogenous variables */" << endl
<< " if (v3 == NULL)" << endl
<< " return;" << endl
<< " else" << endl
<< " {" << endl
<< endl
<< third_derivatives_output.str()
<< " }" << endl;
<< endl;
DynamicOutput << "}" << endl << endl;
}
......
......@@ -1392,7 +1392,6 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
<< " if ~isreal(g1)" << endl
<< " g1 = real(g1)+2*imag(g1);" << endl
<< " end" << endl
<< "end" << endl
<< "if nargout >= 3," << endl
<< " %" << endl
<< " % Hessian matrix" << endl
......@@ -1405,7 +1404,7 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
<< " g2 = sparse(v2(:,1),v2(:,2),v2(:,3)," << equations.size() << "," << g2ncols << ");" << endl;
else
StaticOutput << " g2 = sparse([],[],[]," << equations.size() << "," << g2ncols << ");" << endl;
StaticOutput << "end" << endl;
// Initialize g3 matrix
StaticOutput << "if nargout >= 4," << endl
<< " %" << endl
......@@ -1419,6 +1418,9 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
<< " g3 = sparse(v3(:,1),v3(:,2),v3(:,3)," << nrows << "," << ncols << ");" << endl;
else // Either 3rd derivatives is all zero, or we didn't compute it
StaticOutput << " g3 = sparse([],[],[]," << nrows << "," << ncols << ");" << endl;
StaticOutput << "end" << endl
<< "end" << endl
<< "end" << endl;
}
else if (output_type == oCStaticModel)
{
......@@ -1432,27 +1434,24 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
<< " /* Jacobian */" << endl
<< " if (g1 == NULL)" << endl
<< " return;" << endl
<< " else" << endl
<< " {" << endl
<< endl
<< jacobian_output.str()
<< " }" << endl;
<< endl;
if (second_derivatives.size())
StaticOutput << " /* Hessian for endogenous and exogenous variables */" << endl
<< " if (v2 == NULL)" << endl
<< " return;" << endl
<< " else" << endl
<< " {" << endl
<< endl
<< hessian_output.str()
<< " }" << endl;
<< endl;
if (third_derivatives.size())
StaticOutput << " /* Third derivatives for endogenous and exogenous variables */" << endl
<< " if (v3 == NULL)" << endl
<< " return;" << endl
<< " else" << endl
<< " {" << endl
<< third_derivatives_output.str()
<< " }" << endl;
<< " if (v3 == NULL)" << endl
<< " return;" << endl
<< endl
<< third_derivatives_output.str()
<< endl;
}
else
{
......
Markdown is supported
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