From cfaf5a685dfb6883f9a31ee68b63d74c7b2038c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 17 Jan 2023 19:05:04 +0100
Subject: [PATCH] =?UTF-8?q?Preprocessor:=20actually=20obey=20the=20?=
 =?UTF-8?q?=E2=80=9Cmfs=E2=80=9D=20option=20for=20the=20static=20model?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

As a consequence, fix steady state computation when mfs > 0.
---
 matlab/evaluate_steady_state.m | 30 +++++++++++++++---------------
 preprocessor                   |  2 +-
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m
index b64c143d02..c0bb16be5a 100644
--- a/matlab/evaluate_steady_state.m
+++ b/matlab/evaluate_steady_state.m
@@ -361,20 +361,19 @@ elseif ~options.bytecode && options.block
         fh_static = str2func(sprintf('%s.sparse.block.static_%d', M.fname, b));
         if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ...
                 M.block_structure_stat.block(b).Simulation_Type ~= 2
+            mfs_idx = M.block_structure_stat.block(b).variable(end-M.block_structure_stat.block(b).mfs+1:end);
             if options.solve_algo <= 4 || options.solve_algo >= 9
-                [z, errorflag] = dynare_solve(@block_mfs_steadystate, ...
-                                              ys(M.block_structure_stat.block(b).variable), ...
-                                              options.simul.maxit, options.solve_tolf, options.solve_tolx, ...
-                                              options, fh_static, b, ys, exo_ss, params, T, M);
+                [ys(mfs_idx), errorflag] = dynare_solve(@block_mfs_steadystate, ys(mfs_idx), ...
+                                                        options.simul.maxit, options.solve_tolf, options.solve_tolx, ...
+                                                        options, fh_static, b, ys, exo_ss, params, T, M);
                 if errorflag
                     check = 1;
                     break
                 end
-                ys(M.block_structure_stat.block(b).variable) = z;
             else
-                n = length(M.block_structure_stat.block(b).variable);
+                nze = length(M.block_structure_stat.block(b).g1_sparse_rowval);
                 [ys, T, ~, info2] = solve_one_boundary(fh_static, ys, exo_ss, ...
-                                                       params, [], T, M.block_structure_stat.block(b).variable, n, 1, false, b, 0, options.simul.maxit, ...
+                                                       params, [], T, mfs_idx, nze, 1, false, b, 0, options.simul.maxit, ...
                                                        options.solve_tolf, ...
                                                        0, options.solve_algo, true, false, false, M, options, []);
                 if info2
@@ -407,15 +406,15 @@ elseif options.bytecode
         for b = 1:length(M.block_structure_stat.block)
             if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ...
                     M.block_structure_stat.block(b).Simulation_Type ~= 2
-                [z, errorflag] = dynare_solve(@block_bytecode_mfs_steadystate, ...
-                                              ys(M.block_structure_stat.block(b).variable), ...
-                                              options.simul.maxit, options.solve_tolf, options.solve_tolx, ...
-                                              options, b, ys, exo_ss, params, T, M);
+                mfs_idx = M.block_structure_stat.block(b).variable(end-M.block_structure_stat.block(b).mfs+1:end);
+                [ys(mfs_idx), errorflag] = dynare_solve(@block_bytecode_mfs_steadystate, ...
+                                                        ys(mfs_idx), options.simul.maxit, ...
+                                                        options.solve_tolf, options.solve_tolx, ...
+                                                        options, b, ys, exo_ss, params, T, M);
                 if errorflag
                     check = 1;
                     break
                 end
-                ys(M.block_structure_stat.block(b).variable) = z;
             end
             % Compute endogenous if the block is of type evaluate forward/backward or if there are recursive variables in a solve block.
             % Also update the temporary terms vector (needed for the dynare_solve case)
@@ -496,13 +495,14 @@ jac = j(eq_index,1:nvar);
 
 function [r, g1] = block_mfs_steadystate(y, fh_static, b, y_all, exo, params, T, M)
 % Wrapper around the static files, for block without bytecode
-y_all(M.block_structure_stat.block(b).variable) = y;
+mfs_idx = M.block_structure_stat.block(b).variable(end-M.block_structure_stat.block(b).mfs+1:end);
+y_all(mfs_idx) = y;
 [~,~,r,g1] = fh_static(y_all, exo, params, M.block_structure_stat.block(b).g1_sparse_rowval, ...
                        M.block_structure_stat.block(b).g1_sparse_colval, ...
                        M.block_structure_stat.block(b).g1_sparse_colptr, T);
 
 function [r, g1] = block_bytecode_mfs_steadystate(y, b, y_all, exo, params, T, M)
 % Wrapper around the static files, for block without bytecode
-indx = M.block_structure_stat.block(b).variable;
-y_all(indx) = y;
+mfs_idx = M.block_structure_stat.block(b).variable(end-M.block_structure_stat.block(b).mfs+1:end);
+y_all(mfs_idx) = y;
 [r, g1] = bytecode(y_all, exo, params, y_all, 1, y_all, T, 'evaluate', 'static', 'block_decomposed', ['block = ' int2str(b) ]);
diff --git a/preprocessor b/preprocessor
index 4bba274f39..7db02b23e9 160000
--- a/preprocessor
+++ b/preprocessor
@@ -1 +1 @@
-Subproject commit 4bba274f3931222df89f3a04b016340f6b2222df
+Subproject commit 7db02b23e9408983758bb38ba844b4959670b8b5
-- 
GitLab