Invalid memory accesses in local_state_space_iteration_2 when there are more shocks than states

In local_state_space_iteration_2, in function ss2Iteration, the block that computes ghx·yhat+ghu·u reads as follows:

          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)
            y[variable_] += ghx[variable+column_]*yhat[column+particle__];

This code makes 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 will try to read invalid memory references in ghx and yhat, and it will either crash or return dummy results.

The same problem is present in the ss2Iteration_pruning function.

The fix is simply to reorganize the loops, with one loop that only deals with the states and another one that deals with shocks.

@stepan-a If you agree with this diagnostic, I will take care of fixing it.