From 762243c705b36ccd3f838e814bd8432651bc0833 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 26 Sep 2022 13:09:33 +0200
Subject: [PATCH] Julia: drop get_power_deriv function from module

The function is now provided separately by Dynare.jl.
---
 src/DataTree.cc     | 20 --------------------
 src/DataTree.hh     |  2 --
 src/DynamicModel.cc |  7 +------
 src/StaticModel.cc  |  7 +------
 4 files changed, 2 insertions(+), 34 deletions(-)

diff --git a/src/DataTree.cc b/src/DataTree.cc
index e97204f7..0dde5664 100644
--- a/src/DataTree.cc
+++ b/src/DataTree.cc
@@ -917,26 +917,6 @@ DataTree::writePowerDeriv(ostream &output) const
            << "}" << endl;
 }
 
-void
-DataTree::writePowerDerivJulia(ostream &output) const
-{
-  if (isBinaryOpUsed(BinaryOpcode::powerDeriv))
-    output << "nearbyint(x::T) where T <: Real  = (abs((x)-floor(x)) < abs((x)-ceil(x)) ? floor(x) : ceil(x))" << endl
-	   << endl
-	   << "function get_power_deriv(x::T, p::T, k::Int64) where T <: Real" << endl
-	   << "    if (abs(x) < 1e-12 && p > 0 && k > p && abs(p-nearbyint(p)) < 1e-12 )" << endl
-	   << "        return 0.0" << endl
-	   << "    else" << endl
-	   << "        dxp = x^(p-k)" << endl
-	   << "        for i = 1:k" << endl
-	   << "	     dxp *= p" << endl
-	   << "	     p -= 1" << endl
-	   << "	 end" << endl
-	   << "	 return dxp" << endl
-	   << "    end" << endl
-	   << "end" << endl;
-}
-
 void
 DataTree::writePowerDerivHeader(ostream &output) const
 {
diff --git a/src/DataTree.hh b/src/DataTree.hh
index 5e8ad6d7..8afab57c 100644
--- a/src/DataTree.hh
+++ b/src/DataTree.hh
@@ -281,8 +281,6 @@ public:
   void writePowerDeriv(ostream &output) const;
   //! Write getPowerDeriv in C (prototype)
   void writePowerDerivHeader(ostream &output) const;
-  //! Write getPowerDeriv in Julia
-  void writePowerDerivJulia(ostream &output) const;
   //! Thrown when trying to access an unknown variable by deriv_id
   class UnknownDerivIDException
   {
diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc
index a8eac146..965ddc7c 100644
--- a/src/DynamicModel.cc
+++ b/src/DynamicModel.cc
@@ -930,12 +930,7 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const
          << "    dynamicResid!(T, residual, y, x, params, steady_state, it_, false)" << endl
          << "    return nothing" << endl
          << "end" << endl
-         << endl;
-
-  // Write function definition if BinaryOpcode::powerDeriv is used
-  writePowerDerivJulia(output);
-
-  output << "end" << endl;
+         << "end" << endl;
 
   writeToFileIfModified(output, basename + "Dynamic.jl");
 }
diff --git a/src/StaticModel.cc b/src/StaticModel.cc
index b9faf9d0..ad672e87 100644
--- a/src/StaticModel.cc
+++ b/src/StaticModel.cc
@@ -818,12 +818,7 @@ StaticModel::writeStaticJuliaFile(const string &basename) const
          << "    staticResid!(T, residual, y, x, params, false)" << endl
          << "    return nothing" << endl
          << "end" << endl
-         << endl;
-
-  // Write function definition if BinaryOpcode::powerDeriv is used
-  writePowerDerivJulia(output);
-
-  output << "end" << endl;
+         << "end" << endl;
 
   writeToFileIfModified(output, basename + "Static.jl");
 }
-- 
GitLab