From a9b4331a957be6154d597462501a74b5bb7ee408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 6 Dec 2010 17:00:46 +0100 Subject: [PATCH] Bugfix at order 3 (hopefully was not affecting final results, thanks to Pablo Winant for spotting this): - in the 3rd derivatives matrix, among symmetric elements, the first one had the right values but the following ones were set to zero - moreover, the k-order DLL was trying to add all the symmetric elements in the folded tensor, instead of only keeping one value among all the symmetric ones - hopefully, Ondra's tensor library was (silently) refusing to add symmetric elements after the first (and right) value had been added - so the final result was correct --- .../k_order_perturbation/k_ord_dynare.cc | 24 +++---------------- preprocessor/DynamicModel.cc | 4 +--- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/mex/sources/k_order_perturbation/k_ord_dynare.cc b/mex/sources/k_order_perturbation/k_ord_dynare.cc index cce518db9..ce0b1b855 100644 --- a/mex/sources/k_order_perturbation/k_ord_dynare.cc +++ b/mex/sources/k_order_perturbation/k_ord_dynare.cc @@ -211,27 +211,9 @@ KordpDynare::populateDerivativesContainer(const TwoDMatrix &g, int ord, const ve s[2] = revOrder[s2]; else s[2] = s2; - // reordering symmetry indices in increasing order - if (s[0] > s[1]) - { - int temp = s[0]; - s[0] = s[1]; - s[1] = temp; - } - if (s[1] > s[2]) - { - int temp = s[1]; - s[1] = s[2]; - s[2] = temp; - } - if (s[0] > s[1]) - { - int temp = s[0]; - s[0] = s[1]; - s[1] = temp; - } - double x = g.get(i, 2); - mdTi->insert(s, j, x); + double x = g.get(i, 2); + if (s.isSorted()) + mdTi->insert(s, j, x); } } diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index c69bb7ef6..f071edd86 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -2137,8 +2137,6 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll) const d3->writeOutput(third_derivatives_output, output_type, temporary_terms); third_derivatives_output << ";" << endl; - k++; - // Compute the column numbers for the 5 other permutations of (id1,id2,id3) and store them in a set (to avoid duplicates if two indexes are equal) set cols; cols.insert(id1 * hessianColsNbr + id3 * dynJacobianColsNbr + id2); @@ -2147,7 +2145,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll) const cols.insert(id3 * hessianColsNbr + id1 * dynJacobianColsNbr + id2); cols.insert(id3 * hessianColsNbr + id2 * dynJacobianColsNbr + id1); - int k2 = 0; // Keeps the offset of the permutation relative to k + int k2 = 1; // Keeps the offset of the permutation relative to k for (set::iterator it2 = cols.begin(); it2 != cols.end(); it2++) if (*it2 != ref_col) {