Skip to content
Snippets Groups Projects
Verified Commit feed9d32 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

local_state_space_iteration_2 MEX: fix bug when there are more shocks that states

The code that computes ghx·yhat+ghu·u (both with and without pruning) was
making the implicit assumption that q⩽n, i.e. that the number of shocks is less
than or equal to the number of states. If q>n, it would try to read invalid
memory references in ghx and yhat, and would thus either crash or return dummy
results.

Closes: #1820
(cherry picked from commit ce282dc2)
parent 40c559ba
Branches
Tags
No related merge requests found
/*
* Copyright © 2010-2019 Dynare Team
* Copyright © 2010-2021 Dynare Team
*
* This file is part of Dynare.
*
......@@ -80,16 +80,10 @@ ss2Iteration_pruning(double *y2, double *y1, const double *yhat2, const double *
int variable_ = variable + particle_;
// +ghx·yhat2+ghu·u
#ifdef FIRST_ORDER_LOOP
for (int column = 0, column_ = 0; column < q; column++, column_ += m)
{
int i1 = variable+column_;
int i2 = column+particle__;
int i3 = column+particle___;
y2[variable_] += ghx[i1]*yhat2[i2];
y2[variable_] += ghu[i1]*epsilon[i3];
}
for (int column = q, column_ = q*m; column < n; column++, column_ += m)
for (int column = 0, column_ = 0; column < n; column++, column_ += m)
y2[variable_] += ghx[variable+column_]*yhat2[column+particle__];
for (int column = 0, column_ = 0; column < q; column++, column_ += m)
y2[variable_] += ghu[variable+column_]*epsilon[column+particle___];
#endif
// +ghxx·yhat1⊗yhat1
for (int i = 0; i < n*(n+1)/2; i++)
......@@ -163,16 +157,10 @@ ss2Iteration(double *y, const double *yhat, const double *epsilon,
int variable_ = variable + particle_;
// +ghx·yhat+ghu·u
#ifdef FIRST_ORDER_LOOP
for (int column = 0, column_ = 0; column < q; column++, column_ += m)
{
int i1 = variable+column_;
int i2 = column+particle__;
int i3 = column+particle___;
y[variable_] += ghx[i1]*yhat[i2];
y[variable_] += ghu[i1]*epsilon[i3];
}
for (int column = q, column_ = q*m; column < n; column++, column_ += m)
for (int column = 0, column_ = 0; column < n; column++, column_ += m)
y[variable_] += ghx[variable+column_]*yhat[column+particle__];
for (int column = 0, column_ = 0; column < q; column++, column_ += m)
y[variable_] += ghu[variable+column_]*epsilon[column+particle___];
#endif
// +ghxx·yhat⊗yhat
for (int i = 0; i < n*(n+1)/2; i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment