add @inbounds to model equations, temporary vars, and model vars

issue#70
Houtan Bastani 2015-08-21 16:54:11 +02:00
parent 089f9a7eb2
commit 5c0c9efd6f
3 changed files with 27 additions and 15 deletions

View File

@ -2390,13 +2390,13 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia
<< " steady_state::Vector{Float64}, it_::Int, " << " steady_state::Vector{Float64}, it_::Int, "
<< "residual::Vector{Float64})" << endl << "residual::Vector{Float64})" << endl
<< "#=" << endl << comments.str() << "=#" << endl << "#=" << endl << comments.str() << "=#" << endl
<< "@assert size(y) == " << dynJacobianColsNbr << endl << " @assert size(y) == " << dynJacobianColsNbr << endl
<< "@assert size(params) == " << symbol_table.param_nbr() << endl << " @assert size(params) == " << symbol_table.param_nbr() << endl
<< "@assert size(residual) == " << nrows << endl << " @assert size(residual) == " << nrows << endl
<< "fill!(residual, 0.0)" << endl << " fill!(residual, 0.0)" << endl
<< "#" << endl << " #" << endl
<< "# Model equations" << endl << " # Model equations" << endl
<< "#" << endl << " #" << endl
<< model_output.str() << model_output.str()
<< model_eq_output.str() << model_eq_output.str()
<< "end" << endl << endl << "end" << endl << endl

View File

@ -1127,6 +1127,8 @@ ModelTree::writeTemporaryTerms(const temporary_terms_t &tt, ostream &output,
if (IS_C(output_type)) if (IS_C(output_type))
output << "double "; output << "double ";
else if (IS_JULIA(output_type))
output << " @inbounds ";
(*it)->writeOutput(output, output_type, tt, tef_terms); (*it)->writeOutput(output, output_type, tt, tef_terms);
output << " = "; output << " = ";
@ -1199,6 +1201,8 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t
if (IS_C(output_type)) if (IS_C(output_type))
output << "double "; output << "double ";
else if (IS_JULIA(output_type))
output << " @inbounds ";
/* We append underscores to avoid name clashes with "g1" or "oo_" (see /* We append underscores to avoid name clashes with "g1" or "oo_" (see
also VariableNode::writeOutput) */ also VariableNode::writeOutput) */
@ -1229,14 +1233,20 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type)
if (vrhs != 0) // The right hand side of the equation is not empty ==> residual=lhs-rhs; if (vrhs != 0) // The right hand side of the equation is not empty ==> residual=lhs-rhs;
{ {
if (IS_JULIA(output_type))
output << " @inbounds ";
output << "lhs ="; output << "lhs =";
lhs->writeOutput(output, output_type, temporary_terms); lhs->writeOutput(output, output_type, temporary_terms);
output << ";" << endl; output << ";" << endl;
if (IS_JULIA(output_type))
output << " @inbounds ";
output << "rhs ="; output << "rhs =";
rhs->writeOutput(output, output_type, temporary_terms); rhs->writeOutput(output, output_type, temporary_terms);
output << ";" << endl; output << ";" << endl;
if (IS_JULIA(output_type))
output << " @inbounds ";
output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type) output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type)
<< eq + ARRAY_SUBSCRIPT_OFFSET(output_type) << eq + ARRAY_SUBSCRIPT_OFFSET(output_type)
<< RIGHT_ARRAY_SUBSCRIPT(output_type) << RIGHT_ARRAY_SUBSCRIPT(output_type)
@ -1244,6 +1254,8 @@ ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type)
} }
else // The right hand side of the equation is empty ==> residual=lhs; else // The right hand side of the equation is empty ==> residual=lhs;
{ {
if (IS_JULIA(output_type))
output << " @inbounds ";
output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type) output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type)
<< eq + ARRAY_SUBSCRIPT_OFFSET(output_type) << eq + ARRAY_SUBSCRIPT_OFFSET(output_type)
<< RIGHT_ARRAY_SUBSCRIPT(output_type) << RIGHT_ARRAY_SUBSCRIPT(output_type)

View File

@ -1453,14 +1453,14 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c
<< "params::Vector{Float64}," << endl << "params::Vector{Float64}," << endl
<< " residual::Vector{Float64})" << endl << " residual::Vector{Float64})" << endl
<< "#=" << endl << comments.str() << "=#" << endl << "#=" << endl << comments.str() << "=#" << endl
<< "@assert size(y) == " << symbol_table.endo_nbr() << endl << " @assert size(y) == " << symbol_table.endo_nbr() << endl
<< "@assert size(x) == " << symbol_table.exo_nbr() << endl << " @assert size(x) == " << symbol_table.exo_nbr() << endl
<< "@assert size(params) == " << symbol_table.param_nbr() << endl << " @assert size(params) == " << symbol_table.param_nbr() << endl
<< "@assert size(residual) == " << equations.size() << endl << " @assert size(residual) == " << equations.size() << endl
<< "fill!(residual, 0.0)" << endl << " fill!(residual, 0.0)" << endl
<< "#" << endl << " #" << endl
<< "# Model equations" << endl << " # Model equations" << endl
<< "#" << endl << " #" << endl
<< model_output.str() << model_output.str()
<< model_eq_output.str() << model_eq_output.str()
<< "if ~isreal(residual)" << endl << "if ~isreal(residual)" << endl