From 96e3a1b73e2c62878df3dffcaeb355e338ab5d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr> Date: Mon, 8 Feb 2010 16:58:24 +0100 Subject: [PATCH] k_order_perturbation: fixed illegal cast (cherry picked from commit 34ab1a5686f43b3c43249d46c3e44bf18e73a2a9) --- .../k_order_perturbation/k_order_perturbation.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mex/sources/k_order_perturbation/k_order_perturbation.cc b/mex/sources/k_order_perturbation/k_order_perturbation.cc index 6bac93865b..975deacc76 100644 --- a/mex/sources/k_order_perturbation/k_order_perturbation.cc +++ b/mex/sources/k_order_perturbation/k_order_perturbation.cc @@ -44,6 +44,7 @@ #include <cmath> #include <cstring> #include <cctype> +#include <cassert> #ifdef _MSC_VER @@ -303,8 +304,11 @@ extern "C" { map<string, ConstTwoDMatrix>::const_iterator cit = mm.begin(); ++cit; plhs[0] = mxCreateDoubleMatrix((*cit).second.numRows(), (*cit).second.numCols(), mxREAL); - TwoDMatrix g((*cit).second.numRows(), (*cit).second.numCols(), mxGetPr(plhs[0])); - g = (const TwoDMatrix &)(*cit).second; + + // Copy Dynare++ matrix into MATLAB matrix + const ConstVector &vec = (*cit).second.getData(); + assert(vec.skip() == 1); + memcpy(mxGetPr(plhs[0]), vec.base(), vec.length() * sizeof(double)); } if (kOrder >= 2) { @@ -314,8 +318,12 @@ extern "C" { { { plhs[ii] = mxCreateDoubleMatrix((*cit).second.numRows(), (*cit).second.numCols(), mxREAL); - TwoDMatrix g_ii((*cit).second.numRows(), (*cit).second.numCols(), mxGetPr(plhs[ii])); - g_ii = (const TwoDMatrix &)(*cit).second; + + // Copy Dynare++ matrix into MATLAB matrix + const ConstVector &vec = (*cit).second.getData(); + assert(vec.skip() == 1); + memcpy(mxGetPr(plhs[ii]), vec.base(), vec.length() * sizeof(double)); + ++ii; } } -- GitLab