Make various functions more generic, using templates

This was necessary to make some tests work again
time-shift
Sébastien Villemot 2013-01-30 16:43:02 +01:00
parent 02fee79fc7
commit b3acdc0836
5 changed files with 33 additions and 34 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2010-2012 Dynare Team * Copyright (C) 2010-2013 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -63,16 +63,6 @@ InitializeKalmanFilter::setT(Matrix &T, int &info)
mat::assignByVectors(T, mat::nullVec, pi_bm_vbm, g_x, zeta_varobs_back_mixed, mat::nullVec); mat::assignByVectors(T, mat::nullVec, pi_bm_vbm, g_x, zeta_varobs_back_mixed, mat::nullVec);
} }
void
InitializeKalmanFilter::setRQR(Matrix &R, const MatrixView &Q, Matrix &RQRt, int &info)
{
mat::assignByVectors(R, mat::nullVec, mat::nullVec, g_u, zeta_varobs_back_mixed, mat::nullVec);
// Matrix RQRt=R*Q*R'
blas::gemm("N", "N", 1.0, R, Q, 0.0, RQ); // R*Q
blas::gemm("N", "T", 1.0, RQ, R, 0.0, RQRt); // R*Q*R'
}
void void
InitializeKalmanFilter::setPstar(Matrix &Pstar, Matrix &Pinf, const Matrix &T, const Matrix &RQRt, int &info) InitializeKalmanFilter::setPstar(Matrix &Pstar, Matrix &Pinf, const Matrix &T, const Matrix &RQRt, int &info)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2010-2012 Dynare Team * Copyright (C) 2010-2013 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -49,9 +49,9 @@ public:
double qz_criterium_arg, double lyapunov_tol_arg, int &info); double qz_criterium_arg, double lyapunov_tol_arg, int &info);
virtual ~InitializeKalmanFilter(); virtual ~InitializeKalmanFilter();
// initialise parameter dependent KF matrices only but not Ps // initialise parameter dependent KF matrices only but not Ps
template <class VEC> template <class Vec1, class Vec2, class Mat1, class Mat2>
void initialize(VEC &steadyState, const VectorView &deepParams, Matrix &R, void initialize(Vec1 &steadyState, const Vec2 &deepParams, Mat1 &R,
const MatrixView &Q, Matrix &RQRt, Matrix &T, const Mat2 &Q, Matrix &RQRt, Matrix &T,
double &penalty, const MatrixConstView &dataView, double &penalty, const MatrixConstView &dataView,
MatrixView &detrendedDataView, int &info) MatrixView &detrendedDataView, int &info)
{ {
@ -63,9 +63,9 @@ public:
} }
// initialise all KF matrices // initialise all KF matrices
template <class VEC> template <class Vec1, class Vec2, class Mat1, class Mat2>
void initialize(VEC &steadyState, const VectorView &deepParams, Matrix &R, void initialize(Vec1 &steadyState, const Vec2 &deepParams, Mat1 &R,
const MatrixView &Q, Matrix &RQRt, Matrix &T, Matrix &Pstar, Matrix &Pinf, const Mat2 &Q, Matrix &RQRt, Matrix &T, Matrix &Pstar, Matrix &Pinf,
double &penalty, const MatrixConstView &dataView, double &penalty, const MatrixConstView &dataView,
MatrixView &detrendedDataView, int &info) MatrixView &detrendedDataView, int &info)
{ {
@ -86,7 +86,16 @@ private:
Matrix g_u; Matrix g_u;
Matrix Rt, RQ; Matrix Rt, RQ;
void setT(Matrix &T, int &info); void setT(Matrix &T, int &info);
void setRQR(Matrix &R, const MatrixView &Q, Matrix &RQRt, int &info);
template <class Mat1, class Mat2>
void setRQR(Mat1 &R, const Mat2 &Q, Matrix &RQRt, int &info)
{
mat::assignByVectors(R, mat::nullVec, mat::nullVec, g_u, zeta_varobs_back_mixed, mat::nullVec);
// Matrix RQRt=R*Q*R'
blas::gemm("N", "N", 1.0, R, Q, 0.0, RQ); // R*Q
blas::gemm("N", "T", 1.0, RQ, R, 0.0, RQRt); // R*Q*R'
}
void setPstar(Matrix &Pstar, Matrix &Pinf, const Matrix &T, const Matrix &RQRt, int &info); void setPstar(Matrix &Pstar, Matrix &Pinf, const Matrix &T, const Matrix &RQRt, int &info);
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009-2012 Dynare Team * Copyright (C) 2009-2013 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -54,9 +54,9 @@ public:
double qz_criterium_arg, const std::vector<size_t> &varobs_arg, double qz_criterium_arg, const std::vector<size_t> &varobs_arg,
double riccati_tol_arg, double lyapunov_tol_arg, int &info); double riccati_tol_arg, double lyapunov_tol_arg, int &info);
template <class VEC> template <class Vec1, class Vec2, class Mat1>
double compute(const MatrixConstView &dataView, VEC &steadyState, double compute(const MatrixConstView &dataView, Vec1 &steadyState,
const MatrixView &Q, const Matrix &H, const VectorView &deepParams, const Mat1 &Q, const Matrix &H, const Vec2 &deepParams,
VectorView &vll, MatrixView &detrendedDataView, size_t start, size_t period, VectorView &vll, MatrixView &detrendedDataView, size_t start, size_t period,
double &penalty, int &info) double &penalty, int &info)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2010-2012 Dynare Team * Copyright (C) 2010-2013 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -42,8 +42,8 @@ public:
const std::vector<size_t> &zeta_back_arg, const std::vector<size_t> &zeta_mixed_arg, const std::vector<size_t> &zeta_back_arg, const std::vector<size_t> &zeta_mixed_arg,
const std::vector<size_t> &zeta_static_arg, double qz_criterium); const std::vector<size_t> &zeta_static_arg, double qz_criterium);
virtual ~ModelSolution() {}; virtual ~ModelSolution() {};
template <class VEC> template <class Vec1, class Vec2, class Mat1, class Mat2>
void compute(VEC &steadyState, const VectorView &deepParams, Matrix &ghx, Matrix &ghu) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException) void compute(Vec1 &steadyState, const Vec2 &deepParams, Mat1 &ghx, Mat2 &ghu) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException)
{ {
// compute Steady State // compute Steady State
ComputeSteadyState(steadyState, deepParams); ComputeSteadyState(steadyState, deepParams);
@ -66,9 +66,9 @@ private:
DynamicModelDLL dynamicDLLp; DynamicModelDLL dynamicDLLp;
Vector llXsteadyState; Vector llXsteadyState;
//Matrix jacobian; //Matrix jacobian;
template <class VEC> template <class Vec1, class Vec2, class Mat1, class Mat2>
void ComputeModelSolution(VEC &steadyState, const VectorView &deepParams, void ComputeModelSolution(Vec1 &steadyState, const Vec2 &deepParams,
Matrix &ghx, Matrix &ghu) Mat1 &ghx, Mat2 &ghu)
throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException)
{ {
// set extended Steady State // set extended Steady State
@ -88,8 +88,8 @@ private:
//compute rules //compute rules
decisionRules.compute(jacobian, ghx, ghu); decisionRules.compute(jacobian, ghx, ghu);
} }
template <class VEC> template <class Vec1, class Vec2>
void ComputeSteadyState(VEC &steadyState, const VectorView &deepParams) void ComputeSteadyState(Vec1 &steadyState, const Vec2 &deepParams)
{ {
// does nothig for time being. // does nothig for time being.
} }

View File

@ -57,9 +57,9 @@ public:
virtual ~DynamicModelDLL(); virtual ~DynamicModelDLL();
//! evaluate Dynamic model DLL //! evaluate Dynamic model DLL
template<class VEC> template<class Vec1, class Vec2, class Vec3, class Vec4, class Mat1>
void eval(const Vector &y, const Matrix &x, const VectorView &modParams, VEC &ySteady, void eval(const Vec1 &y, const Mat1 &x, const Vec2 &modParams, const Vec3 &ySteady,
Vector &residual, Matrix *g1, Matrix *g2, Matrix *g3) throw (TSException) Vec4 &residual, Matrix *g1, Matrix *g2, Matrix *g3) throw (TSException)
{ {
assert(y.getStride() == 1); assert(y.getStride() == 1);
assert(x.getLd() == x.getRows()); assert(x.getLd() == x.getRows());