From 7a758f6779e9665d1d0bdb5fb7191af3cccbc5cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 28 Apr 2025 16:50:06 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20linearity=20check=20for=20?=
 =?UTF-8?q?Ramsey=20models=20with=20lead/lag>1=20on=20endos=20or=20>0=20on?=
 =?UTF-8?q?=20exos?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Ref. dynare#1960
---
 src/ModelEquationBlock.hh | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/ModelEquationBlock.hh b/src/ModelEquationBlock.hh
index 9b943b24..e5e7bddc 100644
--- a/src/ModelEquationBlock.hh
+++ b/src/ModelEquationBlock.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2010-2024 Dynare Team
+ * Copyright © 2010-2025 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -62,6 +62,17 @@ protected:
   {
     return "original Ramsey model";
   }
+  int
+  getJacobianCol(int deriv_id, [[maybe_unused]] bool sparse) const override
+  {
+    /* Override the DynamicModel method by returning a dummy Jacobian column number.
+       The override is necessary because the method from DynamicModel fails with
+       endos with lag/lead greater than 1 or exos with a lag/lead, while substitutions
+       are by definition not done for an original model.
+       In particular, this fixes dynare#1960 (equation derivatives are computed for models declared
+       as linear, to check whether they are truly linear). */
+    return deriv_id;
+  }
 };
 
 class SteadyStateModel : public DataTree
-- 
GitLab