diff --git a/mex/sources/k_order_perturbation/dynamic_dll.cc b/mex/sources/k_order_perturbation/dynamic_dll.cc index 5760b2960..ffc5649d4 100644 --- a/mex/sources/k_order_perturbation/dynamic_dll.cc +++ b/mex/sources/k_order_perturbation/dynamic_dll.cc @@ -22,13 +22,8 @@ #include -/*********************************** - * Members of DynamicModelDLL for handling loading and calling - * _dynamic () function - **************************************/ -DynamicModelDLL::DynamicModelDLL(const string &modName, const int y_length, const int j_cols, - const int n_max_lag, const int n_exog, const Vector &ySteady_arg, const string &sExt) throw (DynareException) : - length(y_length), jcols(j_cols), nMax_lag(n_max_lag), nExog(n_exog), ySteady(ySteady_arg) +DynamicModelDLL::DynamicModelDLL(const string &modName, int nExog_arg, const string &sExt) throw (DynareException) : + nExog(nExog_arg) { string fName; #if !defined(__CYGWIN32__) && !defined(_WIN32) @@ -94,59 +89,10 @@ DynamicModelDLL::~DynamicModelDLL() } void -DynamicModelDLL::eval(double *y, double *x, int nb_row_x, double *params, - int it_, double *residual, double *g1, double *g2, double *g3) -{ - double *steady_state = const_cast(ySteady.base()); - Dynamic(y, x, nb_row_x, params, steady_state, it_, residual, g1, g2, g3); -} - -void -DynamicModelDLL::eval(const Vector &y, const TwoDMatrix &x, const Vector *modParams, - int it_, Vector &residual, TwoDMatrix *g1, TwoDMatrix *g2, TwoDMatrix *g3) throw (DynareException) -{ - double *dresidual, *dg1 = NULL, *dg2 = NULL, *dg3 = NULL; - - if ((jcols-nExog) != y.length()) - throw DynareException(__FILE__, __LINE__, "DLL Error: (jcols-nExog)!=ys.length()"); - - if (g1 != NULL) - { - if (g1->nrows() != length) - throw DynareException(__FILE__, __LINE__, "DLL Error: g1 has wrong size"); - dg1 = const_cast(g1->base()); - } - if (g2 != NULL) - dg2 = const_cast(g2->base()); - dresidual = const_cast(residual.base()); - if (g3 != NULL) - dg3 = const_cast(g3->base()); - dresidual = const_cast(residual.base()); - double *dy = const_cast(y.base()); - double *dx = const_cast(x.base()); - double *dbParams = const_cast(modParams->base()); - double *steady_state = const_cast(ySteady.base()); - - Dynamic(dy, dx, nExog, dbParams, steady_state, it_, dresidual, dg1, dg2, dg3); -} - -void -DynamicModelDLL::eval(const Vector &y, const TwoDMatrix &x, const Vector *modParams, +DynamicModelDLL::eval(const Vector &y, const Vector &x, const Vector &modParams, const Vector &ySteady, Vector &residual, TwoDMatrix *g1, TwoDMatrix *g2, TwoDMatrix *g3) throw (DynareException) { - eval(y, x, modParams, nMax_lag, residual, g1, g2, g3); -} - -void -DynamicModelDLL::eval(const Vector &y, const Vector &x, const Vector *modParams, - Vector &residual, TwoDMatrix *g1, TwoDMatrix *g2, TwoDMatrix *g3) throw (DynareException) -{ - /** ignore given exogens and create new 2D x matrix since - * when calling _dynamic(z,x,params,it_) x must be equal to - * zeros(M_.maximum_lag+1,M_.exo_nbr) - **/ - TwoDMatrix mx(nMax_lag+1, nExog); - mx.zeros(); // initialise shocks to 0s - - eval(y, mx, modParams, nMax_lag, residual, g1, g2, g3); + Dynamic(y.base(), x.base(), nExog, modParams.base(), ySteady.base(), 0, residual.base(), + g1 == NULL ? NULL : g1->base(), + g2 == NULL ? NULL : g2->base(), g3 == NULL ? NULL : g3->base()); } diff --git a/mex/sources/k_order_perturbation/dynamic_dll.hh b/mex/sources/k_order_perturbation/dynamic_dll.hh index efed398d9..3c1f34b8c 100644 --- a/mex/sources/k_order_perturbation/dynamic_dll.hh +++ b/mex/sources/k_order_perturbation/dynamic_dll.hh @@ -29,8 +29,8 @@ #include "dynare_exception.h" // _Dynamic DLL pointer -typedef void (*DynamicFn) -(double *y, double *x, int nb_row_x, double *params, double *steady_state, +typedef void (*DynamicFn) +(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, double *residual, double *g1, double *g2, double *g3); /** @@ -40,13 +40,8 @@ typedef void (*DynamicFn) class DynamicModelDLL { private: - DynamicFn Dynamic; // pointer to the Dynamic function in DLL - - const int length; // tot num vars = Num of Jacobian rows - const int jcols; // tot num var t-1, t and t+1 instances + exogs = Num of Jacobian columns - const int nMax_lag; // no of lags + DynamicFn Dynamic; // pointer to the Dynamic function in DLL const int nExog; // no of exogenous - const Vector &ySteady; #if defined(_WIN32) || defined(__CYGWIN32__) HINSTANCE dynamicHinstance; // DLL instance pointer in Windows #else @@ -55,17 +50,9 @@ private: public: // construct and load Dynamic model DLL - DynamicModelDLL(const string &fname, const int length, const int jcols, - const int nMax_lag, const int nExog, const Vector &ySteady_arg, const string &sExt) throw (DynareException); + DynamicModelDLL(const string &fname, int nExog_arg, const string &sExt) throw (DynareException); virtual ~DynamicModelDLL(); - // evaluate Dynamic model DLL - void eval(double *y, double *x, int nb_row_x, double *params, - int it_, double *residual, double *g1, double *g2, double *g3); - void eval(const Vector &y, const Vector &x, const Vector *params, - Vector &residual, TwoDMatrix *g1, TwoDMatrix *g2, TwoDMatrix *g3) throw (DynareException); - void eval(const Vector &y, const TwoDMatrix &x, const Vector *params, - int it_, Vector &residual, TwoDMatrix *g1, TwoDMatrix *g2, TwoDMatrix *g3) throw (DynareException); - void eval(const Vector &y, const TwoDMatrix &x, const Vector *params, + void eval(const Vector &y, const Vector &x, const Vector ¶ms, const Vector &ySteady, Vector &residual, TwoDMatrix *g1, TwoDMatrix *g2, TwoDMatrix *g3) throw (DynareException); }; diff --git a/mex/sources/k_order_perturbation/k_ord_dynare.cc b/mex/sources/k_order_perturbation/k_ord_dynare.cc index feca54ab6..cce518db9 100644 --- a/mex/sources/k_order_perturbation/k_ord_dynare.cc +++ b/mex/sources/k_order_perturbation/k_ord_dynare.cc @@ -113,7 +113,7 @@ KordpDynare::calcDerivativesAtSteady() throw (DynareException) Vector llxSteady(nJcols-nExog); LLxSteady(ySteady, llxSteady); - dynamicDLL.eval(llxSteady, xx, ¶ms, out, &g1, g2p, g3p); + dynamicDLL.eval(llxSteady, xx, params, ySteady, out, &g1, g2p, g3p); populateDerivativesContainer(g1, 1, JacobianIndices); diff --git a/mex/sources/k_order_perturbation/k_order_perturbation.cc b/mex/sources/k_order_perturbation/k_order_perturbation.cc index 2082a2472..1173e7514 100644 --- a/mex/sources/k_order_perturbation/k_order_perturbation.cc +++ b/mex/sources/k_order_perturbation/k_order_perturbation.cc @@ -134,9 +134,6 @@ extern "C" { const int nEndo = (int) mxGetScalar(mxFldp); mxFldp = mxGetField(M_, 0, "param_nbr"); const int nPar = (int) mxGetScalar(mxFldp); - // it_ should be set to M_.maximum_lag - mxFldp = mxGetField(M_, 0, "maximum_lag"); - const int nMax_lag = (int) mxGetScalar(mxFldp); nPred -= nBoth; // correct nPred for nBoth. @@ -195,7 +192,7 @@ extern "C" { std::string jName(fName); //params.basename); jName += ".jnl"; Journal journal(jName.c_str()); - DynamicModelDLL dynamicDLL(fName, nEndo, jcols, nMax_lag, nExog, ySteady, dfExt); + DynamicModelDLL dynamicDLL(fName, nExog, dfExt); // intiate tensor library tls.init(kOrder, nStat+2*nPred+3*nBoth+2*nForw+nExog);