Small improvements to external functions code.

time-shift
Sébastien Villemot 2014-02-24 15:37:55 +01:00
parent 64d3d5cdc8
commit 711a4f62a2
2 changed files with 15 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2003-2012 Dynare Team * Copyright (C) 2003-2014 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -68,10 +68,16 @@ protected:
binary_op_node_map_t binary_op_node_map; binary_op_node_map_t binary_op_node_map;
typedef map<pair<pair<pair<expr_t, expr_t>, expr_t>, TrinaryOpcode>, TrinaryOpNode *> trinary_op_node_map_t; typedef map<pair<pair<pair<expr_t, expr_t>, expr_t>, TrinaryOpcode>, TrinaryOpNode *> trinary_op_node_map_t;
trinary_op_node_map_t trinary_op_node_map; trinary_op_node_map_t trinary_op_node_map;
// (arguments, symb_id) -> ExternalFunctionNode
typedef map<pair<vector<expr_t>, int>, ExternalFunctionNode *> external_function_node_map_t; typedef map<pair<vector<expr_t>, int>, ExternalFunctionNode *> external_function_node_map_t;
external_function_node_map_t external_function_node_map; external_function_node_map_t external_function_node_map;
// ((arguments, deriv_idx), symb_id) -> FirstDerivExternalFunctionNode
typedef map<pair<pair<vector<expr_t>, int>, int>, FirstDerivExternalFunctionNode *> first_deriv_external_function_node_map_t; typedef map<pair<pair<vector<expr_t>, int>, int>, FirstDerivExternalFunctionNode *> first_deriv_external_function_node_map_t;
first_deriv_external_function_node_map_t first_deriv_external_function_node_map; first_deriv_external_function_node_map_t first_deriv_external_function_node_map;
// ((arguments, (deriv_idx1, deriv_idx2)), symb_id) -> SecondDerivExternalFunctionNode
typedef map<pair<pair<vector<expr_t>, pair<int, int> >, int>, SecondDerivExternalFunctionNode *> second_deriv_external_function_node_map_t; typedef map<pair<pair<vector<expr_t>, pair<int, int> >, int>, SecondDerivExternalFunctionNode *> second_deriv_external_function_node_map_t;
second_deriv_external_function_node_map_t second_deriv_external_function_node_map; second_deriv_external_function_node_map_t second_deriv_external_function_node_map;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2007-2013 Dynare Team * Copyright (C) 2007-2014 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -4935,12 +4935,10 @@ FirstDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType
return; return;
} }
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); const int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
int tmpIndx = inputIndex; const int tmpIndx = inputIndex - ARRAY_SUBSCRIPT_OFFSET(output_type);
if (IS_C(output_type))
tmpIndx = tmpIndx - 1;
if (first_deriv_symb_id == symb_id) if (first_deriv_symb_id == symb_id)
output << "TEFD_" << getIndxInTefTerms(symb_id, tef_terms) output << "TEFD_" << getIndxInTefTerms(symb_id, tef_terms)
@ -4982,15 +4980,14 @@ FirstDerivExternalFunctionNode::compile(ostream &CompileCode, unsigned int &inst
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
int tmpIndx = inputIndex;
if (!lhs_rhs) if (!lhs_rhs)
{ {
FLDTEFD_ fldtefd(getIndxInTefTerms(symb_id, tef_terms), tmpIndx); FLDTEFD_ fldtefd(getIndxInTefTerms(symb_id, tef_terms), inputIndex);
fldtefd.write(CompileCode, instruction_number); fldtefd.write(CompileCode, instruction_number);
} }
else else
{ {
FSTPTEFD_ fstptefd(getIndxInTefTerms(symb_id, tef_terms), tmpIndx); FSTPTEFD_ fstptefd(getIndxInTefTerms(symb_id, tef_terms), inputIndex);
fstptefd.write(CompileCode, instruction_number); fstptefd.write(CompileCode, instruction_number);
} }
} }
@ -5193,16 +5190,11 @@ SecondDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType
return; return;
} }
int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); const int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id);
assert(second_deriv_symb_id != eExtFunSetButNoNameProvided); assert(second_deriv_symb_id != eExtFunSetButNoNameProvided);
int tmpIndex1 = inputIndex1; const int tmpIndex1 = inputIndex1 - ARRAY_SUBSCRIPT_OFFSET(output_type);
int tmpIndex2 = inputIndex2; const int tmpIndex2 = inputIndex2 - ARRAY_SUBSCRIPT_OFFSET(output_type);
if (IS_C(output_type))
{
tmpIndex1 = tmpIndex1 - 1;
tmpIndex2 = tmpIndex2 - 1;
}
int indx = getIndxInTefTerms(symb_id, tef_terms); int indx = getIndxInTefTerms(symb_id, tef_terms);
if (second_deriv_symb_id == symb_id) if (second_deriv_symb_id == symb_id)