Bytecode: fix stack_solve_algo=4 when a “solve backward/forward” block follows a “solve two boundaries” block

When solving a “Solve two boundarise” block with stack_solve_algo=4, the
“slowc” variable is modified. This would affect the resolution of further
“solve backward/forward” blocks, which would yield results.

The fix consists in saving and restoring “slowc”.
trustregion
Sébastien Villemot 2022-03-15 15:19:19 +01:00
parent 52dfad35f9
commit 96fb676be7
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 3 additions and 0 deletions

View File

@ -310,6 +310,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
max_res_idx = 0;
bool cvg;
double *y_save;
double another_slowc_save;
#ifdef DEBUG
mexPrintf("simulate_a_block type = %d, periods=%d, y_kmin=%d, y_kmax=%d\n", type, periods, y_kmin, y_kmax);
mexEvalString("drawnow;");
@ -429,6 +430,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
test_mxMalloc(y_save, __LINE__, __FILE__, __func__, y_size*sizeof(double)*(periods+y_kmax+y_kmin));
start_code = it_code;
iter = 0;
another_slowc_save = slowc; // slowc is modified when stack_solve_algo=4, so save it
if (!is_linear
|| stack_solve_algo == 4) // On linear blocks, stack_solve_algo=4 may
// need more than one iteration to find the
@ -485,6 +487,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
Simulate_Newton_Two_Boundaries(block_num, symbol_table_endo_nbr, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, endo_name_length, P_endo_names, vector_table_conditional_local);
max_res = 0; max_res_idx = 0;
}
slowc = another_slowc_save; // slowc is modified when stack_solve_algo=4, so restore it
it_code = end_code;
if (r)
mxFree(r);