From 58b2bc78c3aa8a6612adeaed6c8a92a09f86405d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 4 May 2021 16:31:44 +0200
Subject: [PATCH] Testsuite: check that stochastic solution in block
 decomposition mode is correct

Only test with mfs=0, since the result is wrong for other mfs values.

Ref. #1726
---
 tests/Makefile.am                             |  4 +++
 tests/block_bytecode/lola_stochastic.mod      |  5 ++++
 .../block_bytecode/lola_stochastic_block.mod  | 26 +++++++++++++++++++
 3 files changed, 35 insertions(+)
 create mode 100644 tests/block_bytecode/lola_stochastic.mod
 create mode 100644 tests/block_bytecode/lola_stochastic_block.mod

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 871f1ae33f..79fef2cbdc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -162,6 +162,8 @@ MODFILES = \
 	block_bytecode/lola_solve_one_boundary_mfs1.mod \
 	block_bytecode/lola_solve_one_boundary_mfs2.mod \
 	block_bytecode/lola_solve_one_boundary_mfs3.mod \
+	block_bytecode/lola_stochastic.mod \
+	block_bytecode/lola_stochastic_block.mod \
 	k_order_perturbation/fs2000k2a.mod \
 	k_order_perturbation/fs2000k2_use_dll.mod \
 	k_order_perturbation/fs2000k_1_use_dll.mod \
@@ -703,6 +705,8 @@ block_bytecode/lola_solve_one_boundary_mfs2.m.trs: block_bytecode/lola_solve_one
 block_bytecode/lola_solve_one_boundary_mfs2.o.trs: block_bytecode/lola_solve_one_boundary.o.trs
 block_bytecode/lola_solve_one_boundary_mfs3.m.trs: block_bytecode/lola_solve_one_boundary.m.trs
 block_bytecode/lola_solve_one_boundary_mfs3.o.trs: block_bytecode/lola_solve_one_boundary.o.trs
+block_bytecode/lola_stochastic_block.m.trs: block_bytecode/lola_stochastic.m.trs
+block_bytecode/lola_stochastic_block.o.trs: block_bytecode/lola_stochastic.o.trs
 
 histval_initval_file/ramst_initval_file.m.trs: histval_initval_file/ramst_initval_file_data.m.tls histval_initval_file/ramst_data_generate.m.trs
 histval_initval_file/ramst_initval_file.o.trs: histval_initval_file/ramst_initval_file_data.o.tls histval_initval_file/ramst_data_generate.o.trs
diff --git a/tests/block_bytecode/lola_stochastic.mod b/tests/block_bytecode/lola_stochastic.mod
new file mode 100644
index 0000000000..e6c0071fc9
--- /dev/null
+++ b/tests/block_bytecode/lola_stochastic.mod
@@ -0,0 +1,5 @@
+// Stochastic version of LOLA model, as benchmark for lola_stochastic_block.mod
+
+@#define deterministic = false
+@#define block = false
+@#include "lola_common.inc"
diff --git a/tests/block_bytecode/lola_stochastic_block.mod b/tests/block_bytecode/lola_stochastic_block.mod
new file mode 100644
index 0000000000..c189d336ad
--- /dev/null
+++ b/tests/block_bytecode/lola_stochastic_block.mod
@@ -0,0 +1,26 @@
+/* Stochastic version of block decomposed LOLA model.
+   Check that policy functions are the same as in non-block version. */
+
+@#define deterministic = false
+@#define block = true
+@#define mfs = 0
+@#include "lola_common.inc"
+
+[~, state_reorder] = sort(oo_.dr.state_var);
+
+ref = load('lola_stochastic_results.mat');
+
+[~, ref_state_reorder] = sort(ref.oo_.dr.state_var);
+
+/* NB: With block, the rows of ghx and ghu are in declaration order (and not in
+       DR-order as in non-block mode) */
+
+if max(max(abs(oo_.dr.ghx(:, state_reorder) - ref.oo_.dr.ghx(ref.oo_.dr.inv_order_var, ref_state_reorder)))) > 2e-9
+    error('Error in ghx')
+end
+
+if max(max(abs(oo_.dr.ghu - ref.oo_.dr.ghu(ref.oo_.dr.inv_order_var, :)))) > 6e-9
+    error('Error in ghu')
+end
+
+
-- 
GitLab