preprocessor: fix scoping problem with temporary variables

issue#70
Houtan Bastani 2015-09-04 14:58:14 +02:00
parent 0f75ddbd64
commit 3117bf79f2
2 changed files with 24 additions and 27 deletions

View File

@ -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;
}

View File

@ -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
{