From 6509bc7d3651d7b82adbf4ca53042dbefe6fe7fb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 29 Apr 2022 11:17:11 +0200
Subject: [PATCH] =?UTF-8?q?Allow=20=E2=80=9Clearnt=5Fin=3D1=E2=80=9D=20for?=
 =?UTF-8?q?=20=E2=80=9Cshocks=E2=80=9D=20and=20=E2=80=9Cendval=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In that case, the option has no effect.
---
 src/ParsingDriver.cc | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc
index 2b177248..f6506cec 100644
--- a/src/ParsingDriver.cc
+++ b/src/ParsingDriver.cc
@@ -751,8 +751,13 @@ void
 ParsingDriver::end_endval_learnt_in(const string &learnt_in_period)
 {
   int learnt_in_period_int = stoi(learnt_in_period);
-  if (learnt_in_period_int < 2)
+  if (learnt_in_period_int < 1)
     error("endval: value '" + learnt_in_period + "' is not allowed for 'learnt_in' option");
+  if (learnt_in_period_int == 1)
+    {
+      end_endval(false);
+      return;
+    }
   for (auto [symb_id, value] : init_values)
     if (mod_file->symbol_table.getType(symb_id) != SymbolType::exogenous)
       error("endval(learnt_in=...): " + mod_file->symbol_table.getName(symb_id) + " is not an exogenous variable");
@@ -842,9 +847,9 @@ ParsingDriver::end_shocks(bool overwrite)
                                                       covar_shocks, corr_shocks, mod_file->symbol_table));
   det_shocks.clear();
   if (!learnt_shocks_add.empty())
-    error("shocks: 'add' keyword not allowed unless 'learnt_in' option is passed");
+    error("shocks: 'add' keyword not allowed unless 'learnt_in' option with value >1 is passed");
   if (!learnt_shocks_multiply.empty())
-    error("shocks: 'multiply' keyword not allowed unless 'learnt_in' option is passed");
+    error("shocks: 'multiply' keyword not allowed unless 'learnt_in' option with value >1 is passed");
   var_shocks.clear();
   std_shocks.clear();
   covar_shocks.clear();
@@ -877,8 +882,13 @@ void
 ParsingDriver::end_shocks_learnt_in(const string &learnt_in_period, bool overwrite)
 {
   int learnt_in_period_int = stoi(learnt_in_period);
-  if (learnt_in_period_int < 2)
+  if (learnt_in_period_int < 1)
     error("shocks: value '" + learnt_in_period + "' is not allowed for 'learnt_in' option");
+  if (learnt_in_period_int == 1)
+    {
+      end_shocks(overwrite);
+      return;
+    }
   for (auto &[symb_id, vals] : det_shocks)
     for (auto [period1, period2, expr] : vals)
       if (period1 < learnt_in_period_int)
-- 
GitLab