Commit d95b0cf6 authored by Sébastien Villemot's avatar Sébastien Villemot

K-order DLL, KordpDynare class: removed memory leaks

parent bb3675e7
......@@ -122,31 +122,31 @@ class KordpDynare : public DynamicModel
const int nYss; // nyss ={ nboth + nforw ; }
const int nY; // = num_endo={ nstat + npred + nboth + nforw ; }
const int nJcols; // no of jacobian columns= nExog+nEndo+nsPred+nsForw
const Vector *NNZD; /* the total number of non-zero derivative elements
const Vector &NNZD; /* the total number of non-zero derivative elements
where hessian is 2nd : NZZD(order=2) */
const int nSteps;
const int nOrder;
Journal &journal;
Vector *ySteady;
Vector *params;
TwoDMatrix *vCov;
Vector &ySteady;
Vector &params;
TwoDMatrix &vCov;
TensorContainer<FSSparseTensor> md; // ModelDerivatives
DynareNameList *dnl;
DynareExogNameList *denl;
DynareStateNameList *dsnl;
DynareNameList dnl;
DynareExogNameList denl;
DynareStateNameList dsnl;
const double ss_tol;
const vector<int> *varOrder;
const TwoDMatrix *ll_Incidence;
const vector<int> &varOrder;
const TwoDMatrix &ll_Incidence;
double qz_criterium;
vector<int> *JacobianIndices;
vector<int> JacobianIndices;
public:
KordpDynare(const char **endo, int num_endo,
const char **exo, int num_exo, int num_par,
Vector *ySteady, TwoDMatrix *vCov, Vector *params, int nstat, int nPred,
int nforw, int nboth, const int nJcols, const Vector *NNZD,
Vector &ySteady, TwoDMatrix &vCov, Vector &params, int nstat, int nPred,
int nforw, int nboth, const int nJcols, const Vector &NNZD,
const int nSteps, const int ord,
Journal &jr, DynamicModelDLL &dynamicDLL, double sstol,
const vector<int> *varOrder, const TwoDMatrix *ll_Incidence,
const vector<int> &varOrder, const TwoDMatrix &ll_Incidence,
double qz_criterium) throw (TLException);
virtual ~KordpDynare();
......@@ -203,27 +203,27 @@ public:
const NameList &
getAllEndoNames() const
{
return *dnl;
return dnl;
}
const NameList &
getStateNames() const
{
return *dsnl;
return dsnl;
}
const NameList &
getExogNames() const
{
return *denl;
return denl;
}
const TwoDMatrix &
getVcov() const
{
return *vCov;
return vCov;
}
Vector &
getParams()
{
return *params;
return params;
}
const TensorContainer<FSSparseTensor> &
......@@ -234,31 +234,31 @@ public:
const Vector &
getSteady() const
{
return *ySteady;
return ySteady;
}
Vector &
getSteady()
{
return *ySteady;
return ySteady;
}
void solveDeterministicSteady();
void evaluateSystem(Vector &out, const Vector &yy, const Vector &xx) throw (DynareException);
void evaluateSystem(Vector &out, const Vector &yym, const Vector &yy,
const Vector &yyp, const Vector &xx) throw (DynareException);
void calcDerivatives(const Vector &yy, const Vector &xx) throw (DynareException);
void calcDerivativesAtSteady() throw (DynareException);
DynamicModelDLL &dynamicDLL;
DynamicModel *
clone() const
{
return new KordpDynare(*this);
std::cerr << "KordpDynare::clone() not implemented" << std::endl;
exit(EXIT_FAILURE);
}
Vector *LLxSteady(const Vector &yS) throw (DynareException, TLException); // returns ySteady extended with leads and lags
void LLxSteady(const Vector &yS, Vector &llxSteady) throw (DynareException, TLException); // Given the steady state in yS, returns in llxSteady the steady state extended with leads and lags
private:
vector<int> *ReorderDynareJacobianIndices(const vector<int> *varOrder) throw (TLException);
void populateDerivativesContainer(TwoDMatrix *g, int ord, const vector<int> *vOrder);
void ReorderDynareJacobianIndices() throw (TLException);
void populateDerivativesContainer(const TwoDMatrix &g, int ord, const vector<int> &vOrder);
};
#endif
......@@ -130,17 +130,17 @@ extern "C" {
mxFldp = mxGetField(M_, 0, "params");
double *dparams = (double *) mxGetData(mxFldp);
int npar = (int) mxGetM(mxFldp);
Vector *modParams = new Vector(dparams, npar);
Vector modParams(dparams, npar);
mxFldp = mxGetField(M_, 0, "Sigma_e");
dparams = (double *) mxGetData(mxFldp);
npar = (int) mxGetN(mxFldp);
TwoDMatrix *vCov = new TwoDMatrix(npar, npar, dparams);
TwoDMatrix vCov(npar, npar, dparams);
mxFldp = mxGetField(dr, 0, "ys"); // and not in order of dr.order_var
dparams = (double *) mxGetData(mxFldp);
const int nSteady = (int) mxGetM(mxFldp);
Vector *ySteady = new Vector(dparams, nSteady);
Vector ySteady(dparams, nSteady);
mxFldp = mxGetField(dr, 0, "nstatic");
const int nStat = (int) mxGetScalar(mxFldp);
......@@ -172,9 +172,9 @@ extern "C" {
npar = (int) mxGetM(mxFldp);
if (npar != nEndo) //(nPar != npar)
mexErrMsgTxt("Incorrect number of input var_order vars.");
vector<int> *var_order_vp = (new vector<int>(nEndo));
vector<int> var_order_vp(nEndo);
for (int v = 0; v < nEndo; v++)
(*var_order_vp)[v] = (int)(*(dparams++));
var_order_vp[v] = (int)(*(dparams++));
// the lag, current and lead blocks of the jacobian respectively
mxFldp = mxGetField(M_, 0, "lead_lag_incidence");
......@@ -182,14 +182,14 @@ extern "C" {
npar = (int) mxGetN(mxFldp);
int nrows = (int) mxGetM(mxFldp);
TwoDMatrix *llincidence = new TwoDMatrix(nrows, npar, dparams);
TwoDMatrix llincidence(nrows, npar, dparams);
if (npar != nEndo)
mexErrMsgIdAndTxt("dynare:k_order_perturbation", "Incorrect length of lead lag incidences: ncol=%d != nEndo=%d.", npar, nEndo);
//get NNZH =NNZD(2) = the total number of non-zero Hessian elements
mxFldp = mxGetField(M_, 0, "NNZDerivatives");
dparams = (double *) mxGetData(mxFldp);
Vector *NNZD = new Vector(dparams, (int) mxGetM(mxFldp));
Vector NNZD(dparams, (int) mxGetM(mxFldp));
const int jcols = nExog+nEndo+nsPred+nsForw; // Num of Jacobian columns
......@@ -258,7 +258,7 @@ extern "C" {
app.getFoldDecisionRule().writeMMap(mm, string());
// get latest ysteady
ySteady = (Vector *)(&dynare.getSteady());
ySteady = dynare.getSteady();
if (kOrder == 1)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment