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.
*
@ -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);
}
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
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.
*
@ -49,9 +49,9 @@ public:
double qz_criterium_arg, double lyapunov_tol_arg, int &info);
virtual ~InitializeKalmanFilter();
// initialise parameter dependent KF matrices only but not Ps
template <class VEC>
void initialize(VEC &steadyState, const VectorView &deepParams, Matrix &R,
const MatrixView &Q, Matrix &RQRt, Matrix &T,
template <class Vec1, class Vec2, class Mat1, class Mat2>
void initialize(Vec1 &steadyState, const Vec2 &deepParams, Mat1 &R,
const Mat2 &Q, Matrix &RQRt, Matrix &T,
double &penalty, const MatrixConstView &dataView,
MatrixView &detrendedDataView, int &info)
{
@ -63,9 +63,9 @@ public:
}
// initialise all KF matrices
template <class VEC>
void initialize(VEC &steadyState, const VectorView &deepParams, Matrix &R,
const MatrixView &Q, Matrix &RQRt, Matrix &T, Matrix &Pstar, Matrix &Pinf,
template <class Vec1, class Vec2, class Mat1, class Mat2>
void initialize(Vec1 &steadyState, const Vec2 &deepParams, Mat1 &R,
const Mat2 &Q, Matrix &RQRt, Matrix &T, Matrix &Pstar, Matrix &Pinf,
double &penalty, const MatrixConstView &dataView,
MatrixView &detrendedDataView, int &info)
{
@ -86,7 +86,16 @@ private:
Matrix g_u;
Matrix Rt, RQ;
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);
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2012 Dynare Team
* Copyright (C) 2009-2013 Dynare Team
*
* This file is part of Dynare.
*
@ -54,9 +54,9 @@ public:
double qz_criterium_arg, const std::vector<size_t> &varobs_arg,
double riccati_tol_arg, double lyapunov_tol_arg, int &info);
template <class VEC>
double compute(const MatrixConstView &dataView, VEC &steadyState,
const MatrixView &Q, const Matrix &H, const VectorView &deepParams,
template <class Vec1, class Vec2, class Mat1>
double compute(const MatrixConstView &dataView, Vec1 &steadyState,
const Mat1 &Q, const Matrix &H, const Vec2 &deepParams,
VectorView &vll, MatrixView &detrendedDataView, size_t start, size_t period,
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.
*
@ -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_static_arg, double qz_criterium);
virtual ~ModelSolution() {};
template <class VEC>
void compute(VEC &steadyState, const VectorView &deepParams, Matrix &ghx, Matrix &ghu) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException)
template <class Vec1, class Vec2, class Mat1, class Mat2>
void compute(Vec1 &steadyState, const Vec2 &deepParams, Mat1 &ghx, Mat2 &ghu) throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException)
{
// compute Steady State
ComputeSteadyState(steadyState, deepParams);
@ -66,9 +66,9 @@ private:
DynamicModelDLL dynamicDLLp;
Vector llXsteadyState;
//Matrix jacobian;
template <class VEC>
void ComputeModelSolution(VEC &steadyState, const VectorView &deepParams,
Matrix &ghx, Matrix &ghu)
template <class Vec1, class Vec2, class Mat1, class Mat2>
void ComputeModelSolution(Vec1 &steadyState, const Vec2 &deepParams,
Mat1 &ghx, Mat2 &ghu)
throw (DecisionRules::BlanchardKahnException, GeneralizedSchurDecomposition::GSDException)
{
// set extended Steady State
@ -88,8 +88,8 @@ private:
//compute rules
decisionRules.compute(jacobian, ghx, ghu);
}
template <class VEC>
void ComputeSteadyState(VEC &steadyState, const VectorView &deepParams)
template <class Vec1, class Vec2>
void ComputeSteadyState(Vec1 &steadyState, const Vec2 &deepParams)
{
// does nothig for time being.
}

View File

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