k_order_welfare MEX: drop ObjectiveAC abstract class, it has a single subclass

dprior
Sébastien Villemot 2024-02-07 15:03:23 +01:00
parent adc42bb4cb
commit 0d9857e737
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
6 changed files with 20 additions and 60 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2021-2023 Dynare Team
* Copyright © 2021-2024 Dynare Team
*
* This file is part of Dynare.
*
@ -18,13 +18,12 @@
*/
#include "k_ord_objective.hh"
#include "objective_abstract_class.hh"
#include <cassert>
#include <utility>
KordwDynare::KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams,
std::unique_ptr<ObjectiveAC> objectiveFile_arg,
std::unique_ptr<ObjectiveMFile> objectiveFile_arg,
const std::vector<int>& dr_order) :
model {m},
NNZD {NNZD_arg},

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2021-2023 Dynare Team
* Copyright © 2021-2024 Dynare Team
*
* This file is part of Dynare.
*
@ -21,7 +21,7 @@
#define K_ORD_OBJECTIVE_HH
#include "k_ord_dynare.hh"
#include "objective_abstract_class.hh"
#include "objective_m.hh"
class KordwDynare;
@ -38,11 +38,11 @@ private:
TensorContainer<FSSparseTensor> ud; // planner's objective derivatives, in Dynare++ form
std::vector<int> dynppToDyn; // Maps Dynare++ jacobian variable indices to Dynare ones
std::vector<int> dynToDynpp; // Maps Dynare jacobian variable indices to Dynare++ ones
std::unique_ptr<ObjectiveAC> objectiveFile;
std::unique_ptr<ObjectiveMFile> objectiveFile;
public:
KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams,
std::unique_ptr<ObjectiveAC> objectiveFile_arg, const std::vector<int>& varOrder);
std::unique_ptr<ObjectiveMFile> objectiveFile_arg, const std::vector<int>& varOrder);
void calcDerivativesAtSteady();
void populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_ud, int ord);
[[nodiscard]] const TensorContainer<FSSparseTensor>&

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2021-2022 Dynare Team
* Copyright © 2021-2024 Dynare Team
*
* This file is part of Dynare.
*
@ -87,8 +87,8 @@ The routine proceeds in several steps:
to the approxAtSteady method in the ApproximationWelfare class carries out the necessary
operation
- Importing the derivatives of the felicity function with the calcDerivativesAtSteady() method of
the KordwDynare class. It relies on the Matlab-generated files, which are handled by the
ObjectiveAC and ObjectiveMFile classes
the KordwDynare class. It relies on the MATLAB-generated files, which are handled by the
ObjectiveMFile class
- Pinpointing the derivatives of the felicity and welfare functions. The performStep method of
the KOrderWelfare class carries out the calculations,resorting to the FaaDiBruno class and its
methods to get the needed intermediary results.
@ -301,7 +301,7 @@ extern "C"
mxGetPr(objective_tmp_nbr_mx) + kOrder + 1, 0);
// Getting derivatives of the planner's objective function
std::unique_ptr<ObjectiveAC> objectiveFile;
std::unique_ptr<ObjectiveMFile> objectiveFile;
objectiveFile = std::make_unique<ObjectiveMFile>(fname, ntt_objective);
// make KordwDynare object

View File

@ -1,38 +0,0 @@
/*
* Copyright © 2021-2023 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef OBJECTIVE_ABSTRACT_CLASS_HH
#define OBJECTIVE_ABSTRACT_CLASS_HH
#include <vector>
#include "twod_matrix.hh"
class ObjectiveAC
{
protected:
int ntt; // Size of vector of temporary terms
public:
ObjectiveAC(int ntt_arg) : ntt {ntt_arg} {};
virtual ~ObjectiveAC() = default;
virtual void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual,
std::vector<TwoDMatrix>& md)
= 0;
};
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2021-2023 Dynare Team
* Copyright © 2021-2024 Dynare Team
*
* This file is part of Dynare.
*
@ -27,7 +27,7 @@
#include "objective_m.hh"
ObjectiveMFile::ObjectiveMFile(const std::string& modName, int ntt_arg) :
ObjectiveAC(ntt_arg), ObjectiveMFilename {modName + ".objective.static"}
ntt {ntt_arg}, ObjectiveMFilename {modName + ".objective.static"}
{
}

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2021-2023 Dynare Team
* Copyright © 2021-2024 Dynare Team
*
* This file is part of Dynare.
*
@ -20,24 +20,23 @@
#ifndef OBJECTIVE_M_HH
#define OBJECTIVE_M_HH
#include "objective_abstract_class.hh"
#include <vector>
#include "mex.h"
#include <dynmex.h>
/**
* handles calls to <model>/+objective/static.m
*
**/
class ObjectiveMFile : public ObjectiveAC
#include "twod_matrix.hh"
// Handles calls to <model>/+objective/static.m
class ObjectiveMFile
{
private:
int ntt; // Size of vector of temporary terms
const std::string ObjectiveMFilename;
static void unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray* sparseMat, TwoDMatrix& tdm);
public:
explicit ObjectiveMFile(const std::string& modName, int ntt_arg);
void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual,
std::vector<TwoDMatrix>& md) override;
std::vector<TwoDMatrix>& md);
};
#endif