From 5c0c9efd6f7d7040c59a0581c8a87a21ecd7243e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 21 Aug 2015 16:54:11 +0200 Subject: [PATCH] add @inbounds to model equations, temporary vars, and model vars --- DynamicModel.cc | 14 +++++++------- ModelTree.cc | 12 ++++++++++++ StaticModel.cc | 16 ++++++++-------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index adb3a4aa..c85c26fa 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -2390,13 +2390,13 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll, bool julia << " steady_state::Vector{Float64}, it_::Int, " << "residual::Vector{Float64})" << endl << "#=" << endl << comments.str() << "=#" << endl - << "@assert size(y) == " << dynJacobianColsNbr << endl - << "@assert size(params) == " << symbol_table.param_nbr() << endl - << "@assert size(residual) == " << nrows << endl - << "fill!(residual, 0.0)" << endl - << "#" << endl - << "# Model equations" << endl - << "#" << endl + << " @assert size(y) == " << dynJacobianColsNbr << endl + << " @assert size(params) == " << symbol_table.param_nbr() << endl + << " @assert size(residual) == " << nrows << endl + << " fill!(residual, 0.0)" << endl + << " #" << endl + << " # Model equations" << endl + << " #" << endl << model_output.str() << model_eq_output.str() << "end" << endl << endl diff --git a/ModelTree.cc b/ModelTree.cc index 3ce179a5..92b39963 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1127,6 +1127,8 @@ ModelTree::writeTemporaryTerms(const temporary_terms_t &tt, ostream &output, if (IS_C(output_type)) output << "double "; + else if (IS_JULIA(output_type)) + output << " @inbounds "; (*it)->writeOutput(output, output_type, tt, tef_terms); output << " = "; @@ -1199,6 +1201,8 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t if (IS_C(output_type)) output << "double "; + else if (IS_JULIA(output_type)) + output << " @inbounds "; /* We append underscores to avoid name clashes with "g1" or "oo_" (see 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 (IS_JULIA(output_type)) + output << " @inbounds "; output << "lhs ="; lhs->writeOutput(output, output_type, temporary_terms); output << ";" << endl; + if (IS_JULIA(output_type)) + output << " @inbounds "; output << "rhs ="; rhs->writeOutput(output, output_type, temporary_terms); output << ";" << endl; + if (IS_JULIA(output_type)) + output << " @inbounds "; output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type) << eq + ARRAY_SUBSCRIPT_OFFSET(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; { + if (IS_JULIA(output_type)) + output << " @inbounds "; output << "residual" << LEFT_ARRAY_SUBSCRIPT(output_type) << eq + ARRAY_SUBSCRIPT_OFFSET(output_type) << RIGHT_ARRAY_SUBSCRIPT(output_type) diff --git a/StaticModel.cc b/StaticModel.cc index a7e52267..63a60d52 100644 --- a/StaticModel.cc +++ b/StaticModel.cc @@ -1453,14 +1453,14 @@ StaticModel::writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) c << "params::Vector{Float64}," << endl << " residual::Vector{Float64})" << endl << "#=" << endl << comments.str() << "=#" << endl - << "@assert size(y) == " << symbol_table.endo_nbr() << endl - << "@assert size(x) == " << symbol_table.exo_nbr() << endl - << "@assert size(params) == " << symbol_table.param_nbr() << endl - << "@assert size(residual) == " << equations.size() << endl - << "fill!(residual, 0.0)" << endl - << "#" << endl - << "# Model equations" << endl - << "#" << endl + << " @assert size(y) == " << symbol_table.endo_nbr() << endl + << " @assert size(x) == " << symbol_table.exo_nbr() << endl + << " @assert size(params) == " << symbol_table.param_nbr() << endl + << " @assert size(residual) == " << equations.size() << endl + << " fill!(residual, 0.0)" << endl + << " #" << endl + << " # Model equations" << endl + << " #" << endl << model_output.str() << model_eq_output.str() << "if ~isreal(residual)" << endl